Inner-loop optimization regression from 3.3 to 3.4

Zack Weinberg zack@codesourcery.com
Mon Oct 13 12:25:00 GMT 2003


I wanted a break from machine modes so I thought I'd squeeze some
cycles out of _cpp_skip_block_comment.  In the process I discovered
a serious optimization regression in 3.4, relative to 3.3.

Consider code like the following.

void
_cpp_skip_block_comment (struct cpp_buffer *buf)
{
  unsigned char c, *cur = buf->cur;

  for (;;)
    {
      do
        c = *cur++;
      while (c != '/' && c != '\n');

      if (c == '/')
        {
          if (cur[-2] == '*'
            break;
        
          foo();
        }
      else if (c == '\n')
        bar();
   }
  buf->cur = cur;
}

3.3 generates code like this (I'm only showing the inner loop):

.L93:
        incl    %ebx
        cmpb    $47, %al
        je      .L92
        cmpb    $10, %al
        je      .L94
.L88:
        movzbl  (%ebx), %eax
        jmp     .L93

whereas 3.4 generates code like this:

.L93:
        incl    %ebx
        cmpb    $47, %cl
        setne   %al
        xorl    %edx, %edx
        cmpb    $10, %cl
        setne   %dl
        testl   %eax, %edx
        jne     .L88
        cmpb    $47, %cl
        je      .L92
        cmpb    $10, %cl
        je      .L94
.L88:
        movzbl  (%ebx), %ecx
        jmp     .L93

It seems obvious that 3.4 is significantly worse.  Jan, I'm cc:ing you
because you know the i386 back end and the RTL optimizers quite well.
But if anyone has any idea what has happened here and how we can fix
it, that would be cool.

My patch is a significant win for other reasons, so I'll be checking
it in after it completes testing - if you want to see the code before
it shows up in CVS, let me know.

zw



More information about the Gcc mailing list