[Mlir-commits] [mlir] [MLIR] Prevent invalid IR from being passed outside of RemoveDeadValues (PR #121079)

Andrzej WarzyƄski llvmlistbot at llvm.org
Thu Jan 2 11:26:42 PST 2025


================
@@ -588,22 +661,68 @@ static void cleanBranchOp(BranchOpInterface branchOp, RunLivenessAnalysis &la) {
       operandValues.push_back(successorOperands[operandIdx]);
     }
 
-    BitVector successorLiveOperands = markLives(operandValues, la);
-
     // Do (3)
-    for (int argIdx = successorLiveOperands.size() - 1; argIdx >= 0; --argIdx) {
-      if (!successorLiveOperands[argIdx]) {
-        if (successorBlock->getNumArguments() < successorOperands.size()) {
-          // if block was cleaned through a different code path
-          // we only need to remove operands from the invokation
-          successorOperands.erase(argIdx);
-          continue;
-        }
+    BitVector successorNonLive =
+        markLives(operandValues, nonLiveSet, la).flip();
+    collectNonLiveValues(nonLiveSet, successorBlock->getArguments(),
+                         successorNonLive);
+    cl.blocks.push_back({successorBlock, successorNonLive});
+    cl.successorOperands.push_back({branchOp, succIdx, successorNonLive});
+  }
+}
+
+static void cleanUpDeadVals(RDVFinalCleanupList &RDVFinalCleanupList) {
----------------
banach-space wrote:

Please add a comment. To me, something along these lines would be most helpful:
> Removes dead values collected in `RDVFinalCleanupList`. To be run once when _all_ dead values have been collected.

Feel free to re-use. 

I'd also be tempted to rename `&RDVFinalCleanupList` as `cleanupList` or even `list` (importantly, note camelCase rather than CamelCase). This hook is clear enough that using simpler names should be fine.

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


More information about the Mlir-commits mailing list