[llvm-bugs] [Bug 45868] New: Missed optimization: unnecessary move with division-by-multiplication
via llvm-bugs
llvm-bugs at lists.llvm.org
Sun May 10 18:54:26 PDT 2020
https://bugs.llvm.org/show_bug.cgi?id=45868
Bug ID: 45868
Summary: Missed optimization: unnecessary move with
division-by-multiplication
Product: new-bugs
Version: 10.0
Hardware: PC
OS: Linux
Status: NEW
Severity: enhancement
Priority: P
Component: new bugs
Assignee: unassignedbugs at nondot.org
Reporter: josephcsible at gmail.com
CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org
When Clang does division-by-multiplication, it seems to forget that
multiplication is commutative. It moves the numerator into %rax, but if it
moved the magic number there instead, then it wouldn't have to move the
numerator at all.
Input:
unsigned long f(unsigned long x) {
return x / 7;
}
Actual assembly:
f:
movabsq $2635249153387078803, %rcx
movq %rdi, %rax
mulq %rcx
subq %rdx, %rdi
shrq %rdi
leaq (%rdi,%rdx), %rax
shrq $2, %rax
retq
Desired assembly:
f:
movabsq $2635249153387078803, %rax
mulq %rdi
subq %rdx, %rdi
shrq %rdi
leaq (%rdi,%rdx), %rax
shrq $2, %rax
retq
--
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/20200511/3090a876/attachment.html>
More information about the llvm-bugs
mailing list