Skip to content

Commit e5baf07

Browse files
authored
[AArch64] Generalize CSEL a, b, cc, SUBS(SUB(x,y), 0) -> CSEL a, b, cc, SUBS(x,y) transform to peephole (#167527)
This transform should have never been done in ISel in the first place. It should have been done in peephole, but a few cases were missing.
1 parent 4cd8361 commit e5baf07

File tree

4 files changed

+116
-245
lines changed

4 files changed

+116
-245
lines changed

llvm/lib/Target/AArch64/AArch64ISelLowering.cpp

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26117,29 +26117,6 @@ static SDValue performCSELCombine(SDNode *N,
2611726117
}
2611826118
}
2611926119

26120-
// CSEL a, b, cc, SUBS(SUB(x,y), 0) -> CSEL a, b, cc, SUBS(x,y) if cc doesn't
26121-
// use overflow flags, to avoid the comparison with zero. In case of success,
26122-
// this also replaces the original SUB(x,y) with the newly created SUBS(x,y).
26123-
// NOTE: Perhaps in the future use performFlagSettingCombine to replace SUB
26124-
// nodes with their SUBS equivalent as is already done for other flag-setting
26125-
// operators, in which case doing the replacement here becomes redundant.
26126-
if (Cond.getOpcode() == AArch64ISD::SUBS && Cond->hasNUsesOfValue(1, 1) &&
26127-
isNullConstant(Cond.getOperand(1))) {
26128-
SDValue Sub = Cond.getOperand(0);
26129-
AArch64CC::CondCode CC =
26130-
static_cast<AArch64CC::CondCode>(N->getConstantOperandVal(2));
26131-
if (Sub.getOpcode() == ISD::SUB &&
26132-
(CC == AArch64CC::EQ || CC == AArch64CC::NE || CC == AArch64CC::MI ||
26133-
CC == AArch64CC::PL)) {
26134-
SDLoc DL(N);
26135-
SDValue Subs = DAG.getNode(AArch64ISD::SUBS, DL, Cond->getVTList(),
26136-
Sub.getOperand(0), Sub.getOperand(1));
26137-
DCI.CombineTo(Sub.getNode(), Subs);
26138-
DCI.CombineTo(Cond.getNode(), Subs, Subs.getValue(1));
26139-
return SDValue(N, 0);
26140-
}
26141-
}
26142-
2614326120
// CSEL (LASTB P, Z), X, NE(ANY P) -> CLASTB P, X, Z
2614426121
if (SDValue CondLast = foldCSELofLASTB(N, DAG))
2614526122
return CondLast;

llvm/lib/Target/AArch64/AArch64InstrInfo.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1776,10 +1776,14 @@ static unsigned sForm(MachineInstr &Instr) {
17761776
case AArch64::ADDSWri:
17771777
case AArch64::ADDSXrr:
17781778
case AArch64::ADDSXri:
1779+
case AArch64::ADDSWrx:
1780+
case AArch64::ADDSXrx:
17791781
case AArch64::SUBSWrr:
17801782
case AArch64::SUBSWri:
1783+
case AArch64::SUBSWrx:
17811784
case AArch64::SUBSXrr:
17821785
case AArch64::SUBSXri:
1786+
case AArch64::SUBSXrx:
17831787
case AArch64::ANDSWri:
17841788
case AArch64::ANDSWrr:
17851789
case AArch64::ANDSWrs:
@@ -1800,6 +1804,10 @@ static unsigned sForm(MachineInstr &Instr) {
18001804
return AArch64::ADDSXrr;
18011805
case AArch64::ADDXri:
18021806
return AArch64::ADDSXri;
1807+
case AArch64::ADDWrx:
1808+
return AArch64::ADDSWrx;
1809+
case AArch64::ADDXrx:
1810+
return AArch64::ADDSXrx;
18031811
case AArch64::ADCWr:
18041812
return AArch64::ADCSWr;
18051813
case AArch64::ADCXr:
@@ -1812,6 +1820,10 @@ static unsigned sForm(MachineInstr &Instr) {
18121820
return AArch64::SUBSXrr;
18131821
case AArch64::SUBXri:
18141822
return AArch64::SUBSXri;
1823+
case AArch64::SUBWrx:
1824+
return AArch64::SUBSWrx;
1825+
case AArch64::SUBXrx:
1826+
return AArch64::SUBSXrx;
18151827
case AArch64::SBCWr:
18161828
return AArch64::SBCSWr;
18171829
case AArch64::SBCXr:

0 commit comments

Comments
 (0)