[PATCH] D145299: [X86] Generate better code for std::bit_ceil
Kazu Hirata via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Mar 4 00:25:59 PST 2023
kazu created this revision.
Herald added subscribers: pengfei, hiraditya.
Herald added a project: All.
kazu requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Without this patch, std::bit_ceil is compiled as:
8d 47 ff lea -0x1(%rdi),%eax
f3 0f bd c0 lzcnt %eax,%eax
f6 d8 neg %al
b9 01 00 00 00 mov $0x1,%ecx
c4 e2 79 f7 c1 shlx %eax,%ecx,%eax
83 ff 02 cmp $0x2,%edi
0f 42 c1 cmovb %ecx,%eax
Note cmp and cmovb at the end above. Actually, the sequence produces
correct results without the cmp and cmovb at the end even for inputs 0
and 1:
input 0 1 2
-------------------
lea -1 0 1
lzcnt 0 32 31
neg 0 -32 -31
&0x1f 0 0 1
shlx 1 1 2
This patch recognizes the specific DAG and drops the conditional move,
saving 6 bytes at least.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D145299
Files:
llvm/lib/Target/X86/X86ISelLowering.cpp
llvm/test/CodeGen/X86/bit_ceil.ll
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D145299.502358.patch
Type: text/x-patch
Size: 4506 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230304/aaea40eb/attachment.bin>
More information about the llvm-commits
mailing list