[PATCH] D137936: [AArch64] Optimize cmp chain before legalization
chenglin.bi via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Nov 20 22:37:31 PST 2022
bcl5980 added inline comments.
================
Comment at: llvm/lib/Target/AArch64/AArch64ISelLowering.cpp:8614
// Exit early by inverting the condition, which help reduce indentations.
- SDValue TVal = DAG.getConstant(1, DL, VT);
- SDValue FVal = DAG.getConstant(0, DL, VT);
- AArch64CC::CondCode CC = changeIntCCToAArch64CC(Cond);
- AArch64CC::CondCode InvCC = AArch64CC::getInvertedCondCode(CC);
- return DAG.getNode(AArch64ISD::CSEL, DL, VT, FVal, TVal,
- DAG.getConstant(InvCC, DL, MVT::i32), CCmp);
+ return DAG.getSetCC(DL, VT, Cmp, DAG.getConstant(0, DL, VT), Cond);
}
----------------
It looks this can continue to be simplified to
```
unsigned LogicOp = (Cond == ISD::SETEQ) ? ISD::AND : ISD::OR;
SDValue Cmp = DAG.getSetCC(DL, VT, XOR0, XOR1, Cond);
for (unsigned I = 1; I < WorkList.size(); I++) {
std::tie(XOR0, XOR1) = WorkList[I];
SDValue CmpChain = DAG.getSetCC(DL, VT, XOR0, XOR1, Cond);
Cmp = DAG.getNode(LogicOp, DL, VT, Cmp, CmpChain);
}
return Cmp;
```
Looks more cases can get benefit from it.
================
Comment at: llvm/test/CodeGen/AArch64/dag-combine-setcc.ll:224
; CHECK-NEXT: sbc x9, x3, x10
-; CHECK-NEXT: ccmp x3, x10, #0, eq
-; CHECK-NEXT: b.ne .LBB12_1
+; CHECK-NEXT: cset w11, ne
+; CHECK-NEXT: cmp x3, x10
----------------
bcl5980 wrote:
> Looks regression for this case?
This regression cmp x3, x10 part is a little tricky. It depends on the tree search sequence. If we search RHS first it will disappear. But I don't know how to fix it by a elegant way.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D137936/new/
https://reviews.llvm.org/D137936
More information about the llvm-commits
mailing list