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

--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #5)
> So i have a patch for cfgcleanup but it causes a regression which looks like
> a fake one. I will finish it up later today. Dceing more definitely will
> improve compile time and will improve other passes.

gcc.dg/tree-ssa/pr68619-4.c is failing because we are able to remove an extra
if after dce3 after we had did some jump threading.

so we had:
```
if (x_21(D)->code == 39)
  if (x_21(D)->u.fld[0].rt_rtx->code == 37)
    {
...
    }
if (rtx_class[x_21(D)->code] == 37)
  if (x_21(D)->u.fld[0].rt_rtx->code == 37)
    foop();
```

Jump threading in DOM would turn this into:
```
if (x_21(D)->code == 39)
  if (x_21(D)->u.fld[0].rt_rtx->code == 37)
    {
      ...
    }
  else
    goto newbb;
if (rtx_class[x_21(D)->code] == 37)
  if (x_21(D)->u.fld[0].rt_rtx->code == 37)
    foop();
goto join;
newbb:
tmp = x_21(D)->code;
tmp2 = rtx_class[tmp]; 
if (tmp2 == 37)
  {
    x_21(D)->u.fld[0].rt_rtx->code;
  }
else goto join;

join:
```

So DCE4 remove the loads of `x_21(D)->u.fld[0].rt_rtx->code;` which is correct
and the cleanupcfg would come around and decide to remove condition for `tmp2
== 37`  which is fine.
But we are left with newbb which has dead code in it. The patch then is able to
now remove the stuff in newbb (correctly) and then since this is now just a
forwarder branch, we remove all of newbb fully and change the goto newbb into
join.

And we end up with:
```
if (x_21(D)->code == 39)  {
  if (x_21(D)->u.fld[0].rt_rtx->code == 37)
    {
      ...
    }
  else
    goto join;
}
if (rtx_class[x_21(D)->code] == 37)
  if (x_21(D)->u.fld[0].rt_rtx->code == 37)
    foop();
goto join;

join:
```

And now there is only one place which does the x_21(D)->code (which is casted
to int really), it does not get pre'd and there is no proping the 39 during
DOM3 any more.

I tried to see if there is a good way to resolve what was being tested but
adding an else to the bb that corresponds to the condition in front of foop
call; it works but then it seems like it not testing what it was originally
testing since GCC 5 works too where the other testcase failed in GCC 5.

So I am going to remove the testcase in the end (with a notice in the commit
log to see this comment).

Reply via email to