[llvm] [LV][VPlan] Add initial support for CSA vectorization (PR #121222)

Michael Maitland via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 13 10:13:46 PST 2025


================
@@ -8773,12 +8784,29 @@ VPRecipeBuilder::tryToCreateWidenRecipe(Instruction *Instr,
       PhiRecipe = new VPReductionPHIRecipe(Phi, RdxDesc, *StartV,
                                            CM.isInLoopReduction(Phi),
                                            CM.useOrderedReductions(RdxDesc));
-    } else {
+    } else if (Legal->isFixedOrderRecurrence(Phi)) {
       // TODO: Currently fixed-order recurrences are modeled as chains of
       // first-order recurrences. If there are no users of the intermediate
       // recurrences in the chain, the fixed order recurrence should be modeled
       // directly, enabling more efficient codegen.
       PhiRecipe = new VPFirstOrderRecurrencePHIRecipe(Phi, *StartV);
+    } else if (Legal->isConditionalScalarAssignmentPhi(Phi)) {
+      VPValue *InitScalar = Plan.getOrAddLiveIn(
+          Phi->getIncomingValueForBlock(OrigLoop->getLoopPreheader()));
+
+      // Don't build full CSA for VF=ElementCount::getFixed(1)
+      bool IsScalarVF = LoopVectorizationPlanner::getDecisionAndClampRange(
+          [&](ElementCount VF) { return VF.isScalar(); }, Range);
+
+      // When the VF=getFixed(1), InitData is just InitScalar.
+      VPValue *InitData =
+          IsScalarVF ? InitScalar
+                     : getVPValueOrAddLiveIn(PoisonValue::get(Phi->getType()));
+      PhiRecipe =
+          new VPConditionalScalarAssignmentHeaderPHIRecipe(Phi, InitData);
----------------
michaelmaitland wrote:

Updated.

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


More information about the llvm-commits mailing list