[Mlir-commits] [mlir] [MLIR][Operation] Fix `isBeforeInBlock` crash bug mentioned in https://github.com/llvm/llvm-project/issues/60909 (PR #101172)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Fri Aug 2 00:19:29 PDT 2024


================
@@ -391,7 +391,7 @@ bool Operation::isBeforeInBlock(Operation *other) {
   // parent.
   if (!block->isOpOrderValid()) {
     block->recomputeOpOrder();
-  } else {
+  } else if (block->getOperations().size() > 1) {
----------------
wang-y-z wrote:

Thanks for pointing this out. You are right, and this `hasSingleElement` solution works as well.

I conducted an investigation on `updateOrderIfNecessary` and would like to propose another fix for `addNodeToList` that could address the root cause of the crash occurring with the `-convert-scf-to-cf -test-print-liveness` combination.

When a block contains only one operation and the user calls `op->isBeforeInBlock(op)`, if `block->isOpOrderValid()` returns true, `updateOrderIfNecessary` is called. If `op->hasValidOrder()` is false, it will crash at the assertion `assert(blockFront != blockBack && "expected more than one operation");`. 

This behavior is abnormal and needs fixing. I discovered that after the first pass of `-convert-scf-to-cf`, there is a block with only one operation where the **block order is valid** but the **operation order is invalid**, leading to a crash when `-test-print-liveness` pass runs.

Please review it again, thanks : )

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


More information about the Mlir-commits mailing list