[Mlir-commits] [mlir] [mlir][opt][RemoveDeadValues] Fix crash when processing ops with regions that don't implement RegionBranchOpInterface (PR #182711)

Matthias Springer llvmlistbot at llvm.org
Mon Feb 23 04:32:30 PST 2026


================
@@ -237,6 +238,12 @@ RunLivenessAnalysis::RunLivenessAnalysis(Operation *op) {
         for (auto blockArg : llvm::enumerate(block.getArguments())) {
           if (getLiveness(blockArg.value()))
             continue;
+          // Skip block args of ops with regions that are not
+          // RegionBranchOpInterface or FunctionOpInterface
+          // (e.g. gpu.launch) - solver doesn't analyze their regions
+          if (!isa<RegionBranchOpInterface>(op) &&
----------------
matthias-springer wrote:

Any change to `LivenessAnalysis.cpp` should have a test in `test-liveness-analysis.mlir`. I would even split it off into a separate PR.

That being said, I still don't see what's broken here.
```mlir
// RUN: mlir-opt %s -test-liveness-analysis
func.func @gpu_launch_dead_values_no_crash() {
  %c1 = arith.constant 1 : index
  gpu.launch
    blocks(%bx, %by, %bz) in (%gx = %c1, %gy = %c1, %gz = %c1)
    threads(%tx, %ty, %tz) in (%bsx = %c1, %bsy = %c1, %bsz = %c1) {
    %blk_x = gpu.block_id x
    %thr_x = gpu.thread_id x
    vector.print %bx : index
    gpu.terminator
  } {tag = "gpu.launch"}
  return
}
```

Output:
```
test_tag: gpu.launch:
 operand #0: live
 operand #1: live
 operand #2: live
 operand #3: live
 operand #4: live
 operand #5: live
 region: #0:
   argument: #0: live
   argument: #1: not live
   argument: #2: not live
   argument: #3: not live
   argument: #4: not live
   argument: #5: not live
   argument: #6: not live
   argument: #7: not live
   argument: #8: not live
   argument: #9: not live
   argument: #10: not live
   argument: #11: not live
```

This is exactly what I expected.

Same for one of the other test cases that you added (I didn't try the remaining ones):
```
func.func @gpu_launch_mixed_dead_and_live(%buf: memref<8xf32>, %val: f32) {
  %c1 = arith.constant 1 : index
  gpu.launch
    blocks(%bx, %by, %bz) in (%gx = %c1, %gy = %c1, %gz = %c1)
    threads(%tx, %ty, %tz) in (%bsx = %c1, %bsy = %c1, %bsz = %c1) {
    %blk_x = gpu.block_id x  {tag="blk"} // live
    %thr_x = gpu.thread_id x {tag="thr"} // dead
    memref.store %val, %buf[%blk_x] : memref<8xf32>
    gpu.terminator
  } {tag="gpu.launch"}
  return
}
```

Output:
```
test_tag: blk:
 result #0: live
test_tag: thr:
 result #0: not live
test_tag: gpu.launch:
 operand #0: live
 operand #1: live
 operand #2: live
 operand #3: live
 operand #4: live
 operand #5: live
 region: #0:
   argument: #0: not live
   argument: #1: not live
   argument: #2: not live
   argument: #3: not live
   argument: #4: not live
   argument: #5: not live
   argument: #6: not live
   argument: #7: not live
   argument: #8: not live
   argument: #9: not live
   argument: #10: not live
   argument: #11: not live
```


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


More information about the Mlir-commits mailing list