[Mlir-commits] [mlir] [mlir]use correct iterator when eraseOp (PR #83444)

Matthias Springer llvmlistbot at llvm.org
Thu Feb 29 08:28:24 PST 2024


================
@@ -229,14 +229,14 @@ void RewriterBase::eraseOp(Operation *op) {
       // until the region is empty. (The block graph could be disconnected.)
       while (!r.empty()) {
         SmallVector<Block *> erasedBlocks;
-        for (Block *b : llvm::post_order(&r.front())) {
+        for (Block &b : llvm::reverse(r.getBlocks())) {
----------------
matthias-springer wrote:

Just a first thought: I think this does not guarantee that blocks are erased in reverse "reachability" order. I tried to write this function such that uses are erased before defs and I think `llvm::reverse` does not guarantee that. E.g., you could have blocks `A, B, C` in a region, in that order. But then you the branching behavior could be such that `A ->C -> B`. It's been a while, but I think `llvm::post_order` takes that into account.

I'm out of office at the moment, but I'm going to take a closer look when I'm back.


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


More information about the Mlir-commits mailing list