public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/49795] New: vectorization of conditional code happens only on local variables
@ 2011-07-20 11:46 vincenzo.innocente at cern dot ch
2011-07-20 11:58 ` [Bug tree-optimization/49795] " jakub at gcc dot gnu.org
` (6 more replies)
0 siblings, 7 replies; 8+ messages in thread
From: vincenzo.innocente at cern dot ch @ 2011-07-20 11:46 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49795
Summary: vectorization of conditional code happens only on
local variables
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 this example loop1 does not vectorize, loop2 does
const int N=64;
float c[N];
float d[N];
void loop1() {
for (int i=0; i!=N; ++i) {
if (c[i]<0) d[i] = -d[i];
}
}
void loop2() {
for (int i=0; i!=N; ++i) {
float tmp = d[i];
if (c[i]<0) tmp = -tmp;
d[i]=tmp;
}
}
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug tree-optimization/49795] vectorization of conditional code happens only on local variables
2011-07-20 11:46 [Bug tree-optimization/49795] New: vectorization of conditional code happens only on local variables vincenzo.innocente at cern dot ch
@ 2011-07-20 11:58 ` jakub at gcc dot gnu.org
2011-07-20 12:01 ` paolo.carlini at oracle dot com
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu.org @ 2011-07-20 11:58 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49795
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jakub at gcc dot gnu.org
--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> 2011-07-20 11:57:56 UTC ---
At least from C++0x memory model or OpenMP POV that's highly desirable.
In loop1 d[i] isn't written unconditionally, in loop2 it is, so transforming
loop1 code into loop2 might introduce data races.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug tree-optimization/49795] vectorization of conditional code happens only on local variables
2011-07-20 11:46 [Bug tree-optimization/49795] New: vectorization of conditional code happens only on local variables vincenzo.innocente at cern dot ch
2011-07-20 11:58 ` [Bug tree-optimization/49795] " jakub at gcc dot gnu.org
@ 2011-07-20 12:01 ` paolo.carlini at oracle dot com
2011-07-20 12:32 ` vincenzo.innocente at cern dot ch
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: paolo.carlini at oracle dot com @ 2011-07-20 12:01 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49795
--- Comment #2 from Paolo Carlini <paolo.carlini at oracle dot com> 2011-07-20 12:00:32 UTC ---
Interesting. Then I would be curious to know what other respected compilers vs
OpenMP do in this area, eg, Intel..
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug tree-optimization/49795] vectorization of conditional code happens only on local variables
2011-07-20 11:46 [Bug tree-optimization/49795] New: vectorization of conditional code happens only on local variables vincenzo.innocente at cern dot ch
2011-07-20 11:58 ` [Bug tree-optimization/49795] " jakub at gcc dot gnu.org
2011-07-20 12:01 ` paolo.carlini at oracle dot com
@ 2011-07-20 12:32 ` vincenzo.innocente at cern dot ch
2011-07-20 12:41 ` jakub at gcc dot gnu.org
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: vincenzo.innocente at cern dot ch @ 2011-07-20 12:32 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49795
--- Comment #3 from vincenzo Innocente <vincenzo.innocente at cern dot ch> 2011-07-20 12:32:21 UTC ---
my actual code looks more like this
void loop() {
for (int i=0; i!=N; ++i) {
d[i]=a[i]+b[i];
if (c[i]<0) d[i] = -d[i];
}
}
where d[i] IS written unconditionally (and does not vectorize either)
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug tree-optimization/49795] vectorization of conditional code happens only on local variables
2011-07-20 11:46 [Bug tree-optimization/49795] New: vectorization of conditional code happens only on local variables vincenzo.innocente at cern dot ch
` (2 preceding siblings ...)
2011-07-20 12:32 ` vincenzo.innocente at cern dot ch
@ 2011-07-20 12:41 ` jakub at gcc dot gnu.org
2011-07-20 14:54 ` rguenth at gcc dot gnu.org
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu.org @ 2011-07-20 12:41 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49795
--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> 2011-07-20 12:41:07 UTC ---
That is something different, yeah, in that case the transformation doesn't
introduce new data races and is desirable as well, not just for vectorization.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug tree-optimization/49795] vectorization of conditional code happens only on local variables
2011-07-20 11:46 [Bug tree-optimization/49795] New: vectorization of conditional code happens only on local variables vincenzo.innocente at cern dot ch
` (3 preceding siblings ...)
2011-07-20 12:41 ` jakub at gcc dot gnu.org
@ 2011-07-20 14:54 ` rguenth at gcc dot gnu.org
2011-07-20 17:00 ` vincenzo.innocente at cern dot ch
2023-08-24 7:44 ` pinskia at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu.org @ 2011-07-20 14:54 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49795
Richard Guenther <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |missed-optimization
Status|UNCONFIRMED |NEW
Last reconfirmed| |2011.07.20 14:53:41
CC| |rguenth at gcc dot gnu.org,
| |spop at gcc dot gnu.org
Ever Confirmed|0 |1
Severity|normal |enhancement
--- Comment #5 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-07-20 14:53:41 UTC ---
I think you at least need -ftree-loop-if-convert-stores to vectorize
conditional stores, but it doens't seem to work in this case.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug tree-optimization/49795] vectorization of conditional code happens only on local variables
2011-07-20 11:46 [Bug tree-optimization/49795] New: vectorization of conditional code happens only on local variables vincenzo.innocente at cern dot ch
` (4 preceding siblings ...)
2011-07-20 14:54 ` rguenth at gcc dot gnu.org
@ 2011-07-20 17:00 ` vincenzo.innocente at cern dot ch
2023-08-24 7:44 ` pinskia at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: vincenzo.innocente at cern dot ch @ 2011-07-20 17:00 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49795
--- Comment #6 from vincenzo Innocente <vincenzo.innocente at cern dot ch> 2011-07-20 16:59:20 UTC ---
actually -ftree-loop-if-convert-stores does the "trick" with -Ofast
things are not fully consistent though
of these four loop I get the following
notice how the combination -ftree-loop-if-convert-stores -03 vectorize the
first BUT not the second!
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];
void loop1() {
for (int i=0; i!=N; ++i) {
d[i]=a[i]+b[i];
if (c[i]<0) d[i] = -d[i];
}
}
void loop2() {
for (int i=0; i!=N; ++i) {
float tmp = a[i]+b[i];
if (c[i]<0) tmp = -tmp;
d[i]=tmp;
}
}
void loop3() {
for (int i=0; i!=N; ++i) {
d[i] = (c[i]>0) ? a[i]+b[i] : -a[i]-b[i];
}
}
void loop4() {
for (int i=0; i!=N; ++i) {
float tmp = a[i]+b[i];
tmp = (c[i]>0) ? tmp : -tmp;
d[i] = tmp;
}
}
c++ -Wall -O3 -ftree-vectorizer-verbose=2 -c test/testBug.cpp -o bha.o
test/testBug.cpp:9: note: vectorized 0 loops in function.
test/testBug.cpp:17: note: LOOP VECTORIZED.
test/testBug.cpp:16: note: vectorized 1 loops in function.
test/testBug.cpp:24: note: vectorized 0 loops in function.
test/testBug.cpp:31: note: not vectorized: unsupported data-type bool
test/testBug.cpp:30: note: vectorized 0 loops in function.
pb-d-128-141-131-10:Octave innocent$ c++ -Wall -O3 -ftree-vectorizer-verbose=2
-c test/testBug.cpp -o bha.o -ftree-loop-if-convert-stores
test/testBug.cpp:10: note: LOOP VECTORIZED.
test/testBug.cpp:9: note: vectorized 1 loops in function.
test/testBug.cpp:16: note: vectorized 0 loops in function.
test/testBug.cpp:24: note: vectorized 0 loops in function.
test/testBug.cpp:30: note: vectorized 0 loops in function.
pb-d-128-141-131-10:Octave innocent$ c++ -Wall -Ofast
-ftree-vectorizer-verbose=2 -c test/testBug.cpp -o bha.o
-ftree-loop-if-convert-stores
test/testBug.cpp:10: note: LOOP VECTORIZED.
test/testBug.cpp:9: note: vectorized 1 loops in function.
test/testBug.cpp:17: note: LOOP VECTORIZED.
test/testBug.cpp:16: note: vectorized 1 loops in function.
test/testBug.cpp:25: note: LOOP VECTORIZED.
test/testBug.cpp:24: note: vectorized 1 loops in function.
test/testBug.cpp:31: note: LOOP VECTORIZED.
test/testBug.cpp:30: note: vectorized 1 loops in function.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug tree-optimization/49795] vectorization of conditional code happens only on local variables
2011-07-20 11:46 [Bug tree-optimization/49795] New: vectorization of conditional code happens only on local variables vincenzo.innocente at cern dot ch
` (5 preceding siblings ...)
2011-07-20 17:00 ` vincenzo.innocente at cern dot ch
@ 2023-08-24 7:44 ` pinskia at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-08-24 7:44 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=49795
--- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to vincenzo Innocente from comment #6)
loop1, loop2, and loop4 all vectorize now at -O3.
loop3 can vectorize with -O3 -fno-trapping-math (it can also be vectorize at
-O3 on x86_64 with -march=skylake-avx512 or on aarch64 with SVE enabled).
I almost want to say there is not much to do here.
also about comment #0, the vectorizer does happen for -mavx2. So maybe this is
enough these days ...
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2023-08-24 7:44 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-07-20 11:46 [Bug tree-optimization/49795] New: vectorization of conditional code happens only on local variables vincenzo.innocente at cern dot ch
2011-07-20 11:58 ` [Bug tree-optimization/49795] " jakub at gcc dot gnu.org
2011-07-20 12:01 ` paolo.carlini at oracle dot com
2011-07-20 12:32 ` vincenzo.innocente at cern dot ch
2011-07-20 12:41 ` jakub at gcc dot gnu.org
2011-07-20 14:54 ` rguenth at gcc dot gnu.org
2011-07-20 17:00 ` vincenzo.innocente at cern dot ch
2023-08-24 7:44 ` pinskia at gcc dot gnu.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).