------- Comment #14 from jv244 at cam dot ac dot uk 2009-05-18 12:19 ------- Created an attachment (id=17886) --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=17886&action=view) simplified testcase for common subexpressions.
Richard, thanks very much for the first patch. I tried to get a better testcase for the issue with the number of multiplies being too large (compile with gfortran -O3 -march=native -ffast-math -cpp test.f90). This is the newly attached test_reassoc.f90. The module contains two equivalent subroutines S1 and S2. In S1, gcc manages to reduce the multiplies nearly to the optimal one (I believe optimal is 81+81+9+9=180, gcc finds 198). In S2, which introduces a temporary array somewhat like in the original, this doesn't happen, and the number of multiplies is 324. Looks like the introduction of the temporary array blocks some optimisation. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40168