[llvm] r225127 - InstCombine: match can find ConstantExprs, don't assume we have a Value

David Majnemer david.majnemer at gmail.com
Sat Jan 3 23:36:02 PST 2015


Author: majnemer
Date: Sun Jan  4 01:36:02 2015
New Revision: 225127

URL: http://llvm.org/viewvc/llvm-project?rev=225127&view=rev
Log:
InstCombine: match can find ConstantExprs, don't assume we have a Value

We assumed the output of a match was a Value, this would cause us to
assert because we would fail a cast<>.  Instead, use a helper in the
Operator family to hide the distinction between Value and Constant.

This fixes PR22087.

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=225127&r1=225126&r2=225127&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp Sun Jan  4 01:36:02 2015
@@ -341,10 +341,10 @@ Instruction *InstCombiner::visitMul(Bina
     bool ShlNSW = false;
     if (match(Op0, m_Shl(m_One(), m_Value(Y)))) {
       BO = BinaryOperator::CreateShl(Op1, Y);
-      ShlNSW = cast<BinaryOperator>(Op0)->hasNoSignedWrap();
+      ShlNSW = cast<ShlOperator>(Op0)->hasNoSignedWrap();
     } else if (match(Op1, m_Shl(m_One(), m_Value(Y)))) {
       BO = BinaryOperator::CreateShl(Op0, Y);
-      ShlNSW = cast<BinaryOperator>(Op1)->hasNoSignedWrap();
+      ShlNSW = cast<ShlOperator>(Op1)->hasNoSignedWrap();
     }
     if (BO) {
       if (I.hasNoUnsignedWrap())

Modified: llvm/trunk/test/Transforms/InstCombine/mul.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/mul.ll?rev=225127&r1=225126&r2=225127&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/mul.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/mul.ll Sun Jan  4 01:36:02 2015
@@ -279,3 +279,12 @@ define i64 @test30(i32 %A, i32 %B) {
 ; CHECK-NEXT: %[[mul:.*]] = mul nuw i64 %[[zext1]], %[[zext2]]
 ; CHECK-NEXT: ret i64 %[[mul]]
 }
+
+ at PR22087 = external global i32
+define i32 @test31(i32 %V) {
+; CHECK-LABEL: @test31
+  %mul = mul i32 %V, shl (i32 1, i32 zext (i1 icmp ne (i32* inttoptr (i64 1 to i32*), i32* @PR22087) to i32))
+  ret i32 %mul
+; CHECK:      %[[mul:.*]] = shl i32 %V, zext (i1 icmp ne (i32* inttoptr (i64 1 to i32*), i32* @PR22087) to i32)
+; CHECK-NEXT: ret i32 %[[mul]]
+}





More information about the llvm-commits mailing list