[Mlir-commits] [mlir] [mlir][dataflow] Fix LivenessAnalysis/RemoveDeadValues handling of loop induction variables (PR #161117)
lonely eagle
llvmlistbot at llvm.org
Mon Oct 20 09:52:14 PDT 2025
================
@@ -165,6 +165,28 @@ void LivenessAnalysis::visitBranchOperand(OpOperand &operand) {
blocks.push_back(&block);
}
}
+
+ // In the block of the successor block argument of RegionBranchOpInterface,
+ // there may be arguments of RegionBranchOpInterface, such as the IV of
+ // scf.forOp. Explicitly set this argument to live.
+ auto regionBranchOp = cast<RegionBranchOpInterface>(op);
+ for (size_t i = 0, e = op->getNumRegions(); i < e; ++i) {
+ SmallVector<RegionSuccessor> successors;
+ regionBranchOp.getSuccessorRegions(op->getRegion(i), successors);
+ for (RegionSuccessor successor : successors) {
+ if (successor.isParent())
+ continue;
+ auto arguments = successor.getSuccessor()->getArguments();
+ ValueRange regionInputs = successor.getSuccessorInputs();
+ for (auto argument : arguments) {
+ if (llvm::find(regionInputs, argument) == regionInputs.end()) {
+ (void)getLatticeElement(argument)->markLive();
+ LDBG() << "Marking RegionBranchOp's success argument live: "
+ << argument;
+ }
+ }
+ }
+ }
----------------
linuxlonelyeagle wrote:
I've written a test; perhaps it will do.
```
func.func @dead_value_loop_ivs_has_result(%lb: index, %ub: index, %step: index, %b: i1) -> i1 {
%loop_ret, %a = scf.for %iv = %lb to %ub step %step iter_args(%iter = %b, %iter1 = %lb) -> (i1, index) {
cf.assert %b, "loop not dead"
scf.yield %b, %lb : i1, index
}
return %loop_ret : i1
}
```
https://github.com/llvm/llvm-project/pull/161117
More information about the Mlir-commits
mailing list