llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[mlir][func] Duplicate function elimination pass can create invalid IR

Open christopherbate opened this issue 1 year ago • 0 comments

In the duplicate function elimination logic here, there are a couple bugs:

  1. It is not checked whether a function has a body or not, so in the below some_external_func2 will be replaced with some_external_func:
func.func private @some_external_func(i32, i32) -> i32
func.func private @some_external_func2(i32, i32) -> i32

func.func @some_caller(%arg0: i32, %arg1: i32) -> (i32, i32) {
  %0 = func.call @some_external_func(%arg0, %arg1) : (i32, i32) -> i32
  %1 = func.call @some_external_func2(%arg0, %arg1) : (i32, i32) -> i32
  return %0, %1 : i32, i32
}
  1. The logic assumes that the only users of the func.func symbol are func::CallOp ops, but it doesn't check this. There could be other users (e.g. func.constant, ops not in upstream, or even just a discardable SymbolRefAttr in any op). These symbols will still refer to the removed function symbol at the end of the pass.

christopherbate avatar May 27 '24 16:05 christopherbate