http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57540
Bug ID: 57540 Summary: stack pointer related loop invariants after reload Product: gcc Version: 4.9.0 Status: UNCONFIRMED Severity: enhancement Priority: P3 Component: rtl-optimization Assignee: unassigned at gcc dot gnu.org Reporter: amker.cheng at gmail dot com For below program, void foo ( unsigned char *len, int alphaSize, int maxLen ) { int i, j, k; unsigned char tooLong; int parent [ 258 * 2 ]; parent[0] = -2; tooLong = 0; for (i = 1; i <= alphaSize; i++) { j = 0; k = i; while (parent[k] >= 0) { k = parent[k]; j++; } len[i-1] = j; if (j > maxLen) tooLong = 1; } } Compile with command line, arm-linux-gnueabihf-gcc -S -O2 -marm -mcpu=cortex-a15 -o foo.S -xc foo.E The generated code is like, .cpu cortex-a15 .eabi_attribute 27, 3 .eabi_attribute 28, 1 .fpu vfpv3-d16 .eabi_attribute 20, 1 .eabi_attribute 21, 1 .eabi_attribute 23, 3 .eabi_attribute 24, 1 .eabi_attribute 25, 1 .eabi_attribute 26, 2 .eabi_attribute 30, 2 .eabi_attribute 34, 1 .eabi_attribute 18, 4 .file "foo.E" .text .align 2 .global foo .type foo, %function foo: @ args = 0, pretend = 0, frame = 2064 @ frame_needed = 0, uses_anonymous_args = 0 str lr, [sp, #-4]! sub sp, sp, #2064 mvn r3, #1 sub sp, sp, #4 cmp r1, #0 str r3, [sp] ble .L1 mov ip, sp add r1, r0, r1 .L6: ldr r3, [ip, #4]! mov r2, #0 cmp r3, #0 blt .L3 .L5: add lr, sp, #2064 ////loop invariant add r2, r2, #1 add r3, lr, r3, asl #2 ldr r3, [r3, #-2064] cmp r3, #0 bge .L5 uxtb r2, r2 .L3: strb r2, [r0], #1 cmp r0, r1 bne .L6 .L1: add sp, sp, #2064 add sp, sp, #4 @ sp needed ldr pc, [sp], #4 .size foo, .-foo .ident "GCC: (GNU) 4.9.0 20130524 (experimental)" .section .note.GNU-stack,"",%progbits Apparently, first instruction in basic block .L5 is invariant, but kept in loop because it is generated by reload. I think this is a common issue.