[all-commits] [llvm/llvm-project] 7fa337: [BOLT][RISCV] Handle long tail calls (#67098)
Job Noorman via All-commits
all-commits at lists.llvm.org
Thu Oct 5 01:55:44 PDT 2023
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 7fa33773e355aaef03197e19698303748238d91a
https://github.com/llvm/llvm-project/commit/7fa33773e355aaef03197e19698303748238d91a
Author: Job Noorman <jnoorman at igalia.com>
Date: 2023-10-05 (Thu, 05 Oct 2023)
Changed paths:
M bolt/lib/Core/BinaryFunction.cpp
M bolt/lib/Passes/FixRISCVCallsPass.cpp
M bolt/lib/Target/RISCV/RISCVMCPlusBuilder.cpp
M bolt/test/RISCV/call-annotations.s
Log Message:
-----------
[BOLT][RISCV] Handle long tail calls (#67098)
Long tail calls use the following instruction sequence on RISC-V:
```
1: auipc xi, %pcrel_hi(sym)
jalr zero, %pcrel_lo(1b)(xi)
```
Since the second instruction in isolation looks like an indirect branch,
this confused BOLT and most functions containing a long tail call got
marked with "unknown control flow" and didn't get optimized as a
consequence.
This patch fixes this by detecting long tail call sequence in
`analyzeIndirectBranch`. `FixRISCVCallsPass` also had to be updated to
expand long tail calls to `PseudoTAIL` instead of `PseudoCALL`.
Besides this, this patch also fixes a minor issue with compressed tail
calls (`c.jr`) not being detected.
Note that I had to change `BinaryFunction::postProcessIndirectBranches`
slightly: the documentation of `MCPlusBuilder::analyzeIndirectBranch`
mentions that the [`Begin`, `End`) range contains the instructions
immediately preceding `Instruction`. However, in
`postProcessIndirectBranches`, *all* the instructions in the BB where
passed in the range. This made it difficult to find the preceding
instruction so I made sure *only* the preceding instructions are passed.
More information about the All-commits
mailing list