[llvm] 7b9013f - [PowerPC] Avoid RegScavenger::forward in PPCFrameLowering

Jay Foad via llvm-commits llvm-commits at lists.llvm.org
Tue May 23 02:32:53 PDT 2023


Author: Jay Foad
Date: 2023-05-23T10:30:37+01:00
New Revision: 7b9013f784af87c603aafb20d90ae056ef94f386

URL: https://github.com/llvm/llvm-project/commit/7b9013f784af87c603aafb20d90ae056ef94f386
DIFF: https://github.com/llvm/llvm-project/commit/7b9013f784af87c603aafb20d90ae056ef94f386.diff

LOG: [PowerPC] Avoid RegScavenger::forward in PPCFrameLowering

RegScavenger::backward is preferred because it does not rely on accurate
kill flags.

Differential Revision: https://reviews.llvm.org/D150558

Added: 
    

Modified: 
    llvm/lib/Target/PowerPC/PPCFrameLowering.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/PowerPC/PPCFrameLowering.cpp b/llvm/lib/Target/PowerPC/PPCFrameLowering.cpp
index 71a3590a5094..510da1a3bc51 100644
--- a/llvm/lib/Target/PowerPC/PPCFrameLowering.cpp
+++ b/llvm/lib/Target/PowerPC/PPCFrameLowering.cpp
@@ -458,19 +458,19 @@ PPCFrameLowering::findScratchRegister(MachineBasicBlock *MBB,
       (!UseAtEnd && (&MBB->getParent()->front() == MBB)))
     return true;
 
-  RS.enterBasicBlock(*MBB);
-
-  if (UseAtEnd && !MBB->empty()) {
-    // The scratch register will be used at the end of the block, so must
-    // consider all registers used within the block
-
+  if (UseAtEnd) {
+    // The scratch register will be used before the first terminator (or at the
+    // end of the block if there are no terminators).
     MachineBasicBlock::iterator MBBI = MBB->getFirstTerminator();
-    // If no terminator, back iterator up to previous instruction.
-    if (MBBI == MBB->end())
-      MBBI = std::prev(MBBI);
-
-    if (MBBI != MBB->begin())
-      RS.forward(MBBI);
+    if (MBBI == MBB->begin()) {
+      RS.enterBasicBlock(*MBB);
+    } else {
+      RS.enterBasicBlockEnd(*MBB);
+      RS.backward(std::prev(MBBI));
+    }
+  } else {
+    // The scratch register will be used at the start of the block.
+    RS.enterBasicBlock(*MBB);
   }
 
   // If the two registers are available, we're all good.


        


More information about the llvm-commits mailing list