[llvm] [LV] Support partial reduce subs/fsubs without a mul operand (PR #199664)

Benjamin Maxwell via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 1 03:10:41 PDT 2026


================
@@ -3244,11 +3247,17 @@ void VPExpressionRecipe::printRecipe(raw_ostream &O, const Twine &Indent,
   unsigned Opcode = RecurrenceDescriptor::getOpcode(Red->getRecurrenceKind());
 
   switch (ExpressionType) {
+  case ExpressionTypes::NegatedExtendedReduction:
   case ExpressionTypes::ExtendedReduction: {
+    bool Negated = ExpressionType == ExpressionTypes::NegatedExtendedReduction;
     getOperand(1)->printAsOperand(O, SlotTracker);
     O << " + " << (Red->isPartialReduction() ? "partial." : "") << "reduce.";
     O << Instruction::getOpcodeName(Opcode) << " (";
+    if (Negated)
+      O << (Opcode == Instruction::Add ? "sub (0, " : "fneg(");
     getOperand(0)->printAsOperand(O, SlotTracker);
+    if (Negated)
+      O << ")";
----------------
MacDue wrote:

It should be exercised by `reduce_fsub_fadd_chain_without_mul` and `reduce_sub_add_chain_without_mul` in [partial-reduce-costs.ll](https://github.com/llvm/llvm-project/pull/199664/changes#diff-3581d553e2a4de6f2dae115beed9ed4a4bcace9471258b5df1ab632bd525860f).

```
Cost of 2 for VF 8: EXPRESSION vp<[[VP8:%[0-9]+]]> = ir<0> + partial.reduce.add (sub (0, ir<%load.a>) sext to i32)
Cost of 2 for VF 8: EXPRESSION vp<[[VP8:%[0-9]+]]> = ir<%accum> + partial.reduce.fadd (fneg(ir<%load.a>) reassoc contract fpext to float)
```

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


More information about the llvm-commits mailing list