[llvm] [llvm][NVPTX] Fix quadratic runtime in ProxyRegErasure (PR #105730)
Justin Fargnoli via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 22 14:00:23 PDT 2024
================
@@ -74,44 +72,42 @@ bool NVPTXProxyRegErasure::runOnMachineFunction(MachineFunction &MF) {
case NVPTX::ProxyRegI32:
case NVPTX::ProxyRegI64:
case NVPTX::ProxyRegF32:
- case NVPTX::ProxyRegF64:
- replaceMachineInstructionUsage(MF, MI);
+ case NVPTX::ProxyRegF64: {
+ auto &InOp = *MI.uses().begin();
+ auto &OutOp = *MI.defs().begin();
+ assert(InOp.isReg() && "ProxyReg input should be a register.");
+ assert(OutOp.isReg() && "ProxyReg output should be a register.");
RemoveList.push_back(&MI);
+ RAUWBatch.try_emplace(OutOp.getReg(), InOp.getReg());
break;
}
+ }
}
}
+ // If there were no proxy instructions, exit early.
+ if (RemoveList.empty())
+ return false;
+
+ // Erase the proxy instructions first.
for (auto *MI : RemoveList) {
MI->eraseFromParent();
}
- return !RemoveList.empty();
-}
-
-void NVPTXProxyRegErasure::replaceMachineInstructionUsage(MachineFunction &MF,
- MachineInstr &MI) {
- auto &InOp = *MI.uses().begin();
- auto &OutOp = *MI.defs().begin();
-
- assert(InOp.isReg() && "ProxyReg input operand should be a register.");
- assert(OutOp.isReg() && "ProxyReg output operand should be a register.");
-
+ // Now go replace the registers.
for (auto &BB : MF) {
- for (auto &I : BB) {
- replaceRegisterUsage(I, OutOp, InOp);
+ for (auto &MI : BB) {
+ for (auto &Op : MI.uses()) {
+ if (Op.isReg()) {
----------------
justinfargnoli wrote:
Ignorable nit: prefer early return.
https://github.com/llvm/llvm-project/pull/105730
More information about the llvm-commits
mailing list