public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/105053] New: Wrong loop count for scalar code from vectorizer
@ 2022-03-25 10:51 glisse at gcc dot gnu.org
  2022-03-25 11:28 ` [Bug tree-optimization/105053] " rguenth at gcc dot gnu.org
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: glisse at gcc dot gnu.org @ 2022-03-25 10:51 UTC (permalink / raw)
  To: gcc-bugs

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.

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2022-04-07  9:55 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-25 10:51 [Bug tree-optimization/105053] New: Wrong loop count for scalar code from vectorizer glisse at gcc dot gnu.org
2022-03-25 11:28 ` [Bug tree-optimization/105053] " rguenth at gcc dot gnu.org
2022-03-25 11:31 ` rguenth at gcc dot gnu.org
2022-03-25 12:29 ` rguenth at gcc dot gnu.org
2022-03-25 12:48 ` rguenth at gcc dot gnu.org
2022-03-25 13:29 ` rguenth at gcc dot gnu.org
2022-03-25 14:26 ` cvs-commit at gcc dot gnu.org
2022-03-25 14:27 ` rguenth at gcc dot gnu.org
2022-03-25 16:33 ` glisse at gcc dot gnu.org
2022-03-25 16:37 ` marxin at gcc dot gnu.org
2022-03-28  6:32 ` [Bug tree-optimization/105053] [11 Regression] " rguenth at gcc dot gnu.org
2022-04-07  9:53 ` cvs-commit at gcc dot gnu.org
2022-04-07  9:55 ` rguenth at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).