[llvm] Add LoopVectorizer support for `llvm.vector.partial.reduce.fadd` (PR #163975)

Benjamin Maxwell via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 9 06:42:33 PST 2025


================
@@ -6220,7 +6220,33 @@ LoopVectorizationCostModel::getInstructionCost(Instruction *I,
     }
     [[fallthrough]];
   }
-  case Instruction::FAdd:
+  case Instruction::FAdd: {
+    // Skip this when falling through from Add/Sub.
+    if (I->getOpcode() == Instruction::FAdd) {
+      Value *Op0 = I->getOperand(0);
+      Value *Op1 = I->getOperand(1);
+      if (Op0 && Op1) {
+        Instruction *Mul = dyn_cast<Instruction>(Op0);
+        if (Mul && Mul->getOpcode() == Instruction::FMul) {
+          Value *MulOp0 = Mul->getOperand(0);
+          Value *MulOp1 = Mul->getOperand(1);
+          if (isa<Instruction>(MulOp0) && isa<Instruction>(MulOp1)) {
+            auto Cost = TTI.getPartialReductionCost(
+                I->getOpcode(), MulOp0->getType(), MulOp1->getType(),
+                VectorTy->getScalarType(), VF,
+                TTI.getPartialReductionExtendKind(
+                    dyn_cast<Instruction>(MulOp0)),
+                TTI.getPartialReductionExtendKind(
+                    dyn_cast<Instruction>(MulOp1)),
+                Mul->getOpcode(), CostKind, I->getFastMathFlags());
+            if (Cost.isValid())
+              return Cost;
+          }
+        }
+      }
+    }
+    [[fallthrough]];
+  }
----------------
MacDue wrote:

Why is this needed alongside the existing partial reduction costing? I reverted this change locally and all tests passed. 

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


More information about the llvm-commits mailing list