diff options
| author | Paul Redmond <paul.redmond@intel.com> | 2012-12-19 19:47:13 +0000 |
|---|---|---|
| committer | Paul Redmond <paul.redmond@intel.com> | 2012-12-19 19:47:13 +0000 |
| commit | 5917f4c71597f9666c4e75decc1b5240f05130b5 (patch) | |
| tree | 0f201dd38bd74a6d4caa25baf98458bc51f565f9 /llvm/lib/Transforms/InstCombine | |
| parent | 8013df71c757afeaf996244bb050e09c0257189b (diff) | |
| download | bcm5719-llvm-5917f4c71597f9666c4e75decc1b5240f05130b5.tar.gz bcm5719-llvm-5917f4c71597f9666c4e75decc1b5240f05130b5.zip | |
Transform (x&C)>V into (x&C)!=0 where possible
When the least bit of C is greater than V, (x&C) must be greater than V
if it is not zero, so the comparison can be simplified.
Although this was suggested in Target/X86/README.txt, it benefits any
architecture with a directly testable form of AND.
Patch by Kevin Schoedel
llvm-svn: 170576
Diffstat (limited to 'llvm/lib/Transforms/InstCombine')
| -rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp index 1b96c3cca4e..13516d15c4d 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -1226,6 +1226,16 @@ Instruction *InstCombiner::visitICmpInstWithInstAndIntCst(ICmpInst &ICI, ICI.setOperand(0, NewAnd); return &ICI; } + + // Replace ((X & AndCST) > RHSV) with ((X & AndCST) != 0), if any + // bit set in (X & AndCST) will produce a result greater than RHSV. + if (ICI.getPredicate() == ICmpInst::ICMP_UGT) { + unsigned NTZ = AndCST->getValue().countTrailingZeros(); + if ((NTZ < AndCST->getBitWidth()) && + APInt::getOneBitSet(AndCST->getBitWidth(), NTZ).ugt(RHSV)) + return new ICmpInst(ICmpInst::ICMP_NE, LHSI, + Constant::getNullValue(RHS->getType())); + } } // Try to optimize things like "A[i]&42 == 0" to index computations. |

