[Bug tree-optimization/105053] New: Wrong loop count for scalar code from vectorizer

glisse at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Fri Mar 25 10:51:20 GMT 2022


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105053

            Bug ID: 105053
           Summary: Wrong loop count for scalar code from vectorizer
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: glisse at gcc dot gnu.org
  Target Milestone: ---

#include <vector>
#include <tuple>
#include <algorithm>
#include <random>
#include <iostream>

int main(){
  const long n = 100000000;
  std::vector<std::tuple<int,int,double>> vec;
  vec.reserve(n);
  std::random_device rd;
  std::default_random_engine re(rd());
  std::uniform_int_distribution<int> rand_int;
  std::uniform_real_distribution<double> rand_dbl;
  for(int i=0;i<n;++i)
    vec.emplace_back(rand_int(re), rand_int(re), rand_dbl(re));
  {
    int sup = 0;
    for(int i=0;i<n;++i)
sup=std::max(sup,std::max(std::get<0>(vec[i]),std::get<1>(vec[i])));
    std::cout << sup << '\n';
  }
  {
    int sup = 0;
    for(int i=0;i<n;++i)
sup=std::max(std::max(sup,std::get<0>(vec[i])),std::get<1>(vec[i]));
    std::cout << sup << '\n';
  }
}

Can output for instance
2147483645
2147483637
compiled with -O3, whereas the 2 numbers should be the same.

If I compare what I get from the first loop with -O3 -fno-tree-loop-vectorize
to the second loop with just -O3, the code is almost identical, except that the
(scalar) code only iterates on 1/4 of the array, as if it was using a bound
meant for a vector. -fno-tree-loop-vectorize seems to be ok.


More information about the Gcc-bugs mailing list