Skip to content

Commit 55fb1ca

Browse files
Revert "[mlir] Make remove-dead-values pass remove blocks arguments first" (#166746)
Reverts #165725. See https://lab.llvm.org/buildbot/#/builders/169/builds/16768,
1 parent 474237b commit 55fb1ca

File tree

2 files changed

+23
-38
lines changed

2 files changed

+23
-38
lines changed

mlir/lib/Transforms/RemoveDeadValues.cpp

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -742,25 +742,7 @@ static void processBranchOp(BranchOpInterface branchOp, RunLivenessAnalysis &la,
742742
static void cleanUpDeadVals(RDVFinalCleanupList &list) {
743743
LDBG() << "Starting cleanup of dead values...";
744744

745-
// 1. Blocks
746-
LDBG() << "Cleaning up " << list.blocks.size() << " block argument lists";
747-
for (auto &b : list.blocks) {
748-
// blocks that are accessed via multiple codepaths processed once
749-
if (b.b->getNumArguments() != b.nonLiveArgs.size())
750-
continue;
751-
LDBG() << "Erasing " << b.nonLiveArgs.count()
752-
<< " non-live arguments from block: " << b.b;
753-
// it iterates backwards because erase invalidates all successor indexes
754-
for (int i = b.nonLiveArgs.size() - 1; i >= 0; --i) {
755-
if (!b.nonLiveArgs[i])
756-
continue;
757-
LDBG() << " Erasing block argument " << i << ": " << b.b->getArgument(i);
758-
b.b->getArgument(i).dropAllUses();
759-
b.b->eraseArgument(i);
760-
}
761-
}
762-
763-
// 2. Operations
745+
// 1. Operations
764746
LDBG() << "Cleaning up " << list.operations.size() << " operations";
765747
for (auto &op : list.operations) {
766748
LDBG() << "Erasing operation: "
@@ -769,14 +751,14 @@ static void cleanUpDeadVals(RDVFinalCleanupList &list) {
769751
op->erase();
770752
}
771753

772-
// 3. Values
754+
// 2. Values
773755
LDBG() << "Cleaning up " << list.values.size() << " values";
774756
for (auto &v : list.values) {
775757
LDBG() << "Dropping all uses of value: " << v;
776758
v.dropAllUses();
777759
}
778760

779-
// 4. Functions
761+
// 3. Functions
780762
LDBG() << "Cleaning up " << list.functions.size() << " functions";
781763
// Record which function arguments were erased so we can shrink call-site
782764
// argument segments for CallOpInterface operations (e.g. ops using
@@ -798,7 +780,7 @@ static void cleanUpDeadVals(RDVFinalCleanupList &list) {
798780
(void)f.funcOp.eraseResults(f.nonLiveRets);
799781
}
800782

801-
// 5. Operands
783+
// 4. Operands
802784
LDBG() << "Cleaning up " << list.operands.size() << " operand lists";
803785
for (OperationToCleanup &o : list.operands) {
804786
// Handle call-specific cleanup only when we have a cached callee reference.
@@ -840,7 +822,7 @@ static void cleanUpDeadVals(RDVFinalCleanupList &list) {
840822
}
841823
}
842824

843-
// 6. Results
825+
// 5. Results
844826
LDBG() << "Cleaning up " << list.results.size() << " result lists";
845827
for (auto &r : list.results) {
846828
LDBG() << "Erasing " << r.nonLive.count()
@@ -849,6 +831,24 @@ static void cleanUpDeadVals(RDVFinalCleanupList &list) {
849831
dropUsesAndEraseResults(r.op, r.nonLive);
850832
}
851833

834+
// 6. Blocks
835+
LDBG() << "Cleaning up " << list.blocks.size() << " block argument lists";
836+
for (auto &b : list.blocks) {
837+
// blocks that are accessed via multiple codepaths processed once
838+
if (b.b->getNumArguments() != b.nonLiveArgs.size())
839+
continue;
840+
LDBG() << "Erasing " << b.nonLiveArgs.count()
841+
<< " non-live arguments from block: " << b.b;
842+
// it iterates backwards because erase invalidates all successor indexes
843+
for (int i = b.nonLiveArgs.size() - 1; i >= 0; --i) {
844+
if (!b.nonLiveArgs[i])
845+
continue;
846+
LDBG() << " Erasing block argument " << i << ": " << b.b->getArgument(i);
847+
b.b->getArgument(i).dropAllUses();
848+
b.b->eraseArgument(i);
849+
}
850+
}
851+
852852
// 7. Successor Operands
853853
LDBG() << "Cleaning up " << list.successorOperands.size()
854854
<< " successor operand lists";

mlir/test/Transforms/remove-dead-values.mlir

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -674,18 +674,3 @@ func.func @dead_value_loop_ivs_no_result(%lb: index, %ub: index, %step: index, %
674674
}
675675
return
676676
}
677-
678-
// -----
679-
680-
// CHECK-LABEL: func @op_block_have_dead_arg
681-
func.func @op_block_have_dead_arg(%arg0: index, %arg1: index, %arg2: index, %arg3: i1) {
682-
scf.for %iv = %arg0 to %arg1 step %arg2 {
683-
scf.execute_region {
684-
cf.cond_br %arg3, ^bb1(%arg0 : index), ^bb1(%arg1 : index)
685-
^bb1(%0: index):
686-
scf.yield
687-
}
688-
}
689-
// CHECK-NEXT: return
690-
return
691-
}

0 commit comments

Comments
 (0)