c/859: sparc-specific pessimal code for simple loop

jbuck@synopsys.com jbuck@synopsys.com
Tue Nov 21 13:36:00 GMT 2000


>Number:         859
>Category:       c
>Synopsis:       sparc-specific pessimal code for simple loop
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          pessimizes-code
>Submitter-Id:   net
>Arrival-Date:   Tue Nov 21 13:36:00 PST 2000
>Closed-Date:
>Last-Modified:
>Originator:     Joe Buck
>Release:        gcc version 2.97 20001120 (experimental)
>Organization:
>Environment:
sparc-sun-solaris2.5.1
>Description:
This seems to be a sparc-specific problem.

The code in How-To-Repeat below contains a simple Fortran
style loop.  The inner loop is 8 highly wasteful instructions on the Sparc (sparc-sun-solaris2.5.1):

.LL6:
        sll     %i2, 3, %i0
        ldd     [%i3+%i0], %f6
        add     %i2, 1, %i2
        fmovs   %f6, %f2
        cmp     %i2, %i1
        fmovs   %f7, %f3
        bl      .LL6
        faddd   %f4, %f2, %f4

But on the ix86 the inner loop is much better, with
only four instructions:

.L21:
        faddl   (%ecx,%eax,8)
        incl    %eax
        cmpl    %edx, %eax
        jl      .L21


The slow Sparc code is also present in 2.95.2 (we get the
same 8-instruction loop).

I first encountered this problem when I was trying to see
why I was getting strange results from the Stepanov C++
abstraction penalty benchmark: on Sparc, the "simple" loop
was generating much worse code than the "abstract" loops.

>How-To-Repeat:
/* compile this code with -O2 on sparc, compare with ix86 */
void check(double);

void test0(double* first, double* last)
{
  int n, pdiff = last - first;
  double result = 0;
  for (n = 0; n < pdiff; ++n) result += first[n];
  check(result);
}
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:


More information about the Gcc-bugs mailing list