[llvm] r222659 - InstCombine: Don't create an unused instruction

David Majnemer david.majnemer at gmail.com
Mon Nov 24 08:41:13 PST 2014


Author: majnemer
Date: Mon Nov 24 10:41:13 2014
New Revision: 222659

URL: http://llvm.org/viewvc/llvm-project?rev=222659&view=rev
Log:
InstCombine: Don't create an unused instruction

We would create an instruction but not inserting it.
Not inserting the unused instruction would lead us to verification
failure.

This fixes PR21653.

Modified:
    llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
    llvm/trunk/test/Transforms/InstCombine/mul.ll

Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp?rev=222659&r1=222658&r2=222659&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp Mon Nov 24 10:41:13 2014
@@ -300,8 +300,7 @@ Instruction *InstCombiner::visitMul(Bina
     if (match(Op0, m_Shl(m_One(), m_Value(Y)))) {
       BO = BinaryOperator::CreateShl(Op1, Y);
       ShlNSW = cast<BinaryOperator>(Op0)->hasNoSignedWrap();
-    }
-    if (match(Op1, m_Shl(m_One(), m_Value(Y)))) {
+    } else if (match(Op1, m_Shl(m_One(), m_Value(Y)))) {
       BO = BinaryOperator::CreateShl(Op0, Y);
       ShlNSW = cast<BinaryOperator>(Op1)->hasNoSignedWrap();
     }

Modified: llvm/trunk/test/Transforms/InstCombine/mul.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/mul.ll?rev=222659&r1=222658&r2=222659&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/mul.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/mul.ll Mon Nov 24 10:41:13 2014
@@ -245,3 +245,13 @@ define i32 @test27(i32 %A, i32 %B) {
         ret i32 %D
 ; CHECK: shl nuw i32 %A, %B
 }
+
+define i32 @test28(i32 %A) {
+; CHECK-LABEL: @test28(
+        %B = shl i32 1, %A
+        %C = mul nsw i32 %B, %B
+        ret i32 %C
+; CHECK:      %[[shl1:.*]] = shl i32 1, %A
+; CHECK-NEXT: %[[shl2:.*]] = shl i32 %[[shl1]], %A
+; CHECK-NEXT: ret i32 %[[shl2]]
+}





More information about the llvm-commits mailing list