public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/38434] New: [4.4 Regression] speed regression with hand-unrolled matmul
@ 2008-12-07 11:35 tkoenig at gcc dot gnu dot org
2008-12-07 11:36 ` [Bug rtl-optimization/38434] " tkoenig at gcc dot gnu dot org
` (7 more replies)
0 siblings, 8 replies; 9+ messages in thread
From: tkoenig at gcc dot gnu dot org @ 2008-12-07 11:35 UTC (permalink / raw)
To: gcc-bugs
$ gfortran-4.3 -O3 -funroll-all-loops -ffast-math foo-2.f90
$ ./a.out
subroutine with explicit interface and unroll(1): 2.3321450 s
$ gfortran -O3 -funroll-all-loops -ffast-math foo-2.f90
$ ./a.out
subroutine with explicit interface and unroll(1): 3.0121880 s
$ gfortran -v
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: ../../gcc/trunk/configure --prefix=/home/ig25
--enable-languages=c,fortran --enable-maintainer-mode
Thread model: posix
gcc version 4.4.0 20081122 (experimental) (GCC)
$ cat foo-2.f90
module foo
implicit none
contains
subroutine unroll(a,b,c)
real, dimension(3,3) :: a,b,c
integer :: i,j
do i=1,3
do j=1,3
c(i,j) = a(i,1)*b(1,j) + a(i,2)*b(2,j) + a(i,3)*b(3,j)
end do
end do
end subroutine unroll
end module foo
program main
use foo
implicit none
integer :: k
real, dimension(3,3) :: a,b,c, a0, b0
real :: t1, t2
character(len=90) :: line
call random_number(a0)
call random_number(b0)
a = a0
b = b0
call cpu_time(t1)
do k=1,10**8
call unroll(a,b,c)
end do
call cpu_time(t2)
print *,"subroutine with explicit interface and unroll(1): ",t2-t1, " s"
write (unit=line,fmt='(9G10.3)') c
end program main
--
Summary: [4.4 Regression] speed regression with hand-unrolled
matmul
Product: gcc
Version: 4.4.0
Status: UNCONFIRMED
Keywords: missed-optimization
Severity: normal
Priority: P3
Component: rtl-optimization
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: tkoenig at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38434
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug rtl-optimization/38434] [4.4 Regression] speed regression with hand-unrolled matmul
2008-12-07 11:35 [Bug rtl-optimization/38434] New: [4.4 Regression] speed regression with hand-unrolled matmul tkoenig at gcc dot gnu dot org
@ 2008-12-07 11:36 ` tkoenig at gcc dot gnu dot org
2008-12-07 11:56 ` tkoenig at gcc dot gnu dot org
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: tkoenig at gcc dot gnu dot org @ 2008-12-07 11:36 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from tkoenig at gcc dot gnu dot org 2008-12-07 11:34 -------
I forgot:
$ cat /proc/cpuinfo
processor : 0
vendor_id : AuthenticAMD
cpu family : 6
model : 8
model name : AMD Athlon(TM) XP 2600+
stepping : 1
cpu MHz : 2083.200
cache size : 256 KB
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 1
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov
pat pse36 mmx fxsr sse syscall mmxext 3dnowext 3dnow up ts
bogomips : 4170.03
clflush size : 32
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38434
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug rtl-optimization/38434] [4.4 Regression] speed regression with hand-unrolled matmul
2008-12-07 11:35 [Bug rtl-optimization/38434] New: [4.4 Regression] speed regression with hand-unrolled matmul tkoenig at gcc dot gnu dot org
2008-12-07 11:36 ` [Bug rtl-optimization/38434] " tkoenig at gcc dot gnu dot org
@ 2008-12-07 11:56 ` tkoenig at gcc dot gnu dot org
2008-12-07 12:26 ` tkoenig at gcc dot gnu dot org
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: tkoenig at gcc dot gnu dot org @ 2008-12-07 11:56 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from tkoenig at gcc dot gnu dot org 2008-12-07 11:55 -------
On x86_64:
With 4.3.3:
$ ./a.out
subroutine with explicit interface and unroll(1): 1.5400960 s
With 4.4.0:
$ ./a.out
subroutine with explicit interface and unroll(1): 1.5480961 s
Probably target-specific.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38434
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug rtl-optimization/38434] [4.4 Regression] speed regression with hand-unrolled matmul
2008-12-07 11:35 [Bug rtl-optimization/38434] New: [4.4 Regression] speed regression with hand-unrolled matmul tkoenig at gcc dot gnu dot org
2008-12-07 11:36 ` [Bug rtl-optimization/38434] " tkoenig at gcc dot gnu dot org
2008-12-07 11:56 ` tkoenig at gcc dot gnu dot org
@ 2008-12-07 12:26 ` tkoenig at gcc dot gnu dot org
2008-12-07 12:41 ` rguenth at gcc dot gnu dot org
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: tkoenig at gcc dot gnu dot org @ 2008-12-07 12:26 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from tkoenig at gcc dot gnu dot org 2008-12-07 12:25 -------
I'll upgrade to current trunk and run another test.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38434
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug rtl-optimization/38434] [4.4 Regression] speed regression with hand-unrolled matmul
2008-12-07 11:35 [Bug rtl-optimization/38434] New: [4.4 Regression] speed regression with hand-unrolled matmul tkoenig at gcc dot gnu dot org
` (2 preceding siblings ...)
2008-12-07 12:26 ` tkoenig at gcc dot gnu dot org
@ 2008-12-07 12:41 ` rguenth at gcc dot gnu dot org
2008-12-09 19:31 ` mmitchel at gcc dot gnu dot org
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2008-12-07 12:41 UTC (permalink / raw)
To: gcc-bugs
------- Comment #4 from rguenth at gcc dot gnu dot org 2008-12-07 12:40 -------
There is one thing that is on my list to investigate. This is how the
following
impacts hardware prefetchers:
<bb 2>:
pretmp.34_33 = (*b_13(D))[6];
pretmp.34_62 = (*b_13(D))[7];
pretmp.34_88 = (*b_13(D))[8];
pretmp.37_92 = (*b_13(D))[0];
pretmp.39_95 = (*b_13(D))[1];
pretmp.39_97 = (*b_13(D))[2];
pretmp.39_99 = (*b_13(D))[3];
pretmp.39_101 = (*b_13(D))[4];
pretmp.39_103 = (*b_13(D))[5];
D.1523_164 = (*a_9(D))[0];
D.1526_163 = D.1523_164 * pretmp.37_92;
D.1528_194 = (*a_9(D))[3];
D.1531_192 = D.1528_194 * pretmp.39_95;
D.1532_191 = D.1526_163 + D.1531_192;
D.1534_189 = (*a_9(D))[6];
...
that is, should we try to schedule memory loads and stores to be sequential?
It would be interesting to measure the difference in manually unrolled code
with optimal ordering and the ordering generated by the compiler during
unrolling.
Other than that, the above (all loads of b before all uses) certaily increases
register pressure for i?86 too much so you get spills:
flds 24(%ecx)
fstps -24(%ebp)
flds 28(%ecx)
fstps -20(%ebp)
flds 32(%ecx)
fstps -16(%ebp)
flds (%ecx)
flds 4(%ecx)
flds 8(%ecx)
flds 12(%ecx)
fstps -12(%ebp)
...
and the RTL level doesn't know enough about aliasing to do anything about that.
-fschedule-insns manages to improve things somewhat again - but certainly
scheduling of loads/stores at the tree level would be nice (re-assoc only
schedules registers).
In the end this shouldn't be a regression - maybe the early unrolling of the
innermost loop we do changes things enough though.
It is interesting that before PRE the loads from b are in-order, but PRE
insertion places them out-of-order. Huh. Because we iterate over antic
expressions.
--
rguenth at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
GCC target triplet| |i?86-*-*
Target Milestone|--- |4.4.0
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38434
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug rtl-optimization/38434] [4.4 Regression] speed regression with hand-unrolled matmul
2008-12-07 11:35 [Bug rtl-optimization/38434] New: [4.4 Regression] speed regression with hand-unrolled matmul tkoenig at gcc dot gnu dot org
` (3 preceding siblings ...)
2008-12-07 12:41 ` rguenth at gcc dot gnu dot org
@ 2008-12-09 19:31 ` mmitchel at gcc dot gnu dot org
2008-12-10 13:40 ` steven at gcc dot gnu dot org
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: mmitchel at gcc dot gnu dot org @ 2008-12-09 19:31 UTC (permalink / raw)
To: gcc-bugs
--
mmitchel at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Priority|P3 |P2
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38434
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug rtl-optimization/38434] [4.4 Regression] speed regression with hand-unrolled matmul
2008-12-07 11:35 [Bug rtl-optimization/38434] New: [4.4 Regression] speed regression with hand-unrolled matmul tkoenig at gcc dot gnu dot org
` (4 preceding siblings ...)
2008-12-09 19:31 ` mmitchel at gcc dot gnu dot org
@ 2008-12-10 13:40 ` steven at gcc dot gnu dot org
2009-01-31 14:36 ` bonzini at gnu dot org
2009-02-04 12:02 ` [Bug rtl-optimization/38434] big performance boost from 4.3's -O3 vs. -O2 (in any version) on 3x3 matmul bonzini at gnu dot org
7 siblings, 0 replies; 9+ messages in thread
From: steven at gcc dot gnu dot org @ 2008-12-10 13:40 UTC (permalink / raw)
To: gcc-bugs
--
steven at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Ever Confirmed|0 |1
Last reconfirmed|0000-00-00 00:00:00 |2008-12-10 13:36:41
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38434
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug rtl-optimization/38434] [4.4 Regression] speed regression with hand-unrolled matmul
2008-12-07 11:35 [Bug rtl-optimization/38434] New: [4.4 Regression] speed regression with hand-unrolled matmul tkoenig at gcc dot gnu dot org
` (5 preceding siblings ...)
2008-12-10 13:40 ` steven at gcc dot gnu dot org
@ 2009-01-31 14:36 ` bonzini at gnu dot org
2009-02-04 12:02 ` [Bug rtl-optimization/38434] big performance boost from 4.3's -O3 vs. -O2 (in any version) on 3x3 matmul bonzini at gnu dot org
7 siblings, 0 replies; 9+ messages in thread
From: bonzini at gnu dot org @ 2009-01-31 14:36 UTC (permalink / raw)
To: gcc-bugs
------- Comment #5 from bonzini at gnu dot org 2009-01-31 14:36 -------
A pass like the one Google's guy posted to lower register pressure would help
here.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38434
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug rtl-optimization/38434] big performance boost from 4.3's -O3 vs. -O2 (in any version) on 3x3 matmul
2008-12-07 11:35 [Bug rtl-optimization/38434] New: [4.4 Regression] speed regression with hand-unrolled matmul tkoenig at gcc dot gnu dot org
` (6 preceding siblings ...)
2009-01-31 14:36 ` bonzini at gnu dot org
@ 2009-02-04 12:02 ` bonzini at gnu dot org
7 siblings, 0 replies; 9+ messages in thread
From: bonzini at gnu dot org @ 2009-02-04 12:02 UTC (permalink / raw)
To: gcc-bugs
------- Comment #6 from bonzini at gnu dot org 2009-02-04 12:02 -------
We have:
4.3 4.4
-O2 3.36 3.32
-O3 3.02 3.50
-O3 -funroll-all-loops 2.92 3.45
Interestingly enough, if I _really_ hand-unroll the loop as suggested by the
wrong summary, 4.4 is faster than 4.3:
4.3 4.4
-O2 3.53 3.23
-O3 3.53 3.23
-O3 -funroll-all-loops 3.45 3.18
This means:
1) that -funroll-all-loops is not really affecting the benchmark, but only the
test code
2) that the regression is actually at -O3, not at -O2, and there's really no
guarantee of what performance you get past -O2
3) ultimately, that this is not a regression, but just an enhancement request:
4.4 -O2 is better, but not as good as 4.3 -O3.
--- here is the hand-unrolled loop code:
module foo
implicit none
contains
subroutine unroll(a,b,c)
real, dimension(3,3) :: a,b,c
c(1,1) = a(1,1)*b(1,1) + a(1,2)*b(2,1) + a(1,3)*b(3,1)
c(1,2) = a(1,1)*b(1,2) + a(1,2)*b(2,2) + a(1,3)*b(3,2)
c(1,3) = a(1,1)*b(1,3) + a(1,2)*b(2,3) + a(1,3)*b(3,3)
c(2,1) = a(2,1)*b(1,1) + a(2,2)*b(2,1) + a(2,3)*b(3,1)
c(2,2) = a(2,1)*b(1,2) + a(2,2)*b(2,2) + a(2,3)*b(3,2)
c(2,3) = a(2,1)*b(1,3) + a(2,2)*b(2,3) + a(2,3)*b(3,3)
c(3,1) = a(3,1)*b(1,1) + a(3,2)*b(2,1) + a(3,3)*b(3,1)
c(3,2) = a(3,1)*b(1,2) + a(3,2)*b(2,2) + a(3,3)*b(3,2)
c(3,3) = a(3,1)*b(1,3) + a(3,2)*b(2,3) + a(3,3)*b(3,3)
end subroutine unroll
end module foo
program main
use foo
implicit none
integer :: k
real, dimension(3,3) :: a,b,c, a0, b0
real :: t1, t2
character(len=90) :: line
call random_number(a0)
call random_number(b0)
a = a0
b = b0
call cpu_time(t1)
do k=1,10**8
call unroll(a,b,c)
end do
call cpu_time(t2)
print *,"subroutine with explicit interface and unroll(1): ",t2-t1, " s"
write (unit=line,fmt='(9G10.3)') c
end program main
--
bonzini at gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Priority|P2 |P3
Last reconfirmed|2008-12-10 13:36:41 |2009-02-04 12:02:14
date| |
Summary|[4.4 Regression] speed |big performance boost from
|regression with hand- |4.3's -O3 vs. -O2 (in any
|unrolled matmul |version) on 3x3 matmul
Target Milestone|4.4.0 |---
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38434
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2009-02-04 12:02 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-12-07 11:35 [Bug rtl-optimization/38434] New: [4.4 Regression] speed regression with hand-unrolled matmul tkoenig at gcc dot gnu dot org
2008-12-07 11:36 ` [Bug rtl-optimization/38434] " tkoenig at gcc dot gnu dot org
2008-12-07 11:56 ` tkoenig at gcc dot gnu dot org
2008-12-07 12:26 ` tkoenig at gcc dot gnu dot org
2008-12-07 12:41 ` rguenth at gcc dot gnu dot org
2008-12-09 19:31 ` mmitchel at gcc dot gnu dot org
2008-12-10 13:40 ` steven at gcc dot gnu dot org
2009-01-31 14:36 ` bonzini at gnu dot org
2009-02-04 12:02 ` [Bug rtl-optimization/38434] big performance boost from 4.3's -O3 vs. -O2 (in any version) on 3x3 matmul bonzini at gnu dot 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).