[PATCH] D10826: Fix AArch64 prologue for empty frame with dynamic allocas

Evgeniy Stepanov eugenis at google.com
Thu Jul 9 15:11:18 PDT 2015


eugenis added inline comments.

================
Comment at: lib/Target/AArch64/AArch64FrameLowering.cpp:356-362
@@ -355,5 +355,9 @@
     // Use the first callee-saved register as a scratch register
-    assert(MF.getRegInfo().isPhysRegUsed(AArch64::X9) &&
-           "No scratch register to align SP!");
-    scratchSPReg = AArch64::X9;
+    if (MF.getRegInfo().isPhysRegUsed(AArch64::X9)) {
+      scratchSPReg = AArch64::X9;
+    } else if (RegInfo->hasBasePointer(MF)) {
+      scratchSPReg = RegInfo->getBaseRegister();
+    } else {
+      report_fatal_error("No scratch register to align SP!");
+    }
   }
----------------
t.p.northover wrote:
> kristof.beyls wrote:
> > I think slightly nicer/better logic is
> >     if (RegInfo->hasBasePointer(MF))
> >       scratchSPReg = RegInfo->getBaseRegister();
> >     else
> >       scratchSPReg = AArch64::X9;
> >     assert(MF.getRegInfo().isPhysRegUsed(scratchSPReg) &&
> >            "No scratch register to align SP!");
> > 
> > With the above code, a few small tweaks to the tests in test/CodeGen/AArch64/aarch64-dynamic-stack-layout.ll are needed (to use the base pointer X19 instead of X9 for a few tests). When both X9 and X19 are available as scratch registers it's an arbitrary decision which one to use.
> Can't we just nick any temporary register we please (I think the original comment miscategorises X9) and make sure it's used?
> 
>     scratchSPReg = AArch64::X9;
>     MF.getRegInfo().setPhysRegUsed(scratchSPReg); // Take that!
The caller in PrologEpilogInserter.cpp does

  TFI->processFunctionBeforeCalleeSavedScan(Fn, RS);

  // Scan the function for modified callee saved registers and insert spill code
  // for any callee saved registers that are modified.
  calculateCalleeSavedRegisters(Fn);

...

  if (!F->hasFnAttribute(Attribute::Naked))
    insertPrologEpilogCode(Fn);

So it looks like it is too late to add used regisgters at this point (in emitPrologue).


http://reviews.llvm.org/D10826







More information about the llvm-commits mailing list