https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63679
Bug ID: 63679 Summary: [4.9 Regression][AArch64] Failure to constant fold. Product: gcc Version: 5.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: belagod at gcc dot gnu.org When this piece of code is compiled with -O3 -mgeneral-regs-only 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; } 4.9 gcc generates: foo: sub sp, sp, #32 mov w0, 28 add sp, sp, 32 ret .size foo, .-foo .ident "GCC: (unknown) 4.9.2 20140930 (prerelease)" 5.0 generates: foo: adrp x0, .LANCHOR0 sub sp, sp, #32 add x0, x0, :lo12:.LANCHOR0 ldr x7, [x0] ldr x6, [x0, 16] ldr x1, [x0, 8] sbfx x5, x7, 32, 32 ldr x0, [x0, 24] add w2, w6, w7 str x0, [sp, 24] mov x4, x1 str x1, [sp, 8] sbfx x1, x6, 32, 32 ldr x3, [sp, 24] add w1, w1, w5 add w1, w1, w2 str x7, [sp] add w0, w3, w4 sbfx x4, x4, 32, 32 sbfx x3, x3, 32, 32 add w0, w0, w1 add w3, w4, w3 str x6, [sp, 16] add w0, w3, w0 add sp, sp, 32 ret .size foo, .-foo .section .rodata .align 3 .LANCHOR0 = . + 0 .LC0: .word 0 .word 1 .word 2 .word 3 .word 4 .word 5 .word 6 .word 7 .ident "GCC: (unknown) 5.0.0 20141023 (experimental)" Constant-folding seems to have got a bit messed up. I've observed this only on aarch64-none-elf-gcc. 5.0 x86_64 seems to work fine. foo: .LFB0: .cfi_startproc movl $28, %eax ret .cfi_endproc .LFE0: .size foo, .-foo .section .text.unlikely .LCOLDE0: .text .LHOTE0: .ident "GCC: (GNU) 5.0.0 20141023 (experimental)" .section .note.GNU-stack,"",@progbits Looks like a aarch64-specific backend issue. $ aarch64-none-elf-gcc -v Target: aarch64-none-elf Configured with: /work/dev/arm/src/gcc/configure --target=aarch64-none-elf --prefix=/work/dev/arm/bin//install --with-gmp=/work/dev/arm/bin//host-tools --with-mpfr=/work/dev/arm/bin//host-tools --with-mpc=/work/dev/arm/bin//host-tools --with-cloog=/work/dev/arm/bin//host-tools --with-isl=/work/dev/arm/bin//host-tools --with-pkgversion=unknown --disable-shared --disable-nls --disable-threads --disable-tls --enable-checking=yes --enable-languages=c,c++ --with-newlib Thread model: single gcc version 5.0.0 20141023 (experimental) (unknown)