[llvm] [AArch64] Adjust comparison constant if adjusting it means less instructions (PR #151024)
David Green via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 11 02:05:51 PDT 2025
================
@@ -3969,42 +3977,45 @@ static SDValue getAArch64Cmp(SDValue LHS, SDValue RHS, ISD::CondCode CC,
case ISD::SETGE:
if (!C.isMinSignedValue()) {
APInt CMinusOne = C - 1;
- if (isLegalCmpImmed(CMinusOne)) {
+ if (isLegalCmpImmed(CMinusOne) ||
+ (NumImmForC > numberOfInstrToLoadImm(CMinusOne))) {
CC = (CC == ISD::SETLT) ? ISD::SETLE : ISD::SETGT;
RHS = DAG.getConstant(CMinusOne, DL, VT);
}
}
break;
case ISD::SETULT:
- case ISD::SETUGE:
- if (!C.isZero()) {
- APInt CMinusOne = C - 1;
- if (isLegalCmpImmed(CMinusOne)) {
- CC = (CC == ISD::SETULT) ? ISD::SETULE : ISD::SETUGT;
- RHS = DAG.getConstant(CMinusOne, DL, VT);
- }
+ case ISD::SETUGE: {
+ // C is not 0 because it is a legal immediate.
+ APInt CMinusOne = C - 1;
+ if (isLegalCmpImmed(CMinusOne) ||
+ (NumImmForC > numberOfInstrToLoadImm(CMinusOne))) {
+ CC = (CC == ISD::SETULT) ? ISD::SETULE : ISD::SETUGT;
+ RHS = DAG.getConstant(CMinusOne, DL, VT);
}
- break;
+ } break;
case ISD::SETLE:
case ISD::SETGT:
if (!C.isMaxSignedValue()) {
APInt CPlusOne = C + 1;
- if (isLegalCmpImmed(CPlusOne)) {
+ if (isLegalCmpImmed(CPlusOne) ||
+ (NumImmForC > numberOfInstrToLoadImm(CPlusOne))) {
CC = (CC == ISD::SETLE) ? ISD::SETLT : ISD::SETGE;
RHS = DAG.getConstant(CPlusOne, DL, VT);
}
}
break;
case ISD::SETULE:
- case ISD::SETUGT:
- if (!C.isAllOnes()) {
- APInt CPlusOne = C + 1;
- if (isLegalCmpImmed(CPlusOne)) {
- CC = (CC == ISD::SETULE) ? ISD::SETULT : ISD::SETUGE;
- RHS = DAG.getConstant(CPlusOne, DL, VT);
- }
+ case ISD::SETUGT: {
+ // The maxmimum possible number, -1, is a legal cmp immediate, so no
+ // need to check for it.
----------------
davemgreen wrote:
Same here for the assert and the }.
https://github.com/llvm/llvm-project/pull/151024
More information about the llvm-commits
mailing list