[PATCH] D145211: Relax cross-section branches

Eli Friedman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 27 16:33:28 PDT 2023


efriedma added a comment.

> Yeah, the linker will clobber X16 to relax unconditional jumps. The ABI seems designed around the assumption that out-of-range unconditional jumps only exist at function call boundaries, so we have to work around that.

Alternatively, we could try to make register allocation understand that branches clobber x16, I guess?  Haven't thought through how exactly that would work.  The advantages of letting the linker split: one, we can completely avoid the extra instructions in libraries that are small, and two, linker-generated thunks would move the thunking code outside the hot section.  But I won't insist on it (we can always revise this part later).



================
Comment at: llvm/lib/Target/AArch64/AArch64InstrInfo.cpp:287
+      .addReg(Reg)
+      .addReg(AArch64::SP)
+      .addImm(-16);
----------------
dhoekwater wrote:
> efriedma wrote:
> > Do we know at this point that the function isn't using the red zone?  (We usually use the emergency spill slot for this sort of situation.)
> Because BranchRelaxation runs after Frame Finalization, we can't add an emergency spill slot at this point.
> 
> We could add a spill slot to every function just in case spilling is necessary, but I would expect it to degrade performance.
> 
> Since Red Zone on AArch64 isn't widely used, it should be alright if it isn't compatible with MFS/BBSections on AArch64. I'll add an explicit check here to assert that we're not doing anything we shouldn't.
Can we write some reasonable heuristic for whether we might need to spill?  I mean, during frame finalization, we should at least be able to tell if there's any cold code in the function.

If disabling red zone usage in the relevant functions is the simplest way forward, I guess I'm fine with that.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D145211/new/

https://reviews.llvm.org/D145211



More information about the llvm-commits mailing list