[llvm] [AArch64] Eliminate Common SUBS by Reassociating Non-Constants (PR #123344)
David Green via llvm-commits
llvm-commits at lists.llvm.org
Sat Jan 18 10:27:15 PST 2025
================
@@ -24899,16 +24899,36 @@ static SDValue reassociateCSELOperandsForCSE(SDNode *N, SelectionDAG &DAG) {
SDValue SubsNode = N->getOperand(3);
if (SubsNode.getOpcode() != AArch64ISD::SUBS || !SubsNode.hasOneUse())
return SDValue();
- auto *CmpOpConst = dyn_cast<ConstantSDNode>(SubsNode.getOperand(1));
- if (!CmpOpConst)
- return SDValue();
+ SDValue CmpOpToMatch = SubsNode.getOperand(1);
SDValue CmpOpOther = SubsNode.getOperand(0);
EVT VT = N->getValueType(0);
+ unsigned ExpectedOpcode;
+ std::function<bool(SDValue)> CheckOp;
+ std::function<SDValue()> BuildSubsOp;
+ auto *CmpOpConst = dyn_cast<ConstantSDNode>(CmpOpToMatch);
+ if (CmpOpConst) {
+ ExpectedOpcode = ISD::ADD;
+ CheckOp = [&](SDValue Op) {
+ auto *AddOpConst = dyn_cast<ConstantSDNode>(Op);
+ return AddOpConst &&
+ AddOpConst->getAPIntValue() == -CmpOpConst->getAPIntValue();
+ };
+ BuildSubsOp = [&] {
+ return DAG.getConstant(CmpOpConst->getAPIntValue(), SDLoc(CmpOpConst),
----------------
davemgreen wrote:
Constants are OK to create if it helps remove the functions pointers, they are simpler than other instructions (and feel like the lesser of two evils) :)
https://github.com/llvm/llvm-project/pull/123344
More information about the llvm-commits
mailing list