[Bug c++/61252] New: Invalid code produced for omp simd reduction(min:var) where var is reference

2014-05-20 Thread hazeman11 at gmail dot com
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;
}
--


[Bug c++/61252] Invalid code produced for omp simd reduction(min:var) where var is reference

2014-05-20 Thread hazeman11 at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61252

--- Comment #2 from hazeman11 at gmail dot com ---
Yep sorry for so stupid example. I've reduced it to bare minimum without
looking whether it does make sense. Ofcourse something like

maxstep = std::min(std::min(a0[i],a1[i]),maxstep);

would make much more sense. Inside of my original loop ( where i've spotted the
problem ) was much much larger.


[Bug c++/61252] Invalid code produced for omp simd reduction(min:var) where var is reference

2014-05-20 Thread hazeman11 at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61252

--- Comment #3 from hazeman11 at gmail dot com ---
Created attachment 32827
  -- https://gcc.gnu.org/bugzilla/attachment.cgi?id=32827action=edit
corrected minimal example