diff options
author | Sanjay Patel <spatel@rotateright.com> | 2017-10-02 18:26:44 +0000 |
---|---|---|
committer | Sanjay Patel <spatel@rotateright.com> | 2017-10-02 18:26:44 +0000 |
commit | 6e17c00a88e23d0cc4cb491bfd0830f3df7fff66 (patch) | |
tree | e5852b515ab71642c7f1320a77c8ceb84ee893a9 /llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp | |
parent | acdf91817ee881d28f6d00245e041947a45eb1a4 (diff) | |
download | bcm5719-llvm-6e17c00a88e23d0cc4cb491bfd0830f3df7fff66.tar.gz bcm5719-llvm-6e17c00a88e23d0cc4cb491bfd0830f3df7fff66.zip |
[InstCombine] remove one-use restriction for icmp (shr exact X, C1), C2 --> icmp X, (C2<<C1)
llvm-svn: 314698
Diffstat (limited to 'llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp index 1b38266bd4a..c5484456d1f 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -2058,15 +2058,15 @@ Instruction *InstCombiner::foldICmpShrConstant(ICmpInst &Cmp, (!IsAShr && C->shl(ShAmtVal).lshr(ShAmtVal) == *C)) && "Expected icmp+shr simplify did not occur."); - // Check if the bits shifted out are known to be zero. If so, we can compare - // against the unshifted value: + // If the bits shifted out are known zero, compare the unshifted value: // (X & 4) >> 1 == 2 --> (X & 4) == 4. Constant *ShiftedCmpRHS = ConstantInt::get(Shr->getType(), *C << ShAmtVal); - if (Shr->hasOneUse()) { - if (Shr->isExact()) - return new ICmpInst(Pred, X, ShiftedCmpRHS); + if (Shr->isExact()) + return new ICmpInst(Pred, X, ShiftedCmpRHS); - // Otherwise strength reduce the shift into an 'and'. + if (Shr->hasOneUse()) { + // Canonicalize the shift into an 'and': + // icmp eq/ne (shr X, ShAmt), C --> icmp eq/ne (and X, HiMask), (C << ShAmt) APInt Val(APInt::getHighBitsSet(TypeBits, TypeBits - ShAmtVal)); Constant *Mask = ConstantInt::get(Shr->getType(), Val); Value *And = Builder.CreateAnd(X, Mask, Shr->getName() + ".mask"); |