[Mlir-commits] [mlir] [MLIR][SCF] Add regression tests for ConditionPropagation in nested ifs (PR #189036)
Mehdi Amini
llvmlistbot at llvm.org
Fri Mar 27 09:05:08 PDT 2026
https://github.com/joker-eph created https://github.com/llvm/llvm-project/pull/189036
Add explicit tests for condition propagation in scf.if then and else
branches, including the void-return case. These tests serve as regression
tests for the bug reported in #159165 where the SCFIfConditionPropagationPass
(since reverted) had a visited-set that was never populated, causing the pass
to not propagate conditions into nested scf.if statements.
The current ConditionPropagation canonicalization pattern in SCF.cpp
correctly handles both nested ifs and direct condition uses within branches
using the getParentType() ancestor check.
Fixes #159165
Assisted-by: Claude Code
>From 12879767584b2f113ce352b8580c400d33317912 Mon Sep 17 00:00:00 2001
From: Mehdi Amini <joker.eph at gmail.com>
Date: Fri, 27 Mar 2026 06:42:36 -0700
Subject: [PATCH] [MLIR][SCF] Add regression tests for ConditionPropagation in
nested ifs
Add explicit tests for condition propagation in scf.if then and else
branches, including the void-return case. These tests serve as regression
tests for the bug reported in #159165 where the SCFIfConditionPropagationPass
(since reverted) had a visited-set that was never populated, causing the pass
to not propagate conditions into nested scf.if statements.
The current ConditionPropagation canonicalization pattern in SCF.cpp
correctly handles both nested ifs and direct condition uses within branches
using the getParentType() ancestor check.
Fixes #159165
Assisted-by: Claude Code
---
mlir/test/Dialect/SCF/canonicalize.mlir | 38 +++++++++++++++++++++++++
1 file changed, 38 insertions(+)
diff --git a/mlir/test/Dialect/SCF/canonicalize.mlir b/mlir/test/Dialect/SCF/canonicalize.mlir
index f65046ecee6da..62dc2305b5857 100644
--- a/mlir/test/Dialect/SCF/canonicalize.mlir
+++ b/mlir/test/Dialect/SCF/canonicalize.mlir
@@ -949,6 +949,44 @@ func.func @cond_prop(%arg0 : i1) -> index {
// -----
+// Condition propagation: uses of the condition inside the then/else regions
+// are replaced with true/false respectively (regression test for
+// https://github.com/llvm/llvm-project/issues/159165).
+
+// CHECK-LABEL: @cond_prop_then
+func.func @cond_prop_then(%arg0 : i1) {
+ scf.if %arg0 {
+ "test.use"(%arg0) : (i1) -> ()
+ }
+ return
+}
+// CHECK-NEXT: %[[true:.+]] = arith.constant true
+// CHECK-NEXT: scf.if %arg0 {
+// CHECK-NEXT: "test.use"(%[[true]]) : (i1) -> ()
+// CHECK-NEXT: }
+// CHECK-NEXT: return
+// CHECK-NEXT:}
+
+// -----
+
+// CHECK-LABEL: @cond_prop_else
+func.func @cond_prop_else(%arg0 : i1) {
+ scf.if %arg0 {
+ } else {
+ "test.use"(%arg0) : (i1) -> ()
+ }
+ return
+}
+// CHECK-NEXT: %[[false:.+]] = arith.constant false
+// CHECK-NEXT: scf.if %arg0 {
+// CHECK-NEXT: } else {
+// CHECK-NEXT: "test.use"(%[[false]]) : (i1) -> ()
+// CHECK-NEXT: }
+// CHECK-NEXT: return
+// CHECK-NEXT:}
+
+// -----
+
// CHECK-LABEL: @replace_if_with_cond1
func.func @replace_if_with_cond1(%arg0 : i1) -> (i32, i1) {
%true = arith.constant true
More information about the Mlir-commits
mailing list