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

            Bug ID: 91333
           Summary: [9/10 Regression] suboptimal register allocation for
                    inline asm
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Keywords: ra
          Severity: normal
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: glisse at gcc dot gnu.org
  Target Milestone: ---
            Target: x86_64-*-*

static double g(double x){
  asm volatile("":"+x"(x));
  return x;
}
double f(double a,double b){
  return g(g(a)+g(b));
}

(using -O1, -O2 or -O3)

With gcc-8, I get the sensible

        addsd   %xmm1, %xmm0

With gcc-9, I get

        movapd  %xmm0, %xmm2
        movapd  %xmm1, %xmm0
        movapd  %xmm2, %xmm1
        addsd   %xmm1, %xmm0

For some reason gcc decided to swap the 2 numbers?

-mavx helps remove all the moves, but on this slightly larger example:

double h(double a,double b){
  return f(f(a,a),f(b,b));
}

-mavx actually increases the number of moves, from 2 to 4... (and at -O1 gcc
does this strange thing where it stores a double in %rax, good thing that
disappears at -O2)

Reply via email to