mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-14 11:32:34 +00:00
InstCombine: Preserve nsw for (mul %V, -1) -> (sub 0, %V)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@222604 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
5182ad54b2
commit
0f8991742c
@ -136,8 +136,13 @@ Instruction *InstCombiner::visitMul(BinaryOperator &I) {
|
||||
if (Value *V = SimplifyUsingDistributiveLaws(I))
|
||||
return ReplaceInstUsesWith(I, V);
|
||||
|
||||
if (match(Op1, m_AllOnes())) // X * -1 == 0 - X
|
||||
return BinaryOperator::CreateNeg(Op0, I.getName());
|
||||
// X * -1 == 0 - X
|
||||
if (match(Op1, m_AllOnes())) {
|
||||
BinaryOperator *BO = BinaryOperator::CreateNeg(Op0, I.getName());
|
||||
if (I.hasNoSignedWrap())
|
||||
BO->setHasNoSignedWrap();
|
||||
return BO;
|
||||
}
|
||||
|
||||
// Also allow combining multiply instructions on vectors.
|
||||
{
|
||||
|
@ -197,3 +197,10 @@ define <2 x i1> @test21(<2 x i1> %A, <2 x i1> %B) {
|
||||
ret <2 x i1> %C
|
||||
; CHECK: %C = and <2 x i1> %A, %B
|
||||
}
|
||||
|
||||
define i32 @test22(i32 %A) {
|
||||
; CHECK-LABEL: @test22(
|
||||
%B = mul nsw i32 %A, -1
|
||||
ret i32 %B
|
||||
; CHECK: sub nsw i32 0, %A
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user