https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85315
Bug ID: 85315 Summary: missed optimisation opportunity for derefences Product: gcc Version: 8.0.1 Status: UNCONFIRMED Keywords: missed-optimization Severity: normal Priority: P3 Component: rtl-optimization Assignee: unassigned at gcc dot gnu.org Reporter: vegard.nossum at oracle dot com Target Milestone: --- Input: extern int x; extern int a; extern int b; int f() { int y = x; return *(&y + (a + b)); } With -O3, trunk outputs: f(): movl x(%rip), %eax movl %eax, -4(%rsp) movl b(%rip), %eax addl a(%rip), %eax cltq movl -4(%rsp,%rax,4), %eax ret Clang, on the other hand, infers that (a + b) == 0: f(): # @f() movl x(%rip), %eax retq From richi on IRC: """ we don't do this kind of optimization at the moment a related one would be to place a if (a+b != 0) link_error (); after the memory access similarly for array accesses an if (i not-in-range) link_error () thus, we do not derive ranges for address-computation parts [at dereference sites] """