[Mlir-commits] [mlir] [mlir][CSE] Delete dead code immediately in CSE pass (PR #190926)
lonely eagle
llvmlistbot at llvm.org
Wed Apr 15 08:16:08 PDT 2026
linuxlonelyeagle wrote:
> Just for reference, we also encountered the crash, and the simplified example I have is this one:
>
> ```
> // CHECK-LABEL: @cse_dead_parent_duplicate_child
> func.func @cse_dead_parent_duplicate_child(%arg0: i32) -> i32 {
> // CHECK: arith.addi
> %0 = arith.addi %arg0, %arg0 : i32
>
> // Parent 2 is trivially dead because its result is not used.
> // CHECK-NOT: scf.execute_region
> %1 = scf.execute_region -> i32 {
> %child2 = arith.addi %arg0, %arg0 : i32
> scf.yield %child2 : i32
> }
>
> return %0 : i32
> }
> ```
>
> Immediately deleting dead code would work if we had a listener that removes ops from opsToRemove if they have been deleted already. So if the plan is to re-install this PR, I can contribute that code with the listener.
Thank you so much for leaving a comment here and sharing your thoughts on how to solve this. I hadn't thought of this approach because I'm not very familiar with the listener mechanism.
This PR can fix all problem, regarding the points you mentioned test, the issues raised above, and the new test cases I've added to this PR, it in the https://github.com/llvm/llvm-project/pull/191135.
Actually, I have several concerns regarding why I haven't merged the PR above. First, although we are removing dead code, the removal might reveal further dead code—meaning we aren't cleaning it up entirely. However, we likely cannot remove all of it, as other dead values might have already been inserted into the ScopedMapTy, making it difficult to perform a complete cleanup. In fact, I am looking to break through the limitations of ScopedMapTy.. Second, since dead code can be eliminated through the canonicalization pass, we might be able to reduce the complexity of the CSE pass. I believe it's a matter of trade-offs.
You also can see https://github.com/llvm/llvm-project/pull/191394.
Regardless, I'm very happy to have your input here. In software design, perhaps there is no such thing as a perfect solution.đŸ˜‰
https://github.com/llvm/llvm-project/pull/190926
More information about the Mlir-commits
mailing list