[PATCH] D140975: Support critical edge splitting for jump tables
Matthias Braun via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon May 8 09:14:43 PDT 2023
MatzeB added inline comments.
================
Comment at: llvm/lib/Target/X86/X86InstrInfo.cpp:3242
+ // %1 = MOVSX64rm32 %0, 4, XX, 0, $noreg
+ // %2 = ADD64rr %1, %0
+ // JMP64r %2
----------------
craig.topper wrote:
> I'm not sure I understand this code. The MOVSXrm32 is loading from %0, sign extending it, and then adds what it loaded also to %0?
This is how clang generates the code. I mention it here as a reminder for the pattern the code below is searching for.
If you look at the assembly of an example compiled with `-fPIC` you see that the entries in the table record the basic block address relative to the beginning of the jump table. Hence we first need to load from the table and in a 2nd step add the base address of the table to get the final address.
I see something like this for small examples:
```
...
leaq .LJTI0_0(%rip), %rax
movslq (%rax,%rdi,4), %rcx
addq %rax, %rcx
jmpq *%rcx
.LBB0_2:
...
.LBB0_3:
...
...
...
.LJTI0_0:
.long .LBB0_2-.LJTI0_0
.long .LBB0_3-.LJTI0_0
...
```
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D140975/new/
https://reviews.llvm.org/D140975
More information about the llvm-commits
mailing list