[llvm] Resolve FIXME: use RegScavenger to find the best unused register (PR #78910)

via llvm-commits llvm-commits at lists.llvm.org
Sun Jan 21 12:00:46 PST 2024


https://github.com/AtariDreams created https://github.com/llvm/llvm-project/pull/78910

None

>From 3f813b7a18208057a116245f08bcbdab35a84eb1 Mon Sep 17 00:00:00 2001
From: Rose <83477269+AtariDreams at users.noreply.github.com>
Date: Sun, 21 Jan 2024 14:53:16 -0500
Subject: [PATCH] Resolve FIXME: use RegScavenger to find the best unused
 register

---
 llvm/lib/Target/AArch64/AArch64SpeculationHardening.cpp | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/llvm/lib/Target/AArch64/AArch64SpeculationHardening.cpp b/llvm/lib/Target/AArch64/AArch64SpeculationHardening.cpp
index a991d645eb6f405..86135ef39d82148 100644
--- a/llvm/lib/Target/AArch64/AArch64SpeculationHardening.cpp
+++ b/llvm/lib/Target/AArch64/AArch64SpeculationHardening.cpp
@@ -300,13 +300,8 @@ bool AArch64SpeculationHardening::instrumentControlFlow(
       RS.enterBasicBlock(MBB);
     else
       RS.backward(I);
-    // FIXME: The below just finds *a* unused register. Maybe code could be
-    // optimized more if this looks for the register that isn't used for the
-    // longest time around this place, to enable more scheduling freedom. Not
-    // sure if that would actually result in a big performance difference
-    // though. Maybe RegisterScavenger::findSurvivorBackwards has some logic
-    // already to do this - but it's unclear if that could easily be used here.
-    Register TmpReg = RS.FindUnusedReg(&AArch64::GPR64commonRegClass);
+    Register TmpReg = RS.scavengeRegisterBackwards(AArch64::GPR64commonRegClass,
+                                                   I, false, 0, false);
     LLVM_DEBUG(dbgs() << "RS finds "
                       << ((TmpReg == 0) ? "no register " : "register ");
                if (TmpReg != 0) dbgs() << printReg(TmpReg, TRI) << " ";



More information about the llvm-commits mailing list