public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/55342] New: [LRA,x86] Non-optimal code for simple loop with LRA
@ 2012-11-15 15:25 ysrumyan at gmail dot com
  2012-11-15 16:47 ` [Bug rtl-optimization/55342] " hjl.tools at gmail dot com
                   ` (20 more replies)
  0 siblings, 21 replies; 22+ messages in thread
From: ysrumyan at gmail dot com @ 2012-11-15 15:25 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55342

             Bug #: 55342
           Summary: [LRA,x86] Non-optimal code for simple loop with LRA
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: ysrumyan@gmail.com
            Target: x86


For a simple test-case we got -15% regression with LRA on x86 in 32-bit mode.
The test-case is

#define byte unsigned char
#define MIN(a, b) ((a) > (b)?(b):(a))

void convert_image(byte *in, byte *out, int size) {
    int i;
    byte * read = in,
     * write = out;
    for(i = 0; i < size; i++) {
        byte r = *read++;
        byte g = *read++;
        byte b = *read++;
        byte c, m, y, k, tmp;
        c = 255 - r;
        m = 255 - g;
        y = 255 - b;
    if (c < m)
      k = MIN (c, y);
    else
          k = MIN (m, y);
        *write++ = c - k;
        *write++ = m - k;
        *write++ = y - k;
        *write++ = k;
    }
}

The essential part of assembly is (it is correspondent to write-part of loop): 

without LRA
.L4:
    movl    %esi, %ecx
    addl    $4, %eax
    subl    %ecx, %ebx
    movzbl    3(%esp), %ecx
    movb    %bl, -4(%eax)
    movl    %esi, %ebx
    subl    %ebx, %edx
    movb    %dl, -2(%eax)
    subl    %ebx, %ecx
    movb    %cl, -3(%eax)
    cmpl    %ebp, 4(%esp)
    movb    %bl, -1(%eax)
    je    .L1

with LRA

.L4:
    movl    %esi, %eax
    subl    %eax, %ebx
    movl    28(%esp), %eax
    movb    %bl, (%eax)
    movl    %esi, %eax
    subl    %eax, %ecx
    movl    28(%esp), %eax
    movb    %cl, 1(%eax)
    movl    %esi, %eax
    subl    %eax, %edx
    movl    28(%esp), %eax
    movb    %dl, 2(%eax)
    addl    $4, %eax
    movl    %eax, 28(%esp)
    movl    28(%esp), %ecx
    movl    %esi, %eax
    cmpl    %ebp, (%esp)
    movb    %al, -1(%ecx)
    je    .L1

I also wonder why additional moves are required to perform subtraction:

    movl  %esi, %eax
    subl  %eax, %ebx

whereas only one instruction is required:
    subl  %esi, %ebx.

I assume that this part is not related to LRA.


^ permalink raw reply	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2015-06-26 20:35 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-11-15 15:25 [Bug rtl-optimization/55342] New: [LRA,x86] Non-optimal code for simple loop with LRA ysrumyan at gmail dot com
2012-11-15 16:47 ` [Bug rtl-optimization/55342] " hjl.tools at gmail dot com
2012-11-17 18:01 ` [Bug rtl-optimization/55342] [4.8 Regression] " vmakarov at gcc dot gnu.org
2012-11-19 12:06 ` ysrumyan at gmail dot com
2012-12-07 10:13 ` rguenth at gcc dot gnu.org
2013-01-28 18:53 ` jakub at gcc dot gnu.org
2013-02-20 14:11 ` rguenth at gcc dot gnu.org
2013-03-22 14:48 ` [Bug rtl-optimization/55342] [4.8/4.9 " jakub at gcc dot gnu.org
2013-05-31 10:59 ` jakub at gcc dot gnu.org
2013-06-06 15:20 ` vmakarov at gcc dot gnu.org
2013-09-05 14:44 ` ysrumyan at gmail dot com
2013-09-05 14:51 ` ysrumyan at gmail dot com
2013-09-13 13:00 ` ysrumyan at gmail dot com
2013-09-13 13:03 ` ysrumyan at gmail dot com
2013-10-16  9:50 ` jakub at gcc dot gnu.org
2014-05-22  9:07 ` [Bug rtl-optimization/55342] [4.8/4.9/4.10 " rguenth at gcc dot gnu.org
2014-12-19 13:36 ` [Bug rtl-optimization/55342] [4.8/4.9/5 " jakub at gcc dot gnu.org
2015-02-12  7:19 ` [Bug rtl-optimization/55342] [4.8/4.9 " law at redhat dot com
2015-02-12 13:47 ` jakub at gcc dot gnu.org
2015-06-23  8:21 ` rguenth at gcc dot gnu.org
2015-06-26 20:09 ` [Bug rtl-optimization/55342] [4.9 " jakub at gcc dot gnu.org
2015-06-26 20:36 ` jakub at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).