From: Sanjay Patel Date: Thu, 5 Oct 2017 14:26:15 +0000 (+0000) Subject: revert r314698 - [InstCombine] remove one-use restriction for icmp (shr exact X,... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=895743db7616839d8de33f6001af0c485ca89f52;p=llvm revert r314698 - [InstCombine] remove one-use restriction for icmp (shr exact X, C1), C2 --> icmp X, (C2<> 1 == 2 --> (X & 4) == 4. Constant *ShiftedCmpRHS = ConstantInt::get(Shr->getType(), C << ShAmtVal); - if (Shr->isExact()) - return new ICmpInst(Pred, X, ShiftedCmpRHS); - if (Shr->hasOneUse()) { - // Canonicalize the shift into an 'and': - // icmp eq/ne (shr X, ShAmt), C --> icmp eq/ne (and X, HiMask), (C << ShAmt) + if (Shr->isExact()) + return new ICmpInst(Pred, X, ShiftedCmpRHS); + + // Otherwise strength reduce the shift into an 'and'. APInt Val(APInt::getHighBitsSet(TypeBits, TypeBits - ShAmtVal)); Constant *Mask = ConstantInt::get(Shr->getType(), Val); Value *And = Builder.CreateAnd(X, Mask, Shr->getName() + ".mask"); diff --git a/test/Transforms/InstCombine/icmp-shr.ll b/test/Transforms/InstCombine/icmp-shr.ll index 214f315f317..77eaf09eb96 100644 --- a/test/Transforms/InstCombine/icmp-shr.ll +++ b/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 %x, 131072 +; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[SH]], 1024 ; CHECK-NEXT: call void @foo(i32 [[SH]]) ; CHECK-NEXT: ret i1 [[CMP]] ;