public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "vincenzo.innocente at cern dot ch" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/49849] New: loop optimization prevents vectorization
Date: Tue, 26 Jul 2011 07:46:00 -0000 [thread overview]
Message-ID: <bug-49849-4@http.gcc.gnu.org/bugzilla/> (raw)
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49849
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 prevent
the optimization of the second inner loop in "bar"
compare
c++ -Wall -O2 -ftree-vectorize -ftree-vectorizer-verbose=7 -c vectHist.cpp
-ffast-math
c++ -Wall -O3 -ftree-vectorize -ftree-vectorizer-verbose=7 -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=optimizers > /tmp/O3-opts
gcc -c -Q -O2 --help=optimizers > /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=gnu++0x -DNDEBUG -Wall -O2 -ftree-vectorize -msse4
-fvisibility-inlines-hidden -ftree-vectorizer-verbose=2 --param
vect-max-version-for-alias-checks=30 -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 =
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 =
hist[D.4976_29];
vectHist.cpp:33: note: LOOP VECTORIZED.
vectHist.cpp:31: note: not vectorized: data ref analysis failed D.4957_13 =
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 effective
as I added all options by hand) does not vectorize…
c++ -std=gnu++0x -DNDEBUG -Wall -O3 -mavx -ftree-vectorize -msse4
-fvisibility-inlines-hidden -ftree-vectorizer-verbose=2 --param
vect-max-version-for-alias-checks=30 -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 =
co[D.5125_4];
vectHist.cpp:17: note: not vectorized: data ref analysis failed x_5 =
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 =
co[D.5095_54];
vectHist.cpp:30: note: not vectorized: data ref analysis failed D.5096_55 =
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<cmath>
const int N=1024;
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=0; i!=N; ++i) {
float x = co[k[i]];
float y = a[i]/std::sqrt(x*b[i]);
++hist[int(y)];
}
}
// let's give it an hand: split the loop so that the "heavy duty one" vectorize
void bar() {
const int S=8;
int loops = N/S;
float x[S];
float y[S];
for (int j=0; j!=loops; ++j) {
for (int i=0; i!=S; ++i)
x[i] = co[k[j+i]];
for (int i=0; i!=S; ++i) // this should vectorize
y[i] = a[j+i]/std::sqrt(x[i]*b[j+i]);
for (int i=0; i!=S; ++i)
++hist[int(y[i])];
}
}
next reply other threads:[~2011-07-26 7:46 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-07-26 7:46 vincenzo.innocente at cern dot ch [this message]
2011-07-26 8:31 ` [Bug tree-optimization/49849] " vincenzo.innocente at cern dot ch
2011-07-26 9:21 ` rguenth at gcc dot gnu.org
2011-07-26 9:38 ` vincenzo.innocente at cern dot ch
2011-07-26 9:46 ` rguenth at gcc dot gnu.org
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=bug-49849-4@http.gcc.gnu.org/bugzilla/ \
--to=gcc-bugzilla@gcc.gnu.org \
--cc=gcc-bugs@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).