Skip to content

Commit 7ab7bc7

Browse files
authored
[MLIR] Fix LivenessAnalysis/RemoveDeadValues handling of dead function arguments (#160755)
In #153973 I added the correctly handling of block arguments, unfortunately this was gated on operation that also have results. This wasn't intentional and this excluded operations like function from being correctly processed.
1 parent 69194be commit 7ab7bc7

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed

mlir/lib/Analysis/DataFlow/LivenessAnalysis.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,6 @@ RunLivenessAnalysis::RunLivenessAnalysis(Operation *op) {
299299
// The framework doesn't visit operations in dead blocks, so we need to
300300
// explicitly mark them as dead.
301301
op->walk([&](Operation *op) {
302-
if (op->getNumResults() == 0)
303-
return;
304302
for (auto result : llvm::enumerate(op->getResults())) {
305303
if (getLiveness(result.value()))
306304
continue;

mlir/lib/Transforms/RemoveDeadValues.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,8 @@ static void processSimpleOp(Operation *op, RunLivenessAnalysis &la,
289289
static void processFuncOp(FunctionOpInterface funcOp, Operation *module,
290290
RunLivenessAnalysis &la, DenseSet<Value> &nonLiveSet,
291291
RDVFinalCleanupList &cl) {
292-
LDBG() << "Processing function op: " << funcOp.getOperation()->getName();
292+
LDBG() << "Processing function op: "
293+
<< OpWithFlags(funcOp, OpPrintingFlags().skipRegions());
293294
if (funcOp.isPublic() || funcOp.isExternal()) {
294295
LDBG() << "Function is public or external, skipping: "
295296
<< funcOp.getOperation()->getName();

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,3 +615,37 @@ module @last_block_not_exit {
615615
// CHECK-LABEL: @call_private_but_not_use
616616
// CHECK: call @terminated_with_condbr(%false, %true) : (i1, i1)
617617
}
618+
619+
// -----
620+
621+
// Test the elimination of function arguments.
622+
623+
// CHECK-LABEL: func private @single_parameter
624+
// CHECK-SAME: () {
625+
func.func private @single_parameter(%arg0: index) {
626+
return
627+
}
628+
629+
// CHECK-LABEL: func.func private @mutl_parameter(
630+
// CHECK-SAME: %[[ARG0:.*]]: index)
631+
// CHECK: return %[[ARG0]]
632+
func.func private @mutl_parameter(%arg0: index, %arg1: index, %arg2: index) -> index {
633+
return %arg1 : index
634+
}
635+
636+
// CHECK-LABEL: func private @eliminate_parameter
637+
// CHECK-SAME: () {
638+
func.func private @eliminate_parameter(%arg0: index, %arg1: index) {
639+
call @single_parameter(%arg0) : (index) -> ()
640+
return
641+
}
642+
643+
// CHECK-LABEL: func @callee
644+
// CHECK-SAME: (%[[ARG0:.*]]: index, %[[ARG1:.*]]: index, %[[ARG2:.*]]: index)
645+
func.func @callee(%arg0: index, %arg1: index, %arg2: index) -> index {
646+
// CHECK: call @eliminate_parameter() : () -> ()
647+
call @eliminate_parameter(%arg0, %arg1) : (index, index) -> ()
648+
// CHECK: call @mutl_parameter(%[[ARG1]]) : (index) -> index
649+
%res = call @mutl_parameter(%arg0, %arg1, %arg2) : (index, index, index) -> (index)
650+
return %res : index
651+
}

0 commit comments

Comments
 (0)