[Bug tree-optimization/63677] New: Failure to constant fold with vectorization.

belagod at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Wed Oct 29 15:14:00 GMT 2014


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63677

            Bug ID: 63677
           Summary: Failure to constant fold with vectorization.
           Product: gcc
           Version: 5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: belagod at gcc dot gnu.org

This piece of code:

int __attribute__ ((noinline))
foo ()
{
  const int a[8] = { 0, 1, 2, 3, 4, 5, 6, 7 };
  int i, sum;

  sum = 0;
  for (i = 0; i < sizeof (a) / sizeof (*a); i++)
    sum += a[i];

  return sum;
}

when compiled with -O3 on x86_64 generates:

foo:
.LFB0:
    .cfi_startproc
    movdqa    .LC1(%rip), %xmm0
    paddd    .LC0(%rip), %xmm0
    movdqa    %xmm0, %xmm1
    psrldq    $8, %xmm1
    paddd    %xmm1, %xmm0
    movdqa    %xmm0, %xmm1
    psrldq    $4, %xmm1
    paddd    %xmm1, %xmm0
    movd    %xmm0, %eax
    ret
    .cfi_endproc
.LFE0:
    .size    foo, .-foo
    .section    .text.unlikely
.LCOLDE3:
    .text
.LHOTE3:
    .section    .rodata.cst16,"aM",@progbits,16
    .align 16
.LC0:
    .long    0
    .long    1
    .long    2
    .long    3
    .align 16
.LC1:
    .long    4
    .long    5
    .long    6
    .long    7
    .ident    "GCC: (GNU) 5.0.0 20141023 (experimental)"
    .section    .note.GNU-stack,"",@progbits

but when compiled with -O3 -mno-sse generates:

foo:
.LFB0:
    .cfi_startproc
    movl    $28, %eax
    ret
    .cfi_endproc
.LFE0:
    .size    foo, .-foo
    .section    .text.unlikely
.LCOLDE0:

Why isn't constant folding happening when generating code for vector unit?

$ gcc -v
Using built-in specs.
COLLECT_GCC=/work/dev/arm/bin_x86/install/bin/gcc
COLLECT_LTO_WRAPPER=/work/dev/arm/bin_x86/install/libexec/gcc/x86_64-unknown-linux-gnu/5.0.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../src/gcc/configure --prefix=/work/dev/arm/bin_x86/install
--enable-bootstrap --disable-nls --enable-languages=c,c++,fortran
--disable-multilib
Thread model: posix
gcc version 5.0.0 20141023 (experimental) (GCC)



More information about the Gcc-bugs mailing list