https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82703
Bug ID: 82703 Summary: Wrong addition of std::array components with -O2 -ftree-loop-vectorize -ftree-slp-vectorize (works fine with -O2) Product: gcc Version: 7.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: frederic.bron at m4x dot org Target Milestone: --- Created attachment 42463 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=42463&action=edit Minimal example to reproduce the bug The small program attached to this message should always pass, i.e. not print any error. This is the case with -O2. This is also the case with clang++ 4.0.1 with -O3. However with g++ and "-O2 -ftree-loop-vectorize -ftree-slp-vectorize", v3[1] is 2.0 instead of 4.0. Note that if I change double to int, long, long long, float or long double, I have no error. Also if I do not construct Array from int[3] but from double[3], it works and if I remove a useless line, it works... Tested on linux Fedora 26 x86_64 with g++ 7.2.0 and 7.2.1 on westmere, broadwell, skylake. To reproduce failure: g++ -O2 -g -std=c++14 bug.cpp -ftree-loop-vectorize -ftree-slp-vectorize && ./a.out g++ 7.2.0 that shows the bug: Using built-in specs. COLLECT_GCC=g++-7.2.0 COLLECT_LTO_WRAPPER=/softs/gcc-7.2.0/libexec/gcc/x86_64-pc-linux-gnu/7.2.0/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: /softs/build/gcc-7.2.0/configure --prefix=/softs/gcc-7.2.0 --program-suffix=-7.2.0 --with-gmp-include=/softs/gmp-6.1.2/include --with-gmp-lib=/softs/gmp-6.1.2/lib --with-mpfr-include=/softs/mpfr-3.1.5/include --with-mpfr-lib=/softs/mpfr-3.1.5/lib --with-mpc-include=/softs/mpc-1.0.3/include --with-mpc-lib=/softs/mpc-1.0.3/lib --with-isl-include=/softs/isl-0.16.1/include --with-isl-lib=/softs/isl-0.16.1/lib --disable-isl-version-check --enable-lto --enable-nls --disable-multilib Thread model: posix gcc version 7.2.0 (GCC) g++ 7.2.1 that shows the bug: Using built-in specs. COLLECT_GCC=g++ COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/7/lto-wrapper OFFLOAD_TARGET_NAMES=nvptx-none OFFLOAD_TARGET_DEFAULT=1 Target: x86_64-redhat-linux Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,objc,obj-c++,fortran,ada,go,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl --enable-libmpx --enable-offload-targets=nvptx-none --without-cuda-driver --enable-gnu-indirect-function --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux Thread model: posix gcc version 7.2.1 20170915 (Red Hat 7.2.1-2) (GCC)