[llvm] 221a24e - [PassManager] Mark Loop RequireAnalysis as OptionalPassInfoMixin (#196345)
via llvm-commits
llvm-commits at lists.llvm.org
Thu May 7 08:47:04 PDT 2026
Author: Aiden Grossman
Date: 2026-05-07T15:46:59Z
New Revision: 221a24e94f7b03ea881df34cc8867c58ac8fdb52
URL: https://github.com/llvm/llvm-project/commit/221a24e94f7b03ea881df34cc8867c58ac8fdb52
DIFF: https://github.com/llvm/llvm-project/commit/221a24e94f7b03ea881df34cc8867c58ac8fdb52.diff
LOG: [PassManager] Mark Loop RequireAnalysis as OptionalPassInfoMixin (#196345)
\#192120 marked this as RequiredPassInfoMixin, deviating from previous
behavior. This is probably fine for Function/Module analyses, but
doesn't work well for loop analyses in the case that we have a loop in
an optnone function that is not in LCSSA. The LCSSA pass will not run
because it is optional, the analysis will get computed, and then we
assert because the loop is out of LCSSA at the end of the LPM.
Restore the old behavior of just not marking the pass as required as it
seems reasonable enough.
Added:
llvm/test/Other/lpm-require-analysis-optnone.ll
Modified:
llvm/include/llvm/Transforms/Scalar/LoopPassManager.h
Removed:
################################################################################
diff --git a/llvm/include/llvm/Transforms/Scalar/LoopPassManager.h b/llvm/include/llvm/Transforms/Scalar/LoopPassManager.h
index de9e63c125f5e..973d8a3cb1008 100644
--- a/llvm/include/llvm/Transforms/Scalar/LoopPassManager.h
+++ b/llvm/include/llvm/Transforms/Scalar/LoopPassManager.h
@@ -184,7 +184,7 @@ typedef PassManager<Loop, LoopAnalysisManager, LoopStandardAnalysisResults &,
template <typename AnalysisT>
struct RequireAnalysisPass<AnalysisT, Loop, LoopAnalysisManager,
LoopStandardAnalysisResults &, LPMUpdater &>
- : RequiredPassInfoMixin<
+ : OptionalPassInfoMixin<
RequireAnalysisPass<AnalysisT, Loop, LoopAnalysisManager,
LoopStandardAnalysisResults &, LPMUpdater &>> {
PreservedAnalyses run(Loop &L, LoopAnalysisManager &AM,
diff --git a/llvm/test/Other/lpm-require-analysis-optnone.ll b/llvm/test/Other/lpm-require-analysis-optnone.ll
new file mode 100644
index 0000000000000..4e3c406852565
--- /dev/null
+++ b/llvm/test/Other/lpm-require-analysis-optnone.ll
@@ -0,0 +1,29 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
+; RUN: opt < %s -passes="require<no-op-loop>" -S | FileCheck %s
+
+;; Test that if we have a loop out of LCSSA in an optnone function, we do not
+;; assert when we require a loop analysis.
+
+define i32 @foo() #0 {
+; CHECK-LABEL: define i32 @foo(
+; CHECK-SAME: ) #[[ATTR0:[0-9]+]] {
+; CHECK-NEXT: [[ENTRY:.*:]]
+; CHECK-NEXT: br label %[[FOR_COND:.*]]
+; CHECK: [[FOR_COND]]:
+; CHECK-NEXT: [[TMP0:%.*]] = add i16 0, 0
+; CHECK-NEXT: br i1 false, label %[[FOR_COND]], label %[[HANDLER_POINTER_OVERFLOW:.*]]
+; CHECK: [[HANDLER_POINTER_OVERFLOW]]:
+; CHECK-NEXT: [[TMP1:%.*]] = zext i16 [[TMP0]] to i32
+; CHECK-NEXT: ret i32 [[TMP1]]
+;
+entry:
+ br label %for.cond
+for.cond:
+ %0 = add i16 0, 0
+ br i1 false, label %for.cond, label %handler.pointer_overflow
+handler.pointer_overflow:
+ %1 = zext i16 %0 to i32
+ ret i32 %1
+}
+
+attributes #0 = { noinline optnone }
More information about the llvm-commits
mailing list