[Bug inline-asm/65741] New: Missed loop optimization with asm

gccbugzilla at limegreensocks dot com gcc-bugzilla@gcc.gnu.org
Sat Apr 11 06:00:00 GMT 2015


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

            Bug ID: 65741
           Summary: Missed loop optimization with asm
           Product: gcc
           Version: 5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: inline-asm
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gccbugzilla at limegreensocks dot com

Trimming the code down to minimal:

int main()
{
   int lo;

   for(int x=0; x < 10; x++)
   {
      asm ( "# asm here" : "=r" (lo));
   }

   return lo;
}

Compile with: c++.exe -O2 -m64 -S loop.cpp
x86_64-w64-mingw32 5.0.0

The -O2 optimization correctly detects that the asm statement can be moved
outside the loop (and moves it).  However, it then leaves an empty loop:

        movl    $10, %edx
/APP
 # 7 "loop.cpp" 1
        #
 # 0 "" 2
        .p2align 4,,10
/NO_APP
.L2:
        subl    $1, %edx
        jne     .L2

With the asm moved, the .L2 loop serves no purpose.  I expected it to get
optimized out.

Even more perplexing is that if the asm has 2 outputs, it *doesn't* get moved
outside the loop:

int main()
{
   int hi, lo;

   for(int x=0; x < 10; x++)
   {
      asm  ( "# asm here" : "=r" (lo), "=r" (hi));
   }

   return hi * lo;
}

        movl    $10, %edx
        .p2align 4,,10
.L2:
/APP
 # 7 "loop.cpp" 1
        # asm here
 # 0 "" 2
/NO_APP
        subl    $1, %edx
        jne     .L2

I expected this asm to get moved just like the other one did.



More information about the Gcc-bugs mailing list