This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug tree-optimization/66664] New: gcc misses optimization emits subtraction where relocation arithmetic would suffice
- From: "fuz at fuz dot su" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 25 Jun 2015 12:25:07 +0000
- Subject: [Bug tree-optimization/66664] New: gcc misses optimization emits subtraction where relocation arithmetic would suffice
- Auto-submitted: auto-generated
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