[llvm] [AArch64] Transform add(x, abs(y)) -> saba(x, y, 0) (PR #156615)
David Sherwood via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 3 05:48:27 PDT 2025
================
@@ -21913,6 +21914,56 @@ static SDValue performExtBinopLoadFold(SDNode *N, SelectionDAG &DAG) {
return DAG.getNode(N->getOpcode(), DL, VT, Ext0, NShift);
}
+// Transform the following:
+// - add(x, abs(y)) -> saba(x, y, 0)
+// - add(x, zext(abs(y))) -> sabal(x, y, 0)
+static SDValue performAddSABACombine(SDNode *N,
+ TargetLowering::DAGCombinerInfo &DCI) {
+ if (N->getOpcode() != ISD::ADD)
+ return SDValue();
+
+ EVT VT = N->getValueType(0);
+ if (!VT.isFixedLengthVector())
+ return SDValue();
+
+ SDValue N0 = N->getOperand(0);
+ SDValue N1 = N->getOperand(1);
+
+ auto MatchAbsOrZExtAbs = [](SDValue V0, SDValue V1, SDValue &AbsOp,
+ SDValue &Other, bool &IsZExt) {
+ Other = V1;
----------------
david-arm wrote:
I realise with your code below it's not a problem right now, but I think it' still worth only setting `Other` if we found a match.
https://github.com/llvm/llvm-project/pull/156615
More information about the llvm-commits
mailing list