[llvm] [PassManager] Mark Loop RequireAnalysis as OptionalPassInfoMixin (PR #196345)

via llvm-commits llvm-commits at lists.llvm.org
Thu May 7 08:13:58 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-transforms

Author: Aiden Grossman (boomanaiden154)

<details>
<summary>Changes</summary>

\#<!-- -->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.

---
Full diff: https://github.com/llvm/llvm-project/pull/196345.diff


2 Files Affected:

- (modified) llvm/include/llvm/Transforms/Scalar/LoopPassManager.h (+1-1) 
- (added) llvm/test/Other/lpm-require-analysis-optnone.ll (+29) 


``````````diff
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 }

``````````

</details>


https://github.com/llvm/llvm-project/pull/196345


More information about the llvm-commits mailing list