[all-commits] [llvm/llvm-project] e3c72e: LowerTypeTests: Shrink check size by 1 instruction...
Peter Collingbourne via All-commits
all-commits at lists.llvm.org
Fri Jun 6 12:43:45 PDT 2025
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: e3c72e10751bf1c1864b93c4156cf90863aa02a1
https://github.com/llvm/llvm-project/commit/e3c72e10751bf1c1864b93c4156cf90863aa02a1
Author: Peter Collingbourne <peter at pcc.me.uk>
Date: 2025-06-06 (Fri, 06 Jun 2025)
Changed paths:
M llvm/lib/Transforms/IPO/LowerTypeTests.cpp
M llvm/test/Transforms/LowerTypeTests/aarch64-jumptable.ll
M llvm/test/Transforms/LowerTypeTests/asm.ll
M llvm/test/Transforms/LowerTypeTests/export-allones.ll
M llvm/test/Transforms/LowerTypeTests/export-bytearray.ll
M llvm/test/Transforms/LowerTypeTests/export-icall.ll
M llvm/test/Transforms/LowerTypeTests/export-inline.ll
M llvm/test/Transforms/LowerTypeTests/function.ll
M llvm/test/Transforms/LowerTypeTests/import.ll
M llvm/test/Transforms/LowerTypeTests/simple.ll
M llvm/test/Transforms/LowerTypeTests/simplify.ll
M llvm/test/Transforms/MergeFunc/cfi-thunk-merging.ll
M llvm/test/Transforms/SimplifyTypeTests/basic.ll
M llvm/unittests/Transforms/IPO/LowerTypeTests.cpp
Log Message:
-----------
LowerTypeTests: Shrink check size by 1 instruction on x86.
We currently generate code like this on x86 for a jump table with 5 elements,
assuming the call target is in rbx:
lea global_addr(%rip), %rax # initialize temporary rax with base address
mov %rbx, %rcx # initialize another temporary rcx for index (rbx will be used for the call, so it is still live)
sub %rax, %rcx # compute `address - base`
ror $0x3, %rcx # compute `(address - base) ror 3` i.e. index
cmp $0x4, %rcx # check index <= 4
ja .Ltrap
[...]
.Ltrap:
ud1
A more efficient instruction sequence, that only needs one temporary
register and one fewer instruction, is possible by subtracting the
address we are testing from the fixed address instead of vice versa:
lea (global_addr + 4*8)(%rip), %rax # initialize temporary rax with address of last element
sub %rbx, %rax # compute `last element - address`
ror $0x3, %rax # compute `(last element - address) ror 3` i.e. 4 - index
cmp $0x4, %rax # check 4 - index <= 4 (same as above)
ja .Ltrap
[...]
.Ltrap:
ud1
Change LowerTypeTests to generate that sequence. As a consequence, the
order of bits in the bitsets is reversed. Because it doesn't matter how we
do the subtraction on other architectures (to the best of my knowledge),
do so unconditionally.
Reviewers: fmayer, vitalybuka
Reviewed By: fmayer
Pull Request: https://github.com/llvm/llvm-project/pull/142887
To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications
More information about the All-commits
mailing list