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

            Bug ID: 115277
           Summary: ICF needs to match loop bound estimates
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: hubicka at gcc dot gnu.org
  Target Milestone: ---

jan@localhost:/tmp> cat tt.c
int array[1000];
void
test (int a)
{
        if (__builtin_expect (a > 3, 1))
                return;
        for (int i = 0; i < a; i++)
                array[i]=i;
}
void
test2 (int a)
{
        if (__builtin_expect (a > 10, 1))
                return;
        for (int i = 0; i < a; i++)
                array[i]=i;
}
int
main()
{
        test(1);
        test(2);
        test(3);
        test2(10);
        if (array[9] != 9)
                __builtin_abort ();
        return 0;
}
jan@localhost:/tmp> gcc -O2 tt.c ; ./a.out
jan@localhost:/tmp> gcc -O3 tt.c ; ./a.out
Aborted (core dumped)


The problem here is that we do not match value ranges and thus we can end up
with different estimates on number of iterations.

Reply via email to