[Mlir-commits] [mlir] [mlir][liveness] fix bugs in liveness analysis (PR #133416)
donald chen
llvmlistbot at llvm.org
Sat Mar 29 17:20:42 PDT 2025
================
@@ -106,51 +108,88 @@ void LivenessAnalysis::visitBranchOperand(OpOperand &operand) {
// the forwarded branch operands or the non-branch operands. Thus they need
// to be handled separately. This is where we handle them.
- // This marks values of type (1.b) liveness as "live". A non-forwarded
+ // This marks values of type (1.b/1.c) liveness as "live". A non-forwarded
// branch operand will be live if a block where its op could take the control
- // has an op with memory effects.
+ // has an op with memory effects or could result in different results.
// Populating such blocks in `blocks`.
+ bool mayLive = false;
SmallVector<Block *, 4> blocks;
if (isa<RegionBranchOpInterface>(op)) {
- // When the op is a `RegionBranchOpInterface`, like an `scf.for` or an
- // `scf.index_switch` op, its branch operand controls the flow into this
- // op's regions.
- for (Region ®ion : op->getRegions()) {
- for (Block &block : region)
- blocks.push_back(&block);
+ if (op->getNumResults() != 0) {
+ // This mark value of type 1.c liveness as may live, because the region
+ // branch operation has a return value, and the non-forwarded operand can
+ // determine the region to jump to, it can thereby control the result of
+ // the region branch operation.
+ // Therefore, if the result value is live, we conservatively consider the
+ // non-forwarded operand of the region branch operation with result may
+ // live and record all result.
+ for (Value result : op->getResults()) {
+ if (getLatticeElement(result)->isLive) {
----------------
cxy-1993 wrote:
This is guaranteed by the function's call site(https://github.com/llvm/llvm-project/blob/e3a3f78f35e091f005197bdd8f0464684546b5a0/mlir/lib/Analysis/DataFlow/SparseAnalysis.cpp#L565 https://github.com/llvm/llvm-project/blob/e3a3f78f35e091f005197bdd8f0464684546b5a0/mlir/lib/Analysis/DataFlow/SparseAnalysis.cpp#L599) , and this function will only receive non-forwarded operands by its definition.(https://github.com/llvm/llvm-project/blob/e3a3f78f35e091f005197bdd8f0464684546b5a0/mlir/include/mlir/Analysis/DataFlow/SparseAnalysis.h#L411)
https://github.com/llvm/llvm-project/pull/133416
More information about the Mlir-commits
mailing list