https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61252
Bug ID: 61252
Summary: Invalid code produced for omp simd reduction(min:var)
where var is reference
Product: gcc
Version: 4.9.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: hazeman11 at gmail dot com
Created attachment 32826
-- https://gcc.gnu.org/bugzilla/attachment.cgi?id=32826action=edit
minimal code with reduce_bad
Invalid code produced ( loop optimized out ) for case when reduction variable
is a reference. I've looked into OpenMP specification but didn't find
requirement for reduction variable to be local ( althought I didn't spend much
time on it :) ).
System: ubuntu 12.04 64bit
GCC -v
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-unknown-linux-gnu/4.9.1/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../configure --enable-checking=release
--enable-languages=c,c++ --enable-multiarch --disable-multilib --enable-shared
--enable-threads=posix --with-abi=m64 --program-suffix=-4.9 --with-gmp=/usr/lib
--with-mpc=/usr/lib --with-mpfr=/usr/lib --without-included-gettext
--with-system-zlib --with-tune=generic --prefix=/usr/local
Thread model: posix
gcc version 4.9.1 20140514 (prerelease) (GCC)
Compilation options:
g++ -fopenmp -O3 -g3 -ffast-math -Wall -ftree-vectorize -march=core-avx2 -c
test.cpp -o test.o
-- code --
void reduce_bad( int N, float* a0, float* a1, float maxstep )
{
#pragma omp simd reduction(min:maxstep)
for(int i=0;iN;i++) {
maxstep = std::min(a0[i],a1[i]);
}
}
---
and here is workaround for this bug
-- code --
void reduce_good( int N, float* a0, float* a1, float ret )
{
float maxstep = ret;
#pragma omp simd reduction(min:maxstep)
for(int i=0;iN;i++) {
maxstep = std::min(a0[i],a1[i]);
}
ret = maxstep;
}
--