[llvm] [X86] Recognise VPMADD52L pattern with AVX512IFMA/AVXIFMA (#153787) (PR #156714)
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 9 01:50:40 PDT 2025
================
@@ -57966,6 +57966,49 @@ static SDValue pushAddIntoCmovOfConsts(SDNode *N, const SDLoc &DL,
Cmov.getOperand(3));
}
+// Attempt to turn ADD(MUL(x, y), acc)) -> VPMADD52L
+// When upper 12 bits of x, y and MUL(x, y) are known to be 0
+static SDValue matchVPMADD52(SDNode *N, SelectionDAG &DAG, const SDLoc &DL,
+ EVT VT, const X86Subtarget &Subtarget) {
+ using namespace SDPatternMatch;
+ if (!VT.isVector() || VT.getScalarSizeInBits() != 64 ||
+ (!Subtarget.hasAVXIFMA() && !Subtarget.hasIFMA()))
+ return SDValue();
+
+ // Need AVX-512VL vector length extensions if operating on XMM/YMM registers
+ if (!Subtarget.hasAVXIFMA() && !Subtarget.hasVLX() &&
+ VT.getSizeInBits() < 512)
+ return SDValue();
+
+ const auto TotalSize = VT.getSizeInBits();
+ if (TotalSize < 128 || !isPowerOf2_64(TotalSize))
+ return SDValue();
+
+ SDValue X, Y, Acc;
+ if (!sd_match(N, m_Add(m_Mul(m_Value(X), m_Value(Y)), m_Value(Acc))))
+ return SDValue();
+
+ KnownBits KnownX = DAG.computeKnownBits(X);
+ KnownBits KnownY = DAG.computeKnownBits(Y);
+ KnownBits KnownMul = KnownBits::mul(KnownX, KnownY);
+ if (KnownX.countMinLeadingZeros() < 12 ||
+ KnownY.countMinLeadingZeros() < 12 ||
+ KnownMul.countMinLeadingZeros() < 12)
+ return SDValue();
----------------
RKSimon wrote:
computeKnownBits can be expensive - we're better off doing early-outs if the tests fail:
```
KnownBits KnownX = DAG.computeKnownBits(X);
if (KnownX.countMinLeadingZeros() < 12)
return SDValue();
KnownBits KnownY = DAG.computeKnownBits(Y);
if (KnownY.countMinLeadingZeros() < 12)
return SDValue();
KnownBits KnownMul = KnownBits::mul(KnownX, KnownY);
if (KnownMul.countMinLeadingZeros() < 12)
return SDValue();
```
https://github.com/llvm/llvm-project/pull/156714
More information about the llvm-commits
mailing list