[llvm] [AMPGPU] Emit s_singleuse_vdst instructions when a register is used multiple times in the same instruction. (PR #89601)

Scott Egerton via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 24 11:27:19 PDT 2024


================
@@ -83,26 +84,13 @@ class AMDGPUInsertSingleUseVDST : public MachineFunctionPass {
         // instruction to be marked as a single use producer.
         bool AllProducerOperandsAreSingleUse = true;
 
-        for (const auto &Operand : MI.operands()) {
-          if (!Operand.isReg())
-            continue;
-          const auto Reg = Operand.getReg();
-
-          // Count the number of times each register is read.
-          if (Operand.readsReg())
-            for (const MCRegUnit &Unit : TRI->regunits(Reg))
-              RegisterUseCount[Unit]++;
+        // Gather a list of Registers used before updating use counts to avoid
+        // double counting registers that appear multiple times in a single
+        // MachineInstr.
+        DenseSet<MCRegUnit> RegistersUsed;
----------------
ScottEgerton wrote:

I didn't realise DenseSet wasn't ideal, I chose it as the elements need to be unique. Is there a better alternative that you would suggest?

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


More information about the llvm-commits mailing list