https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66664
Bug ID: 66664 Summary: gcc misses optimization emits subtraction where relocation arithmetic would suffice Product: gcc Version: 5.0 Status: UNCONFIRMED Severity: minor Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: fuz at fuz dot su Target Milestone: --- For the following C code: int foo(int x) { extern int bar[]; return bar[x - 1]; } gcc emits the following code (with -O3) on amd64 Linux: foo: subl $1, %edi movslq %edi, %rdi movl bar(,%rdi,4), %eax ret .ident "GCC: (GNU) 5.0.0 20150314 (experimental)" I expected gcc to emit the following (as signed underflow is undefined): foo: movslq %edi, %rdi movl bar-4(,%rdi,4), %eax ret or even this (as the memory model places global variables in the first 2^32 byte of RAM): foo: movl bar-4(,%edi,4), %eax ret