[llvm] [PassManager] Mark Loop RequireAnalysis as OptionalPassInfoMixin (PR #196345)
Aiden Grossman via llvm-commits
llvm-commits at lists.llvm.org
Thu May 7 08:12:43 PDT 2026
https://github.com/boomanaiden154 created https://github.com/llvm/llvm-project/pull/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.
>From ad8b198dc24e0b94e44e4751930aabf9136c668d Mon Sep 17 00:00:00 2001
From: Aiden Grossman <aidengrossman at google.com>
Date: Thu, 7 May 2026 15:09:52 +0000
Subject: [PATCH] [PassManager] Mark Loop RequireAnalysis as
OptionalPassInfoMixin
\#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.
---
.../llvm/Transforms/Scalar/LoopPassManager.h | 2 +-
.../Other/lpm-require-analysis-optnone.ll | 29 +++++++++++++++++++
2 files changed, 30 insertions(+), 1 deletion(-)
create mode 100644 llvm/test/Other/lpm-require-analysis-optnone.ll
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