[PATCH] D156837: [AArch64][CodeGen] Avoid inverting hot branches during relaxation
Daniel Hoekwater via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 17 18:36:38 PDT 2023
dhoekwater added a comment.
A bit more info on the motivation for this patch:
Machine function splitting (MFS) places super cold basic blocks in a different ELF section (the `.test.split` section), so any hot branches targeting the cold basic blocks must be relaxed. The current method of relaxing a conditional branch is to invert the condition, which biases the branch predictor in the opposite direction. Since these branches are almost never taken, the bias has a significant impact on runtime performance.
This patch mitigates the impact of MFS on the branch predictor by avoiding inverting the conditional branch. Instead, if the spot right after the last hot block is in range, we can 1) place a "trampoline," a basic block that only consists of an unconditional to the destination, at this location and 2) retarget the conditional branch to the trampoline. This increases the cost of actually taking the branch to the cold section, but it is almost never taken; doing so significantly improves performance when the branch is not taken.
================
Comment at: llvm/lib/CodeGen/BranchRelaxation.cpp:85
+ // basic block that isn't in the cold section.
+ MachineBasicBlock *TrampolineInsertionPoint;
std::unique_ptr<RegScavenger> RS;
----------------
arsenm wrote:
> null initialize and remove the one in scanFunction?
We either need the null assignment in `scanFunction` or `runOnMachineFunction` since just null initializing it will keep the insertion point from the previous function. I'll keep the one in `scanFunction`, since it doesn't require that the previous call to `runOnMachineFunction` executed successfully.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D156837/new/
https://reviews.llvm.org/D156837
More information about the llvm-commits
mailing list