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

            Bug ID: 117252
           Summary: SLSR does not always handle mem_refs
           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
  Target Milestone: ---

Take:
```
/* { dg-do compile } */
/* { dg-options "-O2 -fdump-tree-dom3" } */

struct x
{
  int a[16];
  int b[16];
  int c[16];
};

extern void foo (int, int, int);


void
f1 (int *p, __SIZE_TYPE__ n)
{
  foo (p[n], p[16+n], p[n+2*16]);
}

/* { dg-final { scan-tree-dump-times "\\* 4;" 1 "dom3" { target { int32 } } } }
*/
/* { dg-final { scan-tree-dump-times "\\* 2;" 1 "dom3" { target { int16 } } } }
*/
/* { dg-final { scan-tree-dump-times "p_\\d\+\\(D\\) \\+ \[^\r\n\]*_\\d\+;" 1
"dom3" } } */
/*
  { dg-final { scan-tree-dump-times "MEM *<int>? *\\\[\\(struct x
\\*\\)\[^\r\n\]*_\\d\+" 3 "dom3" } } */

```

Currently SLSR produces:
```
  _1 = n_12(D) * 4;
  _2 = p_13(D) + _1;
  _3 = *_2;
  _5 = _1 + 64;
  _6 = p_13(D) + _5;
  _7 = *_6;
  _9 = _5 + 64;
  _10 = p_13(D) + _9;
  _11 = *_10;
  foo (_3, _7, _11);
```

Which is good that is able to remove the multiple n*4 but it does not remove
the redundant `p + _1 ` (which is removed on the rtl level later on).

Note this is a reduced testcase from gcc.dg/tree-ssa/slsr-27.c if we expand out
the array reference early.

Reply via email to