[llvm] r185973 - InstSimplify: X >> X -> 0

David Majnemer david.majnemer at gmail.com
Tue Jul 9 15:01:22 PDT 2013


Author: majnemer
Date: Tue Jul  9 17:01:22 2013
New Revision: 185973

URL: http://llvm.org/viewvc/llvm-project?rev=185973&view=rev
Log:
InstSimplify: X >> X -> 0

Modified:
    llvm/trunk/lib/Analysis/InstructionSimplify.cpp
    llvm/trunk/test/Transforms/InstCombine/div-shift.ll
    llvm/trunk/test/Transforms/InstSimplify/compare.ll

Modified: llvm/trunk/lib/Analysis/InstructionSimplify.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/InstructionSimplify.cpp?rev=185973&r1=185972&r2=185973&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/InstructionSimplify.cpp (original)
+++ llvm/trunk/lib/Analysis/InstructionSimplify.cpp Tue Jul  9 17:01:22 2013
@@ -1363,6 +1363,10 @@ static Value *SimplifyLShrInst(Value *Op
   if (Value *V = SimplifyShift(Instruction::LShr, Op0, Op1, Q, MaxRecurse))
     return V;
 
+  // X >> X -> 0
+  if (Op0 == Op1)
+    return Constant::getNullValue(Op0->getType());
+
   // undef >>l X -> 0
   if (match(Op0, m_Undef()))
     return Constant::getNullValue(Op0->getType());
@@ -1391,6 +1395,10 @@ static Value *SimplifyAShrInst(Value *Op
   if (Value *V = SimplifyShift(Instruction::AShr, Op0, Op1, Q, MaxRecurse))
     return V;
 
+  // X >> X -> 0
+  if (Op0 == Op1)
+    return Constant::getNullValue(Op0->getType());
+
   // all ones >>a X -> all ones
   if (match(Op0, m_AllOnes()))
     return Op0;

Modified: llvm/trunk/test/Transforms/InstCombine/div-shift.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/div-shift.ll?rev=185973&r1=185972&r2=185973&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/div-shift.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/div-shift.ll Tue Jul  9 17:01:22 2013
@@ -54,9 +54,9 @@ define i32 @t5(i1 %x, i1 %y, i32 %V) nou
 ; CHECK: t5
 ; CHECK-NOT: udiv
 ; CHECK-NEXT: [[SEL1:%.*]] = select i1 %x, i32 5, i32 6
-; CHECK-NEXT: [[SEL2:%.*]] = select i1 %y, i32 [[SEL1]], i32 %V
-; CHECK-NEXT: [[LSHR:%.*]] = lshr i32 %V, [[SEL2]]
-; CHECK-NEXT: ret i32 [[LSHR]]
+; CHECK-NEXT: [[LSHR:%.*]] = lshr i32 %V, [[SEL1]]
+; CHECK-NEXT: [[SEL2:%.*]] = select i1 %y, i32 [[LSHR]], i32 0
+; CHECK-NEXT: ret i32 [[SEL2]]
   %1 = shl i32 1, %V
   %2 = select i1 %x, i32 32, i32 64
   %3 = select i1 %y, i32 %2, i32 %1

Modified: llvm/trunk/test/Transforms/InstSimplify/compare.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstSimplify/compare.ll?rev=185973&r1=185972&r2=185973&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstSimplify/compare.ll (original)
+++ llvm/trunk/test/Transforms/InstSimplify/compare.ll Tue Jul  9 17:01:22 2013
@@ -357,6 +357,14 @@ define i1 @lshr2(i32 %x) {
 ; CHECK: ret i1 false
 }
 
+define i1 @lshr3(i32 %x) {
+; CHECK: @lshr3
+  %s = lshr i32 %x, %x
+  %c = icmp eq i32 %s, 0
+  ret i1 %c
+; CHECK: ret i1 true
+}
+
 define i1 @ashr1(i32 %x) {
 ; CHECK: @ashr1
   %s = ashr i32 -1, %x
@@ -373,6 +381,14 @@ define i1 @ashr2(i32 %x) {
 ; CHECK: ret i1 false
 }
 
+define i1 @ashr3(i32 %x) {
+; CHECK: @ashr3
+  %s = ashr i32 %x, %x
+  %c = icmp eq i32 %s, 0
+  ret i1 %c
+; CHECK: ret i1 true
+}
+
 define i1 @select1(i1 %cond) {
 ; CHECK: @select1
   %s = select i1 %cond, i32 1, i32 0





More information about the llvm-commits mailing list