[llvm-bugs] [Bug 43431] New: Value range knowledge of higher bits not used in optimizations
via llvm-bugs
llvm-bugs at lists.llvm.org
Tue Sep 24 08:00:16 PDT 2019
https://bugs.llvm.org/show_bug.cgi?id=43431
Bug ID: 43431
Summary: Value range knowledge of higher bits not used in
optimizations
Product: clang
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: enhancement
Priority: P
Component: LLVM Codegen
Assignee: unassignedclangbugs at nondot.org
Reporter: zamazan4ik at tut.by
CC: llvm-bugs at lists.llvm.org, neeilans at live.com,
richard-llvm at metafoo.co.uk
Consider the example:
unsigned long long sample2(unsigned long long m) {
if (m >= 100) __builtin_unreachable();
m *= 16;
return m >> 3;
}
After the `if` statement we do know that the higher bits are set to 0. So
instead of generating the following assembly:
sample2(unsigned long long):
mov rax, rdi
sal rax, 4
shr rax, 3
ret
A more optimal assembly could be generated:
sample2(unsigned long long):
lea rax, [rdi + rdi]
ret
Godbolt playground: https://godbolt.org/z/1iSpTh
Same issues for GCC: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91881
P.S.: that optimization is important for std::to_chars(..., double) like
functions, where a significant of a double is extracted into an unsigned long
long variable, so its upper bits are always zero.
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20190924/ccd64a88/attachment.html>
More information about the llvm-bugs
mailing list