[PATCH] D150558: [PowerPC] Avoid RegScavenger::forward in PPCFrameLowering

Jay Foad via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon May 15 05:24:22 PDT 2023


foad created this revision.
foad added reviewers: arsenm, bogner, RKSimon, nemanjai.
Herald added subscribers: StephenFan, shchenz, kbarton, hiraditya.
Herald added a project: All.
foad requested review of this revision.
Herald added subscribers: llvm-commits, wdng.
Herald added a project: LLVM.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D150558

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


Index: llvm/lib/Target/PowerPC/PPCFrameLowering.cpp
===================================================================
--- llvm/lib/Target/PowerPC/PPCFrameLowering.cpp
+++ llvm/lib/Target/PowerPC/PPCFrameLowering.cpp
@@ -458,19 +458,19 @@
       (!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.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D150558.522129.patch
Type: text/x-patch
Size: 1261 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230515/82dbad2e/attachment.bin>


More information about the llvm-commits mailing list