[llvm] [VPlan] Truncate/Extend ComputeReductionResult at construction (NFC). (PR #141860)

Mel Chen via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 30 03:03:48 PDT 2025


================
@@ -9266,6 +9247,31 @@ void LoopVectorizationPlanner::adjustRecipesForReductions(
           Builder.createNaryOp(VPInstruction::ComputeReductionResult,
                                {PhiR, NewExitingVPV}, Flags, ExitDL);
     }
+    // If the vector reduction can be performed in a smaller type, we truncate
+    // then extend the loop exit value to enable InstCombine to evaluate the
+    // entire expression in the smaller type.
+    if (MinVF.isVector() && PhiTy != RdxDesc.getRecurrenceType() &&
+        !RecurrenceDescriptor::isAnyOfRecurrenceKind(
+            RdxDesc.getRecurrenceKind())) {
+      assert(!PhiR->isInLoop() && "Unexpected truncated inloop reduction!");
----------------
Mel-Chen wrote:

Add 
      assert(!RecurrenceDescriptor::isMinMaxRecurrenceKind(
            RdxDesc.getRecurrenceKind()) && ...);
since min/max type-promoted recurrence is unavailable.

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


More information about the llvm-commits mailing list