https://bugs.llvm.org/show_bug.cgi?id=52365
Bug ID: 52365
Summary: missed optimization for the sum of two numbers
Product: clang
Version: 12.0
Hardware: PC
OS: All
Status: NEW
Severity: normal
Priority: P
Component: C++
Assignee: unassignedclangb...@nondot.org
Reporter: dushis...@gmail.com
CC: blitzrak...@gmail.com, dgre...@apple.com,
erik.pilking...@gmail.com, llvm-bugs@lists.llvm.org,
richard-l...@metafoo.co.uk
For such simple function:
int32_t f(int32_t & __restrict a, const int32_t & __restrict b) {
a += b + 17;
return a + b;
}
clang (12/13) produces (-O3) such assembly (amd64):
mov eax, dword ptr [rsi]
mov ecx, dword ptr [rdi]
lea edx, [rax + rcx]
add ecx, eax
add ecx, 17
mov dword ptr [rdi], ecx
add eax, edx
add eax, 17
ret
while gcc producues:
mov eax, DWORD PTR [rsi]
mov edx, DWORD PTR [rdi]
lea edx, [rax+17+rdx]
mov DWORD PTR [rdi], edx
add eax, edx
ret
even without benchmark (which show that gcc's variant wins)
you can see that for some reason clang forgot that in "ecx"
has "a + b + 17", so it can just add it to eax and that's all.
But for some reason it recalculate expression again via:
add eax, edx
add eax, 17
--
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