[llvm] [LoopVectorize] Compute BlockFrequencyInfo eagerly to fix assertion failure (PR #215237)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 10 03:39:36 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-transforms
@llvm/pr-subscribers-vectorizers
Author: Karthika Devi C (kartcq)
<details>
<summary>Changes</summary>
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
---
Full diff: https://github.com/llvm/llvm-project/pull/215237.diff
1 Files Affected:
- (modified) llvm/lib/Transforms/Vectorize/LoopVectorize.cpp (+8-2)
``````````diff
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)
``````````
</details>
https://github.com/llvm/llvm-project/pull/215237
More information about the llvm-commits
mailing list