https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84101
Bug ID: 84101
Summary: -O3 and -ftree-vectorize trying too hard for function
returning trivial pair-of-uint64_t-structure
Product: gcc
Version: 7.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: gcc at gmch dot uk
Target Milestone: ---
The following:
typedef struct uint64_pair uint64_pair_t ;
struct uint64_pair
{
uint64_t w0 ;
uint64_t w1 ;
} ;
uint64_pair_t pair(int num)
{
uint64_pair_t p ;
p.w0 = num << 1 ;
p.w1 = num >> 1 ;
return p ;
}
for recent x86_64, under v7.1.0, using "-O3", compiles to:
pair:
lea (%rdi,%rdi,1),%eax
sar %edi
movslq %edi,%rdi
cltq
mov %rax,-0x18(%rsp)
movq -0x18(%rsp),%xmm0
mov %rdi,-0x18(%rsp)
movhps -0x18(%rsp),%xmm0
movaps %xmm0,-0x18(%rsp)
mov -0x18(%rsp),%rax
mov -0x10(%rsp),%rdx
retq
using "-O3 -fno-tree-vectorize", compiles to:
pair:
lea (%rdi,%rdi,1),%eax
sar %edi
movslq %edi,%rdx
cltq
retq
I note that v6.3 produces the shorter code without the "-fno-tree-vectorize".