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

            Bug ID: 111459
           Summary: DSE after deleting trivial dead statements sometimes
                    should do a cfgcleanup
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Keywords: internal-improvement
          Severity: enhancement
          Priority: P3
         Component: tree-optimization
          Assignee: pinskia at gcc dot gnu.org
          Reporter: pinskia at gcc dot gnu.org
  Target Milestone: ---

Take at -O1:
```
void foo(void);
static int i;
static int *j = &i;
static char l;
static void(a)(char) {}
static short(b)(short c, short d) { return c - d; }
static short(e)(short f, int g) {
    return f < 0 || g < 0 || g >= 32 ? f : f >> g;
}
static short(h)(short f, int g) { return g >= 2 ?: f >> g; }
static char k(char m, short n) {
    short o;
    int *p = &i;
    if (!(((m) >= 1) && ((m) <= 1))) {
        __builtin_unreachable();
    }
    o = e(i, i);
    if (h(1, o))
        ;
    else {
        m = 0;
        for (; m >= -20; m = b(m, 9))
            if (a(i), n) {
                if (*p)
                    ;
                else
                    foo();
                ;
            } else
                return l;
    }
    return i;
}
int main() { k(0 <= 0 > *j, i); }
```

In dse5 we delete trivial dead statements for _30 and _31 below:
  _16 = (int) _2;
  if (_16 > 1)
    goto <bb 7>; [78.67%]
  else
    goto <bb 6>; [21.33%]

  <bb 6> [local count: 536870912]:
  _30 = 1 >> _16;
  iftmp.7_31 = (short int) _30;

  <bb 7> [local count: 1073741829]:

But we should recongize that the bb 6 becomes empty and we should add
TODO_cleanup_cfg to the todos like dse already does for removing trivial dead
phis:
      if (removed_phi && gimple_seq_empty_p (phi_nodes (bb)))
        todo |= TODO_cleanup_cfg;

I am filing this to record what I found so I can work on it later this week.

Reply via email to