[Bug tree-optimization/110931] [14 Regression] Dead Code Elimination Regression since r14-2890-gcc2003cd875

2024-03-08 Thread law at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110931

--- Comment #5 from Jeffrey A. Law  ---
One could also look at this as a failure to propagate.

  l.0_1 = l;
  t_4 = (short int) l.0_1;
  if (t_4 == 0)
goto ; [50.00%]
  else
goto ; [50.00%]


We ought to be able to propagate l.0_1 into the conditional for t_4.  If we do
that, then we'll be able to propagate 0 for l.0_1 in this block:

;;   basic block 3, loop depth 0, count 536870912 (estimated locally, freq
0.5000)
;;prev block 2, next block 4, flags: (NEW, VISITED)
;;pred:   2 [50.0% (guessed)]  count:536870912 (estimated locally, freq
0.5000) (TRUE_VALUE,EXECUTABLE)
  b_5 = (char) l.0_1;
  if (b_5 != 1)
goto ; [0.00%]
  else
goto ; [100.00%]


And once we propagate the value 0 that will make the make bb5 (containing the
call to foo) unreachable.

IIRC we have (had?) some code to do these kinds of propagations through
conversions.  IIRC it was fairly conservative, perhaps overly so.

[Bug tree-optimization/110931] [14 Regression] Dead Code Elimination Regression since r14-2890-gcc2003cd875

2024-03-07 Thread law at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110931

Jeffrey A. Law  changed:

   What|Removed |Added

 CC||law at gcc dot gnu.org
   Priority|P3  |P2

[Bug tree-optimization/110931] [14 Regression] Dead Code Elimination Regression since r14-2890-gcc2003cd875

2023-08-08 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110931

Andrew Pinski  changed:

   What|Removed |Added

 Blocks||85316

--- Comment #4 from Andrew Pinski  ---
(In reply to Andrew Pinski from comment #2)
> Basically there is a missing VRP happening here:
> l.0_1 [irange] int [-INF, -65536][0, 0][65536, +INF]
> Partial equiv (b_6 pe8 l.0_1)
>  :
> b_6 = (char) l.0_1;
> ...
> Obvious that b_6 will have the range [0,0] as the other parts of l.0_1 is
> outside of that range. But for some reason VRP didn't figure that out here
> ...

Oh it looks like we don't prop NONZERO back and I missed that when I first
looked at this.

In this case we have:
l&(short)(-1) == 0

But we don't record that in the above, only a range ...


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85316
[Bug 85316] [meta-bug] VRP range propagation missed cases

[Bug tree-optimization/110931] [14 Regression] Dead Code Elimination Regression since r14-2890-gcc2003cd875

2023-08-07 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110931

--- Comment #3 from Andrew Pinski  ---
Here is one that has always failed due to a similar issue where the inner cast
was removed:
```
void foo(void);
int l=1000;

int main(void)
{
  short t = l;
  int t1 = t;
  if (t1 == 0) {
signed char b = t1;
if (b != 1) __builtin_unreachable();
foo();
  }
}
```

[Bug tree-optimization/110931] [14 Regression] Dead Code Elimination Regression since r14-2890-gcc2003cd875

2023-08-07 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110931

--- Comment #2 from Andrew Pinski  ---
Basically there is a missing VRP happening here:
l.0_1   [irange] int [-INF, -65536][0, 0][65536, +INF]
Partial equiv (b_6 pe8 l.0_1)
 :
b_6 = (char) l.0_1;
...
Obvious that b_6 will have the range [0,0] as the other parts of l.0_1 is
outside of that range. But for some reason VRP didn't figure that out here ...

I don't understand how this is supposed to work

[Bug tree-optimization/110931] [14 Regression] Dead Code Elimination Regression since r14-2890-gcc2003cd875

2023-08-07 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110931

Andrew Pinski  changed:

   What|Removed |Added

 Status|UNCONFIRMED |NEW
   Last reconfirmed||2023-08-07
 Ever confirmed|0   |1

--- Comment #1 from Andrew Pinski  ---
Reduced testcase:
```
void foo(void);
int l=1000;

int main(void)
{
  short t = l;
  unsigned t1 = t;
  if (t1 == 0) {
#if 1
char b = t1;
#else
char b = l;
#endif
if (b != 1) __builtin_unreachable();
foo();
  }
}
```

Changing 1 to 0 in the #if, shows the missed optimization too.

[Bug tree-optimization/110931] [14 Regression] Dead Code Elimination Regression since r14-2890-gcc2003cd875

2023-08-07 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110931

Andrew Pinski  changed:

   What|Removed |Added

   Keywords||missed-optimization
   Target Milestone|--- |14.0