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

            Bug ID: 116553
           Summary: slsr does not understand `a+PHI<CST0,CST1>` only
                    `PHI<a + CST0,a+CST1>`
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: enhancement
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pinskia at gcc dot gnu.org
            Blocks: 64700
  Target Milestone: ---

Take (extracted from gcc.dg/tree-ssa/slsr-34.c ):
```
extern void
g (void);

int
f (int c, int i)
{
  int a1, a2, a3, x1, x2, x3, x;

  a1 = i * 16;
  x1 = c + a1;

  i = i + 2;
  a2 = i * 16;
  x2 = c + a2;

  if (x2 > 6)
    {
      if (c < 200)
        i = i + 2;
      else
        i = i + 4;
      g ();
    }
  else
    i = i + 6;

  i = i + 2;
  a3 = i * 16;
  x3 = c + a3;

  x = x1 + x2 + x3;
  return x;
}


int
f1 (int c, int i)
{
  int a1, a2, a3, x1, x2, x3, x;

  a1 = i * 16;
  x1 = c + a1;

  i = i + 2;
  a2 = i * 16;
  x2 = c + a2;

  if (x2 > 6)
    {
      int t;
      if (c < 200)
        t = 2;
      else
        t = 4;
      i = i + t;
      g ();
    }
  else
    i = i + 6;

  i = i + 2;
  a3 = i * 16;
  x3 = c + a3;

  x = x1 + x2 + x3;
  return x;
}

```

slsr is able to handle f but not f1. But both are semantically the same. 

I found this while fixing PR 64700.


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64700
[Bug 64700] Sink common code through PHI

Reply via email to