mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-04-06 09:44:39 +00:00
InstCombine: Propagate NSW for -X * -Y -> X * Y
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@222612 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
7eca618dfc
commit
082eff658e
@ -237,9 +237,16 @@ Instruction *InstCombiner::visitMul(BinaryOperator &I) {
|
||||
}
|
||||
}
|
||||
|
||||
if (Value *Op0v = dyn_castNegVal(Op0)) // -X * -Y = X*Y
|
||||
if (Value *Op1v = dyn_castNegVal(Op1))
|
||||
return BinaryOperator::CreateMul(Op0v, Op1v);
|
||||
if (Value *Op0v = dyn_castNegVal(Op0)) { // -X * -Y = X*Y
|
||||
if (Value *Op1v = dyn_castNegVal(Op1)) {
|
||||
BinaryOperator *BO = BinaryOperator::CreateMul(Op0v, Op1v);
|
||||
if (I.hasNoSignedWrap() &&
|
||||
match(Op0, m_NSWSub(m_Value(), m_Value())) &&
|
||||
match(Op1, m_NSWSub(m_Value(), m_Value())))
|
||||
BO->setHasNoSignedWrap();
|
||||
return BO;
|
||||
}
|
||||
}
|
||||
|
||||
// (X / Y) * Y = X - (X % Y)
|
||||
// (X / Y) * -Y = (X % Y) - X
|
||||
|
@ -220,3 +220,12 @@ define i32 @test24(i32 %A) {
|
||||
ret i32 %C
|
||||
; CHECK: mul nsw i32 %A, 6
|
||||
}
|
||||
|
||||
define i32 @test25(i32 %A, i32 %B) {
|
||||
; CHECK-LABEL: @test25(
|
||||
%C = sub nsw i32 0, %A
|
||||
%D = sub nsw i32 0, %B
|
||||
%E = mul nsw i32 %C, %D
|
||||
ret i32 %E
|
||||
; CHECK: mul nsw i32 %A, %B
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user