[llvm-commits] [llvm] r50118 - in /llvm/trunk: lib/Transforms/Scalar/InstructionCombining.cpp test/Transforms/InstCombine/shl-icmp.ll

Evan Cheng evan.cheng at apple.com
Tue Apr 22 17:38:06 PDT 2008


Author: evancheng
Date: Tue Apr 22 19:38:06 2008
New Revision: 50118

URL: http://llvm.org/viewvc/llvm-project?rev=50118&view=rev
Log:
Don't do: "(X & 4) >> 1 == 2  --> (X & 4) == 4" if there are more than one uses of the shift result.

Added:
    llvm/trunk/test/Transforms/InstCombine/shl-icmp.ll
Modified:
    llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp

Modified: llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp?rev=50118&r1=50117&r2=50118&view=diff

==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp Tue Apr 22 19:38:06 2008
@@ -6065,13 +6065,14 @@
     // 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);

Added: llvm/trunk/test/Transforms/InstCombine/shl-icmp.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/shl-icmp.ll?rev=50118&view=auto

==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/shl-icmp.ll (added)
+++ llvm/trunk/test/Transforms/InstCombine/shl-icmp.ll Tue Apr 22 19:38:06 2008
@@ -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
+}





More information about the llvm-commits mailing list