[llvm] [LV] Add option `--bypass-vf-comparison` to bypass VF comparison. NFC (PR #110460)

Elvis Wang via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 30 00:48:39 PDT 2024


https://github.com/ElvisWang123 created https://github.com/llvm/llvm-project/pull/110460

The assertion of checking if the VF selected by legacy model and the vplan-based cost model are the same is good for user to find if the vplan-based cost model is misaligned to the legacy cost model. 
But the assertion may block users from compiling their program normally. 

Adding this option lets users report the issue and compile their program normally.

>From f4ad136fd80f84842ff92078c33c8ad6655a9d60 Mon Sep 17 00:00:00 2001
From: Elvis Wang <elvis.wang at sifive.com>
Date: Sun, 29 Sep 2024 22:07:20 -0700
Subject: [PATCH] [LV] Add option `-bypass-vf-comparison` to bypass VF
 comparison. NFC

The assertion of checking if the VF selected by legacy model and the
vplan-based cost model is good for user to find if the vplan-based
cost model is misaligned to the legacy cost model.
But the assertion may block users from compiling their program normally.
Adding this option lets users report the issue and compile their
program normally.
---
 llvm/lib/Transforms/Vectorize/LoopVectorize.cpp | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index 792e0e17dd8719..a7ac3e970c3062 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -384,6 +384,13 @@ static cl::opt<bool> UseWiderVFIfCallVariantsPresent(
     cl::Hidden,
     cl::desc("Try wider VFs if they enable the use of vector variants"));
 
+// Bypass the assertion when the VF selected by vplan-based cost model is
+// different from the VF selected by legacy cost model.
+static cl::opt<bool>
+    BypassVFComparison("bypass-vf-comparison", cl::init(false), cl::Hidden,
+                       cl::desc("Bypass VF comparison between legacy cost "
+                                "model and the vplan-base cost model."));
+
 // Likelyhood of bypassing the vectorized loop because assumptions about SCEV
 // variables not overflowing do not hold. See `emitSCEVChecks`.
 static constexpr uint32_t SCEVCheckBypassWeights[] = {1, 127};
@@ -7383,10 +7390,13 @@ VectorizationFactor LoopVectorizationPlanner::computeBestVF() {
   // different VF to be picked by the VPlan-based cost model.
   VPCostContext CostCtx(CM.TTI, *CM.TLI, Legal->getWidestInductionType(), CM);
   precomputeCosts(BestPlan, BestFactor.Width, CostCtx);
-  assert((BestFactor.Width == LegacyVF.Width ||
+  assert(BypassVFComparison ||
+         (BestFactor.Width == LegacyVF.Width ||
           planContainsAdditionalSimplifications(getPlanFor(BestFactor.Width),
                                                 CostCtx, OrigLoop)) &&
-         " VPlan cost model and legacy cost model disagreed");
+             " VPlan cost model and legacy cost model disagreed. Please report "
+             "the issue and you can bypass "
+             "this assertion by `-bypass-vf-comparison=true`.");
   assert((BestFactor.Width.isScalar() || BestFactor.ScalarCost > 0) &&
          "when vectorizing, the scalar cost must be computed.");
 #endif



More information about the llvm-commits mailing list