[llvm] [AArch64][Codegen]Transform saturating smull to sqdmulh (PR #143671)
David Green via llvm-commits
llvm-commits at lists.llvm.org
Sun Jun 29 13:24:29 PDT 2025
================
@@ -20717,6 +20717,83 @@ static SDValue performBuildVectorCombine(SDNode *N,
return SDValue();
}
+// A special combine for the vqdmulh family of instructions.
+// smin( sra ( mul( sext v0, sext v1 ) ), SHIFT_AMOUNT ),
+// SATURATING_VAL ) can be reduced to sext(sqdmulh(...))
+static SDValue trySQDMULHCombine(SDNode *N, SelectionDAG &DAG) {
+
+ if (N->getOpcode() != ISD::TRUNCATE)
+ return SDValue();
+
+ EVT VT = N->getValueType(0);
+
+ if (!VT.isVector() || VT.getScalarSizeInBits() > 64)
+ return SDValue();
+
+ SDValue SMin = N->getOperand(0);
+
+ if (SMin.getOpcode() != ISD::SMIN)
+ return SDValue();
+
+ ConstantSDNode *Clamp = isConstOrConstSplat(SMin.getOperand(1));
+
+ if (!Clamp)
+ return SDValue();
+
+ MVT ScalarType;
+ unsigned ShiftAmt = 0;
+ switch (Clamp->getSExtValue()) {
+ case (1ULL << 15) - 1:
+ ScalarType = MVT::i16;
+ ShiftAmt = 16;
+ break;
+ case (1ULL << 31) - 1:
+ ScalarType = MVT::i32;
----------------
davemgreen wrote:
ScalarType isn't used. It could check is matches the SExt scalar type.
I might be good to have test cases for edge conditions like that too.
https://github.com/llvm/llvm-project/pull/143671
More information about the llvm-commits
mailing list