[llvm] [VPlan] Only use selectVectorizationFactor for cross-check (NFCI). (PR #103033)

via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 21 02:59:04 PDT 2024


================
@@ -7300,7 +7283,20 @@ ElementCount LoopVectorizationPlanner::computeBestVF() {
         ProfitableVFs.push_back(CurrentFactor);
     }
   }
-  return BestFactor.Width;
+
+#ifndef NDEBUG
+  // Select the optimal vectorization factor according to the legacy cost-model.
+  // This is now only used to verify the decisions by the new VPlan-based
+  // cost-model and will be retired once the VPlan-based cost-model is
+  // stabilized.
+  VectorizationFactor LegacyVF = selectVectorizationFactor();
+  assert(BestFactor.Width == LegacyVF.Width &&
+         " VPlan cost model and legacy cost model disagreed");
+  assert((BestFactor.Width.isScalar() || BestFactor.ScalarCost > 0) &&
+         "when vectorizing, the scalar cost must be non-zero.");
----------------
ayalz wrote:

As zero and/or max seem ambiguous - used as both artificial initial uncomputed values ("// A default constructed InstructionCost is a valid zero cost") and possibly considered valid computed costs, perhaps worth augmenting InstructionCost's `enum CostState` to include `UnSet` in addition to `Valid` and `InValid`?

One alternative could be to represent uncomputed costs via extreme out-of-bound values - getMinValue()-1 and/or getMaxValue()+1, somewhat analogous to -infinity and +infinity of floating-point numbers, where NaN represents InValid.

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


More information about the llvm-commits mailing list