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: unassignedclangb...@nondot.org
Reporter: zamazan...@tut.by
CC: llvm-bugs@lists.llvm.org, neeil...@live.com,
richard-l...@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.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs