diff options
author | Sanjay Patel <spatel@rotateright.com> | 2017-10-15 15:39:15 +0000 |
---|---|---|
committer | Sanjay Patel <spatel@rotateright.com> | 2017-10-15 15:39:15 +0000 |
commit | 934738a3daee3306e02183b0d620a7b07bc00eed (patch) | |
tree | ca820208beb43fb4aefae55cb5efcfdd5cffb541 | |
parent | 606093a53ba6effd69bca68bda3088325f2fcd7e (diff) | |
download | bcm5719-llvm-934738a3daee3306e02183b0d620a7b07bc00eed.tar.gz bcm5719-llvm-934738a3daee3306e02183b0d620a7b07bc00eed.zip |
revert r314984: revert r314698 - [InstCombine] remove one-use restriction for icmp (shr exact X, C1), C2 --> icmp X, (C2<<C1)
Recommitting r314698. The bug exposed by this change should be fixed with:
https://reviews.llvm.org/rL315579
llvm-svn: 315857
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp | 12 | ||||
-rw-r--r-- | llvm/test/Transforms/InstCombine/icmp-shr.ll | 2 |
2 files changed, 7 insertions, 7 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp index 67b5e5c130b..c3a3c4fbc4c 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -2060,15 +2060,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(ShrTy, 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(ShrTy, Val); Value *And = Builder.CreateAnd(X, Mask, Shr->getName() + ".mask"); diff --git a/llvm/test/Transforms/InstCombine/icmp-shr.ll b/llvm/test/Transforms/InstCombine/icmp-shr.ll index 77eaf09eb96..214f315f317 100644 --- a/llvm/test/Transforms/InstCombine/icmp-shr.ll +++ b/llvm/test/Transforms/InstCombine/icmp-shr.ll @@ -483,7 +483,7 @@ declare void @foo(i32) define i1 @exact_multiuse(i32 %x) { ; CHECK-LABEL: @exact_multiuse( ; CHECK-NEXT: [[SH:%.*]] = lshr exact i32 %x, 7 -; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[SH]], 1024 +; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 %x, 131072 ; CHECK-NEXT: call void @foo(i32 [[SH]]) ; CHECK-NEXT: ret i1 [[CMP]] ; |