mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-13 10:32:06 +00:00
Canonicalize -1 - x to ~x.
Instcombine does this but apparently there are situations where this pattern will escape the optimizer and / or created by isel. Here is a case that's seen in JavaScriptCore: %t1 = sub i32 0, %a %t2 = add i32 %t1, -1 The dag combiner pattern: ((c1-A)+c2) -> (c1+c2)-A will fold it to -1 - %a. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@93773 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
2d53c21eca
commit
1ad0e8b576
@ -1176,6 +1176,9 @@ SDValue DAGCombiner::visitSUB(SDNode *N) {
|
|||||||
if (N1C)
|
if (N1C)
|
||||||
return DAG.getNode(ISD::ADD, N->getDebugLoc(), VT, N0,
|
return DAG.getNode(ISD::ADD, N->getDebugLoc(), VT, N0,
|
||||||
DAG.getConstant(-N1C->getAPIntValue(), VT));
|
DAG.getConstant(-N1C->getAPIntValue(), VT));
|
||||||
|
// Canonicalize (sub -1, x) -> ~x, i.e. (xor x, -1)
|
||||||
|
if (N0C && N0C->isAllOnesValue())
|
||||||
|
return DAG.getNode(ISD::XOR, N->getDebugLoc(), VT, N1, N0);
|
||||||
// fold (A+B)-A -> B
|
// fold (A+B)-A -> B
|
||||||
if (N0.getOpcode() == ISD::ADD && N0.getOperand(0) == N1)
|
if (N0.getOpcode() == ISD::ADD && N0.getOperand(0) == N1)
|
||||||
return N0.getOperand(1);
|
return N0.getOperand(1);
|
||||||
|
@ -131,3 +131,14 @@ bb12:
|
|||||||
; X32: andl {{.*}}[[REG]]
|
; X32: andl {{.*}}[[REG]]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
define i32 @test8(i32 %a) nounwind {
|
||||||
|
; rdar://7553032
|
||||||
|
entry:
|
||||||
|
%t1 = sub i32 0, %a
|
||||||
|
%t2 = add i32 %t1, -1
|
||||||
|
ret i32 %t2
|
||||||
|
; X64: test8:
|
||||||
|
; X64: notl %eax
|
||||||
|
; X32: test8:
|
||||||
|
; X32: notl %eax
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user