From a17a9dc8df60745a97b98f4e33b11c5d26b49225 Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Mon, 24 Nov 2014 16:41:13 +0000 Subject: [PATCH] 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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@222659 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/InstCombine/InstCombineMulDivRem.cpp | 3 +-- test/Transforms/InstCombine/mul.ll | 10 ++++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp b/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp index d7847ca5ccd..3956869e2d3 100644 --- a/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp +++ b/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp @@ -300,8 +300,7 @@ Instruction *InstCombiner::visitMul(BinaryOperator &I) { if (match(Op0, m_Shl(m_One(), m_Value(Y)))) { BO = BinaryOperator::CreateShl(Op1, Y); ShlNSW = cast(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(Op1)->hasNoSignedWrap(); } diff --git a/test/Transforms/InstCombine/mul.ll b/test/Transforms/InstCombine/mul.ll index 934448290e0..a52c31ab4af 100644 --- a/test/Transforms/InstCombine/mul.ll +++ b/test/Transforms/InstCombine/mul.ll @@ -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]] +} -- 2.34.1