On Thu, 19 Apr 2018, Jakub Jelinek wrote:

> Hi!
> 
> As mentioned in the PR, this optimization can't work if @0's precision
> is higher than @1's precision, because originally it compares just some set
> of lower bits, but in the new comparison compares all bits.
> If @0's precision is smaller than @1's precision (in this case @0 can't be
> a pointer, as we disallow such direct casts), then in theory it can be
> handled, but will not match what the comment says and we'd need to verify
> that the @1 constant can be represented in the @0's precision.
> 
> This patch just verifies the precision is the same and does small formatting
> cleanup.  Bootstrapped/regtested on x86_64-linux and i686-linux, ok for
> trunk?

OK.

Richard.

> 2018-04-18  Jakub Jelinek  <ja...@redhat.com>
> 
>       PR tree-optimization/85446
>       * match.pd ((intptr_t) x eq/ne CST to x eq/ne (typeof x) cst): Require
>       the integral and pointer types to have the same precision.
> 
> --- gcc/match.pd.jj   2018-04-09 20:15:49.158631652 +0200
> +++ gcc/match.pd      2018-04-18 09:55:47.176343913 +0200
> @@ -3711,10 +3711,13 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
>  (for cmp (ne eq)
>   (simplify
>    (cmp (convert @0) INTEGER_CST@1)
> -  (if ((POINTER_TYPE_P (TREE_TYPE (@0)) && !FUNC_OR_METHOD_TYPE_P (TREE_TYPE 
> (TREE_TYPE (@0)))
> -     && INTEGRAL_TYPE_P (TREE_TYPE (@1)))
> -      || (INTEGRAL_TYPE_P (TREE_TYPE (@0)) && POINTER_TYPE_P (TREE_TYPE (@1))
> -       && !FUNC_OR_METHOD_TYPE_P (TREE_TYPE (TREE_TYPE (@1)))))
> +  (if (((POINTER_TYPE_P (TREE_TYPE (@0))
> +      && !FUNC_OR_METHOD_TYPE_P (TREE_TYPE (TREE_TYPE (@0)))
> +      && INTEGRAL_TYPE_P (TREE_TYPE (@1)))
> +     || (INTEGRAL_TYPE_P (TREE_TYPE (@0))
> +         && POINTER_TYPE_P (TREE_TYPE (@1))
> +         && !FUNC_OR_METHOD_TYPE_P (TREE_TYPE (TREE_TYPE (@1)))))
> +       && TYPE_PRECISION (TREE_TYPE (@0)) == TYPE_PRECISION (TREE_TYPE (@1)))
>     (cmp @0 (convert @1)))))
>  
>  /* Non-equality compare simplifications from fold_binary  */
> 
>       Jakub
> 
> 

-- 
Richard Biener <rguent...@suse.de>
SUSE LINUX GmbH, GF: Felix Imendoerffer, Jane Smithard, Graham Norton, HRB 
21284 (AG Nuernberg)

Reply via email to