[Bug tree-optimization/28940] New: Overzealous CSE with static array access

lmakhlis at bmc dot com gcc-bugzilla@gcc.gnu.org
Sat Sep 2 21:14:00 GMT 2006

char a[10], b[10];

int f1(int i)
        return a[i+1] + b[i+1];

With -O1 and higher, gcc performs CSE on i+1:

        addl    $1, %edi
        movslq  %edi,%rdi
        movsbl  a(%rdi),%eax
        movsbl  b(%rdi),%edx
        addl    %edx, %eax

This doesn't happen with the equivalent
        return (&a[0])[i+1] + (&b[0])[i+1];
        return *(a + i + 1) + *(b + i + 1);
which both compile to
        movslq  %edi,%rdi
        movsbl  a+1(%rdi),%eax
        movsbl  b+1(%rdi),%edx
        addl    %edx, %eax

           Summary: Overzealous CSE with static array access
           Product: gcc
           Version: 4.1.1
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: tree-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: lmakhlis at bmc dot com
 GCC build triplet: x86_64-redhat-linux
  GCC host triplet: x86_64-redhat-linux
GCC target triplet: x86_64-redhat-linux


More information about the Gcc-bugs mailing list