Skip to content

Commit

Permalink
InstCombine: Don't create an unused instruction
Browse files Browse the repository at this point in the history
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
  • Loading branch information
majnemer committed Nov 24, 2014
1 parent c195267 commit a17a9dc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
3 changes: 1 addition & 2 deletions lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<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();
}
Expand Down
10 changes: 10 additions & 0 deletions test/Transforms/InstCombine/mul.ll
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
}

0 comments on commit a17a9dc

Please sign in to comment.