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

--- Comment #43 from Andrew Macleod <amacleod at redhat dot com> ---
(In reply to Jakub Jelinek from comment #42)
> On #c0 foo, this was previously optimized in dom2 which optimized
>   _4 = ABS_EXPR <x_2(D)>;
>   _3 = _4 u> 1.79769313486231570814527423731704356798070567525844996599e+308;
>   _5 = ~_3;
>   if (_4 u> 1.79769313486231570814527423731704356798070567525844996599e+308)
>     goto <bb 3>; [0.00%]
>   else
>     goto <bb 4>; [100.00%]
> 
>   <bb 3> [count: 0]:
>   __builtin_unreachable ();
> 
>   <bb 4> [local count: 1073741824]:
>   return _5;
> without any frange related stuff as:
> -  if (_4 u> 1.79769313486231570814527423731704356798070567525844996599e+308)
> +  if (_3 != 0)
> and
> -  return _5;
> +  return 1;
> 
> But because __builtin_unreachable () is now removed earlier (vrp1 already;
> without providing useful global range though), we don't do that anymore.

Hmm. its because when vrp1 removes the branch to builtin_unreachable, it
calculates the global range of _4 as the union of all the ranges at each use..
this is to avoid issues where the unreachable call may not post-dominate an
earlier use.

THe initial use of _4 still is resolved to only [0, max] so we end up only
using that for the range.

Im experimenting with doing things the same way, except NOT removing the branch
in VRP, but continuing to set the global range the way we do.  I might also be
able to revisit the branch *after* all the globals have been set, and see if
the globals values now cause the condition to fold, and if they do, remove them
only  then...  

ThIs would leave the above case for DOM2 (or someone else to resolve).   It
seems like it might be a reasonable balance...  ie, we only remove the
unreachable in VRP1 if we can determine with 100% positivity that setting the
global value will result in the branch being able to remove.

Its also possible it could also just be left... and another pass should remove
it shortly as it folds away...  and certainly by VRP2 time...   

Anyway, I'll try it a few ways and see what seems to work best.

Reply via email to