diff options
author | David Majnemer <david.majnemer@gmail.com> | 2013-07-09 09:20:58 +0000 |
---|---|---|
committer | David Majnemer <david.majnemer@gmail.com> | 2013-07-09 09:20:58 +0000 |
commit | fecf0d7a0157011964b4f31a7a5374076b1b236c (patch) | |
tree | 345738601f1fa7f210a98dfd85ae074dbbe7d49b /lib/Transforms/InstCombine | |
parent | 36b6f7409d9f607317de9815ffc10656b608eab7 (diff) | |
download | external_llvm-fecf0d7a0157011964b4f31a7a5374076b1b236c.zip external_llvm-fecf0d7a0157011964b4f31a7a5374076b1b236c.tar.gz external_llvm-fecf0d7a0157011964b4f31a7a5374076b1b236c.tar.bz2 |
InstCombine: variations on 0xffffffff - x >= 4
The following transforms are valid if -C is a power of 2:
(icmp ugt (xor X, C), ~C) -> (icmp ult X, C)
(icmp ult (xor X, C), -C) -> (icmp uge X, C)
These are nice, they get rid of the xor.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@185915 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/InstCombine')
-rw-r--r-- | lib/Transforms/InstCombine/InstCombineCompares.cpp | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/Transforms/InstCombine/InstCombineCompares.cpp b/lib/Transforms/InstCombine/InstCombineCompares.cpp index e9f3458..8ac0e3f 100644 --- a/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -1126,6 +1126,18 @@ Instruction *InstCombiner::visitICmpInstWithInstAndIntCst(ICmpInst &ICI, Builder->getInt(RHSV ^ NotSignBit)); } } + + // (icmp ugt (xor X, C), ~C) -> (icmp ult X, C) + // iff -C is a power of 2 + if (ICI.getPredicate() == ICmpInst::ICMP_UGT && + XorCST->getValue() == ~RHSV && (RHSV + 1).isPowerOf2()) + return new ICmpInst(ICmpInst::ICMP_ULT, LHSI->getOperand(0), XorCST); + + // (icmp ult (xor X, C), -C) -> (icmp uge X, C) + // iff -C is a power of 2 + if (ICI.getPredicate() == ICmpInst::ICMP_ULT && + XorCST->getValue() == -RHSV && RHSV.isPowerOf2()) + return new ICmpInst(ICmpInst::ICMP_UGE, LHSI->getOperand(0), XorCST); } break; case Instruction::And: // (icmp pred (and X, AndCST), RHS) |