This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug tree-optimization/84512] New: Missed optimization: should be precalculated in compile-time
- From: "zamazan4ik at tut dot by" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 22 Feb 2018 11:38:46 +0000
- Subject: [Bug tree-optimization/84512] New: Missed optimization: should be precalculated in compile-time
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84512
Bug ID: 84512
Summary: Missed optimization: should be precalculated in
compile-time
Product: gcc
Version: tree-ssa
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: zamazan4ik at tut dot by
Target Milestone: ---
gcc(trunk) with '-O3' option for this code:
int foo()
{
int a[10];
for(int i = 0; i < 10; ++i)
{
a[i] = i*i;
}
int res = 0;
for(int i = 0; i < 10; ++i)
{
res += a[i];
}
return res;
}
produces this:
foo():
movabs rax, 4294967296
mov QWORD PTR [rsp-56], rax
movabs rax, 38654705668
mov QWORD PTR [rsp-48], rax
movabs rax, 107374182416
mov QWORD PTR [rsp-40], rax
movabs rax, 210453397540
mov QWORD PTR [rsp-32], rax
movdqa xmm0, XMMWORD PTR [rsp-40]
paddd xmm0, XMMWORD PTR [rsp-56]
movdqa xmm1, xmm0
psrldq xmm1, 8
paddd xmm0, xmm1
movdqa xmm1, xmm0
psrldq xmm1, 4
paddd xmm0, xmm1
movd eax, xmm0
add eax, 145
ret
but clang(trunk) with '-O3' produces this one:
foo(): # @foo()
mov eax, 285
ret