[Mlir-commits] [mlir] [mlir][remove-dead-values] Replace appropriate operation results with poison (PR #181013)

Mehdi Amini llvmlistbot at llvm.org
Sun Feb 15 08:25:51 PST 2026


================
@@ -796,3 +796,36 @@ func.func @scf_while_dead_iter_args() -> i32 {
   }
   return %result#0 : i32
 }
+
+// -----
+
+// CHECK-LABEL: func.func @replace_dead_operarion_result_with_poison
+func.func @replace_dead_operarion_result_with_poison() {
+  %0 = gpu.dynamic_shared_memory : memref<?xi8, #gpu.address_space<workgroup>>
+  %1 = vector.step : vector<1xindex>
+  %2 = scf.while (%arg0 = %1) : (vector<1xindex>) -> vector<1xindex> {
+    %cond = arith.constant true
+    scf.condition(%cond) %arg0 : vector<1xindex>
+  } do {
+    ^bb0(%arg0: vector<1xindex>):
+    scf.yield %arg0 : vector<1xindex>
+  }
+  %3 = scf.while (%arg0 = %2) : (vector<1xindex>) -> vector<1xindex> {
+    %cond = arith.constant true
+    // Check that the binary value in condition is replaced with poison, and
+    // the condition itself is well-formed IR. This prevents a crash in the
+    // canonicalization phase which happens after the dead value removal phase.
+    // CHECK-CANONICALIZE:      %[[VAL1:.*]] = ub.poison : i1
+    // CHECK-CANONICALIZE-NEXT: %[[VAL2:.*]] = ub.poison : vector<1xindex>
+    // CHECK-CANONICALIZE-NEXT: scf.condition(%[[VAL1]]) %[[VAL2]]
+    scf.condition(%cond) %arg0 : vector<1xindex>
+  } do {
+    ^bb0(%arg0: vector<1xindex>):
+    scf.yield %arg0 : vector<1xindex>
+  }
+  smt.solver(%3) : (vector<1xindex>) -> () {
+    ^bb0(%arg0: vector<1xindex>):
+    smt.yield
+  }
+  return
+}
----------------
joker-eph wrote:

This IR looks pretty complicated, I suspect half of it should be able to go away. Can you narrow it down to the minimum amount? 

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


More information about the Mlir-commits mailing list