[Bug c++/85232] New: gcc fails to vectorize a nested simd function call
marcin.krotkiewski at gmail dot com
gcc-bugzilla@gcc.gnu.org
Thu Apr 5 14:03:00 GMT 2018
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85232
Bug ID: 85232
Summary: gcc fails to vectorize a nested simd function call
Product: gcc
Version: 8.0.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: marcin.krotkiewski at gmail dot com
Target Milestone: ---
I'm compiling the following code using gcc version 8.0.1 20180319
(experimental) (also earlier versions), with flags "-march=haswell -O3
-ftree-vectorize -fopt-info-vec -ffast-math -fopenmp":
#pragma omp declare simd notinbranch
double fun1(double arg) __attribute__ ((noinline));
// double fun1(double arg)
// {
// return 2.0*arg;
// }
#pragma omp declare simd notinbranch
// double fun2(double arg) __attribute__ ((noinline));
double fun2(double arg)
{
// if statement is the cause of trouble
if(arg < 0) return 0.;
return 2.0*arg;
}
#pragma omp declare simd notinbranch
double test(double arg)
{
double H = 0;
H = 0;
H += fun1(arg);
H += fun2(arg);
return H;
}
Also here: https://godbolt.org/g/ZJmVzJ
Function test calls two other omp simd vectorized functions. fun1 is declared
here, and should be defined in a different compilation unit. fun2 is defined
here, should be inline'd, and contains an if statement on the argument.
As implemented above, gcc does not vectorize the function call to fun1. There
is a few things I have to do to arrive at a vectorized call:
1. move the definition of fun1 to the same compilation unit (uncomment in the
code above). fun1 is still noinline, so it will not be inline'd and a correct
vectorized call is issued
2. declare fun2 with attribute noinline. Then both fun1 and fun2 calls are
vectorized, but fun2 is not inlined.
The source of all trouble seems to be the if statement in fun2: if I remove it,
all works as expected.
What is the reason of this behaviour? Can I do something to avoid the problem?
I would like fun1 to be defined elsewhere, and fun2 to be inlined.
More information about the Gcc-bugs
mailing list