[Mlir-commits] [mlir] [mlir][Transforms][NFC] `remove-dead-values`: Simplify dropped value handling (PR #173540)
Matthias Springer
llvmlistbot at llvm.org
Sun Dec 28 11:05:08 PST 2025
https://github.com/matthias-springer updated https://github.com/llvm/llvm-project/pull/173540
>From 196331353ff639f1f8d0428d45a3fdde60d7e3dd Mon Sep 17 00:00:00 2001
From: Matthias Springer <me at m-sp.org>
Date: Thu, 25 Dec 2025 10:14:32 +0000
Subject: [PATCH] [mlir][Transforms][NFC] `remove-dead-values`: Simplify
dropped value handling
---
mlir/lib/Transforms/RemoveDeadValues.cpp | 21 +++++++--------------
1 file changed, 7 insertions(+), 14 deletions(-)
diff --git a/mlir/lib/Transforms/RemoveDeadValues.cpp b/mlir/lib/Transforms/RemoveDeadValues.cpp
index 878624abee464..62ce5e0bbb77e 100644
--- a/mlir/lib/Transforms/RemoveDeadValues.cpp
+++ b/mlir/lib/Transforms/RemoveDeadValues.cpp
@@ -111,7 +111,6 @@ struct SuccessorOperandsToCleanup {
struct RDVFinalCleanupList {
SmallVector<Operation *> operations;
- SmallVector<Value> values;
SmallVector<FunctionToCleanUp> functions;
SmallVector<OperandsToCleanup> operands;
SmallVector<ResultsToCleanup> results;
@@ -325,10 +324,8 @@ static void processFuncOp(FunctionOpInterface funcOp, Operation *module,
// Do (1).
for (auto [index, arg] : llvm::enumerate(arguments))
- if (arg && nonLiveArgs[index]) {
- cl.values.push_back(arg);
+ if (arg && nonLiveArgs[index])
nonLiveSet.insert(arg);
- }
// Do (2). (Skip creating generic operand cleanup entries for call ops.
// Call arguments will be removed in the call-site specific segment-aware
@@ -850,14 +847,7 @@ static void cleanUpDeadVals(RDVFinalCleanupList &list) {
op->erase();
}
- // 4. Values
- LDBG() << "Cleaning up " << list.values.size() << " values";
- for (auto &v : list.values) {
- LDBG() << "Dropping all uses of value: " << v;
- v.dropAllUses();
- }
-
- // 5. Functions
+ // 4. Functions
LDBG() << "Cleaning up " << list.functions.size() << " functions";
// Record which function arguments were erased so we can shrink call-site
// argument segments for CallOpInterface operations (e.g. ops using
@@ -874,6 +864,9 @@ static void cleanUpDeadVals(RDVFinalCleanupList &list) {
llvm::interleaveComma(f.nonLiveRets.set_bits(), os);
os << "]";
});
+ // Drop all uses of the dead arguments.
+ for (auto deadIdx : f.nonLiveArgs.set_bits())
+ f.funcOp.getArgument(deadIdx).dropAllUses();
// Some functions may not allow erasing arguments or results. These calls
// return failure in such cases without modifying the function, so it's okay
// to proceed.
@@ -885,7 +878,7 @@ static void cleanUpDeadVals(RDVFinalCleanupList &list) {
(void)f.funcOp.eraseResults(f.nonLiveRets);
}
- // 6. Operands
+ // 5. Operands
LDBG() << "Cleaning up " << list.operands.size() << " operand lists";
for (OperandsToCleanup &o : list.operands) {
// Handle call-specific cleanup only when we have a cached callee reference.
@@ -934,7 +927,7 @@ static void cleanUpDeadVals(RDVFinalCleanupList &list) {
}
}
- // 7. Results
+ // 6. Results
LDBG() << "Cleaning up " << list.results.size() << " result lists";
for (auto &r : list.results) {
LDBG_OS([&](raw_ostream &os) {
More information about the Mlir-commits
mailing list