[Mlir-commits] [mlir] [mlir][Transforms] Fix crash in `-remove-dead-values` on private functions (PR #169269)

lonely eagle llvmlistbot at llvm.org
Sun Nov 23 22:25:08 PST 2025


linuxlonelyeagle wrote:

> > I'm thinking that in this case, shouldn't we save the print? I believe we should save the print
> 
> Why would you save the `vector.print`? In that case, we cannot remove the block argument from the function.

The function added in the test file is the print function parameter, so we should save vector.print.

> In that case, we cannot remove the block argument from the function.
Yes. I just had a thought: since the data flow analysis framework relies on dead-code analysis, a private function that is not called by any other public function will not be fully traversed(Since dead code analysis marks it as dead code, the data flow analysis framework will not reach it.). Here it will cause the function's parameter to be dead.

You can see following example is run well.
```
// $: mlir-opt test.mlir -remove-dead-values
func.func private @clean_func_op_remove_side_effecting_op(%arg0: i32) -> (i32) {
  // vector.print has a side effect but the op is dead.
  vector.print %arg0 : i32
  return %arg0 : i32
}

func.func @main(%arg: i32) {
  func.call @clean_func_op_remove_side_effecting_op(%arg) : (i32) -> (i32)
  return
}
```
more example.https://github.com/llvm/llvm-project/pull/161471 .Previously, I suggested that the fix should involve directly removing the redundant private function.But @ftynse  felt it was not appropriate.

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


More information about the Mlir-commits mailing list