[llvm] [RISCV][WIP] Optimize sum of absolute differences pattern. (PR #82722)
Philip Reames via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 23 12:15:49 PST 2024
================
@@ -13176,6 +13176,61 @@ static SDValue performXORCombine(SDNode *N, SelectionDAG &DAG,
return combineSelectAndUseCommutative(N, DAG, /*AllOnes*/ false, Subtarget);
}
+// Look for (abs (sub (zext X), (zext Y))).
+// Rewrite as (zext (sub (zext (max X, Y), (min X, Y)))) if the user is an add
+// or reduction add. The min/max can be done in parallel and with a lower LMUL
+// than the original code. The two zexts can be folded into widening sub and
+// widening add or widening redsum.
+static SDValue performABSCombine(SDNode *N, SelectionDAG &DAG) {
+ EVT VT = N->getValueType(0);
+ const TargetLowering &TLI = DAG.getTargetLoweringInfo();
+
+ if (!VT.isFixedLengthVector() || VT.getVectorElementType() != MVT::i32 ||
+ !TLI.isTypeLegal(VT))
+ return SDValue();
+
+ SDValue Src = N->getOperand(0);
+ if (Src.getOpcode() != ISD::SUB || !Src.hasOneUse())
+ return SDValue();
+
+ // Make sure the use is an add or reduce add so the zext we create at the end
+ // will be folded.
+ if (!N->hasOneUse() || (N->use_begin()->getOpcode() != ISD::ADD &&
----------------
preames wrote:
Instead of this, we can focus on the fact this allows a narrower representation.
https://github.com/llvm/llvm-project/pull/82722
More information about the llvm-commits
mailing list