From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4683 invoked by alias); 26 Jul 2011 07:46:16 -0000 Received: (qmail 4673 invoked by uid 22791); 26 Jul 2011 07:46:15 -0000 X-SWARE-Spam-Status: No, hits=-2.8 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00,TW_AV X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 26 Jul 2011 07:46:01 +0000 From: "vincenzo.innocente at cern dot ch" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/49849] New: loop optimization prevents vectorization X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: vincenzo.innocente at cern dot ch X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Date: Tue, 26 Jul 2011 07:46:00 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2011-07/txt/msg02219.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D49849 Summary: loop optimization prevents vectorization Product: gcc Version: 4.7.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization AssignedTo: unassigned@gcc.gnu.org ReportedBy: vincenzo.innocente@cern.ch In the following example I suspect that some sort of loop merging at O3 pre= vent the optimization of the second inner loop in "bar" compare c++ -Wall -O2 -ftree-vectorize -ftree-vectorizer-verbose=3D7 -c vectHist.cpp -ffast-math c++ -Wall -O3 -ftree-vectorize -ftree-vectorizer-verbose=3D7 -c vectHist.cpp -ffast-math what I do not understand is that if (following man page) I compare O2 and O3 with gcc -c -Q -O3 --help=3Doptimizers > /tmp/O3-opts gcc -c -Q -O2 --help=3Doptimizers > /tmp/O2-opts diff /tmp/O2-opts /tmp/O3-opts | grep enabled > -fgcse-after-reload [enabled] > -finline-functions [enabled] > -fipa-cp-clone [enabled] > -fpredictive-commoning [enabled] > -ftree-loop-distribute-patterns [enabled] > -ftree-vectorize [enabled] > -funswitch-loops [enabled] I still get c++ -std=3Dgnu++0x -DNDEBUG -Wall -O2 -ftree-vectorize -msse4 -fvisibility-inlines-hidden -ftree-vectorizer-verbose=3D2 --param vect-max-version-for-alias-checks=3D30 -funsafe-loop-optimizations -ftree-loop-distribution -ftree-loop-if-convert-stores -fipa-pta -Wunsafe-loop-optimizations -fgcse-sm -fgcse-las -c vectHist.cpp -ffast-math -funswitch-loops -ftree-loop-distribute-patterns -fpredictive-commoning -finline-functions -fipa-cp-clone -fgcse-after-reload vectHist.cpp:17: note: not vectorized: data ref analysis failed x_5 =3D co[D.4986_4]; vectHist.cpp:16: note: vectorized 0 loops in function. vectHist.cpp:35: note: not vectorized: data ref analysis failed D.4977_30 = =3D hist[D.4976_29]; vectHist.cpp:33: note: LOOP VECTORIZED. vectHist.cpp:31: note: not vectorized: data ref analysis failed D.4957_13 = =3D co[D.4956_12]; vectHist.cpp:25: note: vectorized 1 loops in function. while changing just O2 in 03 (that at this point should be not really effec= tive as I added all options by hand) does not vectorize=E2=80=A6 c++ -std=3Dgnu++0x -DNDEBUG -Wall -O3 -mavx -ftree-vectorize -msse4 -fvisibility-inlines-hidden -ftree-vectorizer-verbose=3D2 --param vect-max-version-for-alias-checks=3D30 -funsafe-loop-optimizations -ftree-loop-distribution -ftree-loop-if-convert-stores -fipa-pta -Wunsafe-loop-optimizations -fgcse-sm -fgcse-las -c vectHist.cpp -ffast-math -funswitch-loops -ftree-loop-distribute-patterns -fpredictive-commoning -finline-functions -fipa-cp-clone -fgcse-after-reload=20 vectHist.cpp:17: note: not vectorized: data ref analysis failed x_5 =3D co[D.5125_4]; vectHist.cpp:17: note: not vectorized: data ref analysis failed x_5 =3D co[D.5125_4]; vectHist.cpp:16: note: vectorized 0 loops in function. vectHist.cpp:30: note: not vectorized: data ref analysis failed D.5096_55 = =3D co[D.5095_54]; vectHist.cpp:30: note: not vectorized: data ref analysis failed D.5096_55 = =3D co[D.5095_54]; vectHist.cpp:25: note: vectorized 0 loops in function. note how it does not report anything about loops at lines 31,33 and 35 --------------------------- // a classroom example #include const int N=3D1024; float __attribute__ ((aligned(16))) a[N]; float __attribute__ ((aligned(16))) b[N]; float __attribute__ ((aligned(16))) c[N]; float __attribute__ ((aligned(16))) d[N]; int __attribute__ ((aligned(16))) k[N]; float __attribute__ ((aligned(16))) co[12]; float __attribute__ ((aligned(16))) hist[100]; // do not expect GCC to vectorize (yet) void foo() { for (int i=3D0; i!=3DN; ++i) { float x =3D co[k[i]]; float y =3D a[i]/std::sqrt(x*b[i]); ++hist[int(y)]; }=20 } // let's give it an hand: split the loop so that the "heavy duty one" vecto= rize void bar() { const int S=3D8; int loops =3D N/S; float x[S]; float y[S]; for (int j=3D0; j!=3Dloops; ++j) { for (int i=3D0; i!=3DS; ++i) x[i] =3D co[k[j+i]]; for (int i=3D0; i!=3DS; ++i) // this should vectorize y[i] =3D a[j+i]/std::sqrt(x[i]*b[j+i]); for (int i=3D0; i!=3DS; ++i) ++hist[int(y[i])]; }=20 }