[llvm] [llvm][NVPTX] Fix RAUW bug in NVPTXProxyRegErasure (PR #105871)

Jeff Niu via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 23 13:31:25 PDT 2024


================
@@ -78,7 +78,11 @@ bool NVPTXProxyRegErasure::runOnMachineFunction(MachineFunction &MF) {
         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());
+        Register replacement = InOp.getReg();
+        // Check if the replacement itself has been replaced.
+        if (auto it = RAUWBatch.find(replacement); it != RAUWBatch.end())
+          replacement = it->second;
----------------
Mogball wrote:

This will deal with longer chains, because it feeds forward the leaf Register. I'll add a test.

```
%0 = proxy %src // %0 mapped to %src
%1 = proxy %0 // since %0 is mapped to %src, %1 is mapped to %src
%2 = proxy %1 // since %1 is mapped to %src, %2 is mapped to %src
```

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


More information about the llvm-commits mailing list