[llvm] [LoopVectorize] Compute BlockFrequencyInfo eagerly to fix assertion failure (PR #215237)
Karthika Devi C via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 10 03:38:57 PDT 2026
https://github.com/kartcq created https://github.com/llvm/llvm-project/pull/215237
After a6af12620778, LoopVectorizePass crashes when processing functions with multiple loops. The lazy BFI lambda requests BlockFrequencyAnalysis after earlier loops have been vectorized, at which point the cached CycleInfo holds stale pointers to blocks that no longer exist in the function.
Compute BFI eagerly at the top of run(), before runImpl() mutates the function, so that CycleInfo is read while the CFG is still consistent.
Fixes #215236
>From 1435a866d11762526ba9696e1bae87fcf14986a0 Mon Sep 17 00:00:00 2001
From: Karthika Devi C <kartc at qti.qualcomm.com>
Date: Mon, 10 Aug 2026 03:20:50 -0700
Subject: [PATCH] [LoopVectorize] Compute BlockFrequencyInfo eagerly to fix
assertion failure
After a6af12620778, LoopVectorizePass crashes when processing
functions with multiple loops. The lazy BFI lambda requests
BlockFrequencyAnalysis after earlier loops have been vectorized,
at which point the cached CycleInfo holds stale pointers to
blocks that no longer exist in the function.
Compute BFI eagerly at the top of run(), before runImpl()
mutates the function, so that CycleInfo is read while the CFG
is still consistent.
Fixes #215236
---
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index 3c65eda187a6e..bc313849b7b82 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -8478,8 +8478,14 @@ PreservedAnalyses LoopVectorizePass::run(Function &F,
auto &MAMProxy = AM.getResult<ModuleAnalysisManagerFunctionProxy>(F);
PSI = MAMProxy.getCachedResult<ProfileSummaryAnalysis>(*F.getParent());
- GetBFI = [&AM, &F]() -> BlockFrequencyInfo & {
- return AM.getResult<BlockFrequencyAnalysis>(F);
+ // Compute BFI eagerly rather than lazily. LoopVectorize may modify the
+ // function (vectorizing earlier loops) before requesting BFI for later loops.
+ // If BFI is computed lazily after such modifications, its dependency
+ // CycleAnalysis may be stale (holding pointers to deleted blocks), causing
+ // crashes.
+ BlockFrequencyInfo &BFIRef = AM.getResult<BlockFrequencyAnalysis>(F);
+ GetBFI = [&BFIRef]() -> BlockFrequencyInfo & {
+ return BFIRef;
};
LoopVectorizeResult Result = runImpl(F);
if (!Result.MadeAnyChange)
More information about the llvm-commits
mailing list