Open Jokeren opened 1 year ago
@llvm/issue-subscribers-mlir
@Jokeren I tested it, and logged out wether the op order is valid in isBeforeInBlock
, and what I found is the following:
SUCCESS case (pipeline run in separate steps): // - Block: 4 // --- LiveIn: arg0@0 arg1@0 arg2@0 arg3@0 arg0@1 arg1@1 arg2@1 arg3@1 // --- LiveOut: arg0@0 arg1@0 arg2@0 arg3@0 arg0@1 arg1@1 arg2@1 // --- BeginLivenessIntervals // --- EndLivenessIntervals // --- BeginCurrentlyLive Current op: cf.br START of live range op: cf.br END of live range op: cf.br op order is INVALD in block ...
-> In Operation::isBeforeInBlock
the op order is invalid in this case, so it hits the recomputeOpOrder
code path, so the code won't hit the else
part where updateOrderIfNecessary
is called, and so it does not crash.
FAILURE case (full pipeline run): // - Block: 4 // --- LiveIn: arg0@0 arg1@0 arg2@0 arg3@0 arg0@1 arg1@1 arg2@1 arg3@1 // --- LiveOut: arg0@0 arg1@0 arg2@0 arg3@0 arg0@1 arg1@1 arg2@1 // --- BeginLivenessIntervals // --- EndLivenessIntervals // --- BeginCurrentlyLive Current op: cf.br START of live range op: cf.br END of live range op: cf.br
-> Crashes, because op order is valid, so we hit the else
part, where updateOrderIfNecessary
happens.
I will now look into why is there a difference in op order validity between the two runs.
The problem only appears if we use a single command line on the IR below. Instead, if we first do
convert-scf-to-cf
, copy the output IR to a file, and then applytest-print-liveness
on the file, we don't observe the problem. (Please bear with me on the weird variable names; it's modified from triton IR)We found one possible explanation. Maybe
isBeforeInBlock
should add an edge case forother == this
becauseupdateOrderIfNecessary
is expected to only be invoked on blocks with more than one. After skippingupdateOrderIfNecessary
whenother == this
, we did solve the problem but it doesn't explain why separatingconvert-scf-to-cf
andtest-print-liveness
could avoid the problem.https://github.com/llvm/llvm-project/blob/fd5d92e6220905f7d942a81108266d427babe143/mlir/lib/IR/Operation.cpp#L274 https://github.com/llvm/llvm-project/blob/fd5d92e6220905f7d942a81108266d427babe143/mlir/lib/IR/Operation.cpp#L304
cc @ptillet
Tested with f50cad2c55dfab4ff3da010a64119b4a93522289
Reproduced with: