[Mlir-commits] [mlir] e9f51a3 - [MLIR][SCF] Add regression tests for ConditionPropagation in nested ifs (#189036)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Fri Mar 27 09:17:16 PDT 2026
Author: Mehdi Amini
Date: 2026-03-27T16:17:11Z
New Revision: e9f51a39f91040fcd36b680b98d9a4da648615a1
URL: https://github.com/llvm/llvm-project/commit/e9f51a39f91040fcd36b680b98d9a4da648615a1
DIFF: https://github.com/llvm/llvm-project/commit/e9f51a39f91040fcd36b680b98d9a4da648615a1.diff
LOG: [MLIR][SCF] Add regression tests for ConditionPropagation in nested ifs (#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
Added:
Modified:
mlir/test/Dialect/SCF/canonicalize.mlir
Removed:
################################################################################
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