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

            Bug ID: 117790
           Summary: Early break vectorization corrupts profile info
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: acoplan at gcc dot gnu.org
  Target Milestone: ---

For the following loop (testcase modified from gcc.dg/tree-ssa/cunroll-14.c):

$ cat t.c
int a[100];
void f()
{
  for (int i = 0; i < 100 && a[i]; i++)
    a[i]++;
}

we vectorize it, but also mess up the profile information in the process:

$ ./xgcc -B . -c t.c -S -o /dev/null -O3 -fdump-tree-ifcvt-blocks-details=- |
grep -B 1 "Invalid sum"
$ ./xgcc -B . -c t.c -S -o /dev/null -O3 -fdump-tree-vect-blocks-details=- |
grep -B 1 "Invalid sum"
;;   basic block 4, loop depth 0, count 69202662 (estimated locally, freq
1.0000), maybe hot
;;   Invalid sum of incoming counts 83168663 (estimated locally, freq 1.2018),
should be 69202662 (estimated locally, freq 1.0000)
--
;;   basic block 8, loop depth 0, count 69202658 (estimated locally, freq
1.0000), maybe hot
;;   Invalid sum of incoming counts 10737420 (estimated locally, freq 0.1552),
should be 69202658 (estimated locally, freq 1.0000)
--
;;   basic block 9, loop depth 1, count 214528238 (estimated locally, freq
3.1000), maybe hot
;;   Invalid sum of incoming counts 259027474 (estimated locally, freq 3.7430),
should be 214528238 (estimated locally, freq 3.1000)

I'm working on fixing this as the alignment peeling patches enable more early
break vect and thus expose this issue more.

One problem is that scale_loop_profile doesn't work for multiple exits (I have
a fix for that), but there are missing profile updates (for early break) in the
vectorizer's peeling code too.

Reply via email to