https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85017

            Bug ID: 85017
           Summary: Missed constant propagation to index of array
                    reference
           Product: gcc
           Version: 8.0.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: sergey.shalnov at intel dot com
  Target Milestone: ---

I found extra instruction generated on x86_64 platform. I have no performance
data to prove performance gap for this but other compilers generates more
optimal code from my point of view.

Command line (the same with -O2 and -O3):
gcc -c -O1 test.c


The source code:

char arr[400];

char foo(int c)
{
    int i = c + 20;
    return arr[i];
}

Main trunk GCC generates following:
  addl    $20, %edi
  movslq  %edi, %rdi
  movzbl  arr(%rdi), %eax
  ret

but other compilers (example with clang):
  movslq  %edi, %rax
  movb    arr+20(%rax), %al
  retq

The constant $20 is better to propagate into array loading instead adding it to
the register explicitly.

Could someone please advice me a workaround or patch? I will provide a
performance data for this.

Sergey

Reply via email to