On Mon, Nov 07, 2016 at 01:17:25PM +0100, Richard Biener wrote:
> 
> The following fixes phiopt to not introduce undefined behavior
> in its abs replacement code in case we negate only positive values
> in the original code.
> 
> Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk.
> 
> Richard.
> 
> 2016-11-07  Richard Biener  <rguent...@suse.de>
> 
>       PR tree-optimization/78228
>       * tree-ssa-phiopt.c (abs_replacement): Avoid introducing
>       undefined behavior.
> 
>       * gcc.dg/tree-ssa/phi-opt-15.c: New testcase.
> 
> Index: gcc/tree-ssa-phiopt.c
> ===================================================================
> --- gcc/tree-ssa-phiopt.c     (revision 241891)
> +++ gcc/tree-ssa-phiopt.c     (working copy)
> @@ -1453,6 +1453,14 @@ abs_replacement (basic_block cond_bb, ba
>    else
>      negate = false;
>  
> +  /* If the code negates only iff positive then make sure to not
> +     introduce undefined behavior when negating or computing the absolute.
> +     ???  We could use range info if present to check for arg1 == INT_MIN.  
> */

Perhaps just

> +  if (negate
> +      && (ANY_INTEGRAL_TYPE_P (TREE_TYPE (arg1))
> +       && ! TYPE_OVERFLOW_WRAPS (TREE_TYPE (arg1))))
    {
      wide_int minv = TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (arg1)));
      if (!expr_not_equal_to (arg1, minv))
        return false;
    }
?

        Jakub

Reply via email to