[llvm] [CodeGen] Correctly handle non-standard cases in RemoveLoadsIntoFakeUses (PR #111551)

Stephen Tozer via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 13 02:33:23 PST 2024


================
@@ -86,20 +93,22 @@ bool RemoveLoadsIntoFakeUses::runOnMachineFunction(MachineFunction &MF) {
   const TargetInstrInfo *TII = ST.getInstrInfo();
   const TargetRegisterInfo *TRI = ST.getRegisterInfo();
 
-  SmallDenseMap<Register, SmallVector<MachineInstr *>> RegFakeUses;
+  SmallVector<MachineInstr *> RegFakeUses;
   LivePhysRegs.init(*TRI);
   SmallVector<MachineInstr *, 16> Statepoints;
   for (MachineBasicBlock *MBB : post_order(&MF)) {
+    RegFakeUses.clear();
     LivePhysRegs.addLiveOuts(*MBB);
 
     for (MachineInstr &MI : make_early_inc_range(reverse(*MBB))) {
       if (MI.isFakeUse()) {
-        for (const MachineOperand &MO : MI.operands()) {
-          // Track the Fake Uses that use this register so that we can delete
-          // them if we delete the corresponding load.
-          if (MO.isReg())
-            RegFakeUses[MO.getReg()].push_back(&MI);
-        }
+        if (MI.getNumOperands() == 0 || !MI.getOperand(0).isReg())
+          continue;
+        const MachineOperand &FakeUseOp = MI.getOperand(0);
+        // Track the Fake Uses that use these register units so that we can
+        // delete them if we delete the corresponding load.
+        if (FakeUseOp.isReg())
----------------
SLTozer wrote:

There won't be any fake uses with multiple operands - we could change that in future, but we'd need changes beyond the scope of this particular patch to enable them. We could preempt their existence, but doing so would complicate the logic further down, because currently we only need to track a list of all "live" fake uses; if we assumed that fake uses could refer to multiple registers then I think we'd need an extra data structure to keep track of which specific registers are being used by each fake use (e.g. a map, or a vector of tuples) so that we'd know which fake uses to delete. It's not a huge complication, but not worth paying for if we aren't going to use it imo - WDYT?

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


More information about the llvm-commits mailing list