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

            Bug ID: 117414
           Summary: missing predicated VN due to combining if statements
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pinskia at gcc dot gnu.org
  Target Milestone: ---

Take the following two functions:
```
void foo();
int f(int *aaa, int j, int t)
{
  int b = *aaa;
  if (b == 0 || t == 1)
    return 0;
  for(int i = 0; i < j; i++)
  {
    if (!*aaa) foo();
  }
}

void foo();
int f1(int *aaa, int j, int t)
{
  int b = *aaa;
  if (b == 0)
    return 0;
  if (t == 1)
    return 0;
  for(int i = 0; i < j; i++)
  {
    if (!*aaa) foo();
  }
}
```

They should produce the same code but currently does not. The second one works
as predicated VN is able to see that `!*aaa` is never true. While the second
does not.

The combining of the if statements loses information for the predication about
*aaa.

This is what is causing gcc.dg/tree-ssa/pr111456-1.c to fail after allowing for
slightly more ifcombine as the predicated fre (handled during pre in that case)
is not happening any more. I suspect this was the original missed optimization,
I just worked around it by optimizing `a == 0 & ((short)a) >= 0` into `a == 0`
which then gets the predication as needed and it is also why
`--param=logical-op-non-short-circuit=0` worked originally too.

Reply via email to