[PATCH] D25615: [Thumb-1] Synthesize TBB/TBH instructions to make use of compressed jump tables
James Molloy via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 14 06:43:01 PDT 2016
jmolloy created this revision.
jmolloy added reviewers: olista01, t.p.northover, rengolin.
jmolloy added a subscriber: llvm-commits.
jmolloy set the repository for this revision to rL LLVM.
The TBB and TBH instructions in Thumb-2 allow jump tables to be compressed into sequences of bytes or shorts respectively. These instructions do not exist in Thumb-1, however it is possible to synthesize them out of a sequence of other instructions.
It turns out this sequence is so short that it's almost never a lose for performance and is ALWAYS a significant win for code size.
TBB example:
Before: lsls r0, r0, #2 After: add r0, pc
adr r1, .LJTI0_0 ldrb r0, [r0, #6]
ldr r0, [r0, r1] lsls r0, r0, #1
mov pc, r0 add pc, r0
=> No change in prologue code size or dynamic instruction count. Jump table shrunk by a factor of 4.
The only case that can increase dynamic instruction count is the TBH case:
Before: lsls r0, r4, #2 After: lsls r4, r4, #1
adr r1, .LJTI0_0 add r4, pc
ldr r0, [r0, r1] ldrh r4, [r4, #6]
mov pc, r0 lsls r4, r4, #1
add pc, r4
=> 1 more instruction in prologue. Jump table shrunk by a factor of 2.
So there is an argument that this should be disabled when optimizing for performance (and a TBH needs to be generated). I'm not so sure about that in practice, because on small cores with Thumb-1 performance is often tied to code size. But I'm willing to turn it off when optimizing for performance if people want (also note that TBHs are fairly rare in practice!)
Repository:
rL LLVM
https://reviews.llvm.org/D25615
Files:
lib/Target/ARM/ARMAsmPrinter.cpp
lib/Target/ARM/ARMConstantIslandPass.cpp
lib/Target/ARM/ARMInstrThumb.td
test/CodeGen/ARM/arm-position-independence-jump-table.ll
test/CodeGen/ARM/jump-table-tbh.ll
test/CodeGen/Thumb2/thumb2-jtb.ll
test/CodeGen/Thumb2/thumb2-tbb.ll
test/CodeGen/Thumb2/thumb2-tbh.ll
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D25615.74676.patch
Type: text/x-patch
Size: 20214 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161014/f2958c35/attachment.bin>
More information about the llvm-commits
mailing list