[llvm] [RISCV] Properly lower multiply-accumulate chains containing a constant (PR #168660)

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 18 20:53:54 PST 2025


================
@@ -25655,3 +25655,17 @@ bool RISCVTargetLowering::shouldFoldMaskToVariableShiftPair(SDValue Y) const {
 
   return VT.getSizeInBits() <= Subtarget.getXLen();
 }
+
+bool RISCVTargetLowering::isReassocProfitable(SelectionDAG &DAG, SDValue N0,
+                                              SDValue N1) const {
+  if (!N0.hasOneUse())
+    return false;
+
+  // Avoid reassociating expressions that can be lowered to vector
+  // multiply accumulate (i.e. add (mul x, y), z)
+  if (N0.getOpcode() == ISD::ADD && N1.getOpcode() == ISD::MUL &&
+      (N0.getValueType().isVector() && Subtarget.hasStdExtV()))
----------------
topperc wrote:

StdExtV seems too restrictive. Any of the Zve extension would also be fine. Probably use `Subtarget.hasVInstructions()`

https://github.com/llvm/llvm-project/pull/168660


More information about the llvm-commits mailing list