[mlir]use correct iterator when eraseOp (#83444)

#66771 introduce `llvm::post_order(&r.front())` which is equal to
`r.front().getSuccessor(...)`.
It will visit the succ block of current block. But actually here need to
visit all block of region in reverse order.
Fixes: #77420.
This commit is contained in:
Congcong Cai 2024-03-05 15:33:49 +08:00 committed by GitHub
parent 1837579bbc
commit 46f65e45e0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 25 additions and 1 deletions

View File

@ -229,7 +229,10 @@ 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())) {
// Some blocks may have invalid successor, use a set including nullptr
// to avoid null pointer.
llvm::SmallPtrSet<Block *, 4> visited{nullptr};
for (Block *b : llvm::post_order_ext(&r.front(), visited)) {
// Visit ops in reverse order.
for (Operation &op :
llvm::make_early_inc_range(ReverseIterator::makeIterable(*b)))

View File

@ -0,0 +1,21 @@
// RUN: mlir-opt --canonicalize %s | FileCheck %s
module {
// CHECK: func.func @f() {
// CHECK-NEXT: return
// CHECK-NEXT: }
func.func @f() {
return
^bb1: // no predecessors
omp.parallel {
%0 = llvm.intr.stacksave : !llvm.ptr
llvm.br ^bb1
^bb1: // pred: ^bb0
omp.terminator
}
return
}
}