aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvan Cheng <evan.cheng@apple.com>2008-04-23 00:38:06 +0000
committerEvan Cheng <evan.cheng@apple.com>2008-04-23 00:38:06 +0000
commitf30752cbcc9a29bc10f1d811bdfe2c78f267e51b (patch)
treef799fd679e1d4be0591595353eff125ceac96eb8
parenta5ddb59a1319ccd23844c74809a64bc4d88f59d1 (diff)
Don't do: "(X & 4) >> 1 == 2 --> (X & 4) == 4" if there are more than one uses of the shift result.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@50118 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Transforms/Scalar/InstructionCombining.cpp5
-rw-r--r--test/Transforms/InstCombine/shl-icmp.ll29
2 files changed, 32 insertions, 2 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp
index 555942ddc1..c2019389ba 100644
--- a/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -6065,13 +6065,14 @@ Instruction *InstCombiner::visitICmpInstWithInstAndIntCst(ICmpInst &ICI,
// Otherwise, check to see if the bits shifted out are known to be zero.
// If so, we can compare against the unshifted value:
// (X & 4) >> 1 == 2 --> (X & 4) == 4.
- if (MaskedValueIsZero(LHSI->getOperand(0),
+ if (LHSI->hasOneUse() &&
+ MaskedValueIsZero(LHSI->getOperand(0),
APInt::getLowBitsSet(Comp.getBitWidth(), ShAmtVal))) {
return new ICmpInst(ICI.getPredicate(), LHSI->getOperand(0),
ConstantExpr::getShl(RHS, ShAmt));
}
- if (LHSI->hasOneUse() || RHSV == 0) {
+ if (LHSI->hasOneUse()) {
// Otherwise strength reduce the shift into an and.
APInt Val(APInt::getHighBitsSet(TypeBits, TypeBits - ShAmtVal));
Constant *Mask = ConstantInt::get(Val);
diff --git a/test/Transforms/InstCombine/shl-icmp.ll b/test/Transforms/InstCombine/shl-icmp.ll
new file mode 100644
index 0000000000..234c40bf68
--- /dev/null
+++ b/test/Transforms/InstCombine/shl-icmp.ll
@@ -0,0 +1,29 @@
+; RUN: llvm-as < %s | opt -instcombine -stats -disable-output |& \
+; RUN: grep {Number of insts combined} | grep 5
+
+define i8 @t1(i8 zeroext %x, i8 zeroext %y) zeroext nounwind {
+entry:
+ %tmp1 = lshr i8 %x, 7
+ %cond1 = icmp ne i8 %tmp1, 0
+ br i1 %cond1, label %bb1, label %bb2
+
+bb1:
+ ret i8 %tmp1
+
+bb2:
+ %tmp2 = add i8 %tmp1, %y
+ ret i8 %tmp2
+}
+
+define i8 @t2(i8 zeroext %x) zeroext nounwind {
+entry:
+ %tmp1 = lshr i8 %x, 7
+ %cond1 = icmp ne i8 %tmp1, 0
+ br i1 %cond1, label %bb1, label %bb2
+
+bb1:
+ ret i8 0
+
+bb2:
+ ret i8 1
+}