mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-13 20:32:21 +00:00
InstSimplify: Simplify (sub 0, X) -> X if it's NUW
This is a generalization of the X - (0 - Y) -> X transform. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@222611 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
1c4abdb6ab
commit
7eca618dfc
@ -683,17 +683,9 @@ static Value *SimplifySubInst(Value *Op0, Value *Op1, bool isNSW, bool isNUW,
|
|||||||
if (Op0 == Op1)
|
if (Op0 == Op1)
|
||||||
return Constant::getNullValue(Op0->getType());
|
return Constant::getNullValue(Op0->getType());
|
||||||
|
|
||||||
// X - (0 - Y) -> X if the second sub is NUW.
|
// 0 - X -> 0 if the sub is NUW.
|
||||||
// If Y != 0, 0 - Y is a poison value.
|
if (isNUW && match(Op0, m_Zero()))
|
||||||
// If Y == 0, 0 - Y simplifies to 0.
|
return Op0;
|
||||||
if (BinaryOperator::isNeg(Op1)) {
|
|
||||||
if (const auto *BO = dyn_cast<BinaryOperator>(Op1)) {
|
|
||||||
assert(BO->getOpcode() == Instruction::Sub &&
|
|
||||||
"Expected a subtraction operator!");
|
|
||||||
if (BO->hasNoUnsignedWrap())
|
|
||||||
return Op0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// (X + Y) - Z -> X + (Y - Z) or Y + (X - Z) if everything simplifies.
|
// (X + Y) - Z -> X + (Y - Z) or Y + (X - Z) if everything simplifies.
|
||||||
// For example, (X + Y) - Y -> X; (Y + X) - Y -> X
|
// For example, (X + Y) - Y -> X; (Y + X) - Y -> X
|
||||||
|
@ -148,3 +148,10 @@ define i1 @or_of_icmps5(i32 %b) {
|
|||||||
ret i1 %cmp
|
ret i1 %cmp
|
||||||
; CHECK: ret i1 true
|
; CHECK: ret i1 true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
define i32 @neg_nuw(i32 %x) {
|
||||||
|
; CHECK-LABEL: @neg_nuw(
|
||||||
|
%neg = sub nuw i32 0, %x
|
||||||
|
ret i32 %neg
|
||||||
|
; CHECK: ret i32 0
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user