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

--- Comment #9 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #8)
> Note the loop one looks like:
>   if (input_4(D) != 0)
>     goto <bb 3>; [89.00%]
>   else
>     goto <bb 4>; [11.00%]
> 
>   <bb 3> [local count: 105119324]:
>   _1 = (unsigned int) input_4(D);
>   _3 = -_1;
>   value_2 = (int) _3;
> 
>   <bb 4> [local count: 118111600]:
>   # value_10 = PHI <value_2(3), 0(2)>
> 
> ---- CUT ----
> Which avoids undefined overflow for INT_MIN.

After r14-4889-g0fc13e8c0e39c5 in phiopt we have:
```
  <bb 2> [local count: 118111600]:
  if (input_3(D) != 0)
    goto <bb 3>; [89.00%]
  else
    goto <bb 4>; [11.00%]

  <bb 3> [local count: 105119324]:
  _1 = (unsigned int) input_3(D);
  _7 = -_1;

  <bb 4> [local count: 118111600]:
  # _11 = PHI <_7(3), 0(2)>
```

There are 2 ways of handling this. First is to handle the TODO in
factor_out_conditional_operation:
      /* TODO: handle more than just casts here. */

Which help others. So I think I am going to implement that way.
Once we handle that we will end up with `input_3 != 0 ? input_3 : 0` which then
will then reduce down to just input_3.

So the operations that should be simple to handle are NEGATIVE_EXPR, ABS_EXPR
and ABSU_EXPR. If we only handle those for 0, it should be the safest form. And
could be expanded later on for other values.

Reply via email to