llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.02k stars 11.96k forks source link

[mlir] remove-dead-values pass throws error when module has a name #107870

Closed mrakitaTT closed 1 month ago

mrakitaTT commented 2 months ago

When the input mlir module has a name, like this for example:

module @test_opt attributes {} {
  func.func public @test_opt(%arg0: tensor<128x10xf32>) -> tensor<128x10xf32> {
    %0 = tensor.empty() : tensor<64x96xbf16>
    // CHECK-NOT: %[[C:.*]] = tensor.empty[[C:.*]]
    return %arg0 : tensor<128x10xf32>
  }
}

then remove-dead-values pass throws this error:

error: cannot optimize an IR with non-function symbol ops, non-call symbol user ops or branch ops

After removing module name (@test_opt) everything works. Seems to be a bug.

CoTinker commented 1 month ago

https://github.com/llvm/llvm-project/blob/ffcff2f465ee8a7f0e0c7676c3e5c1ab889e0ce4/mlir/lib/Transforms/RemoveDeadValues.cpp#L575-L587 It's just unsupported.

joker-eph commented 1 month ago

It's not clear to me that the "unsupported" aspect is intentional or just an accident of the implementation that didn't consider that the walk would apply to the module itself and that it could also have a name?

That is can we just add:

 WalkResult acceptableIR = module->walk([&](Operation *op) { 
    if (op == module) return  WalkResult::advance();