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

--- Comment #3 from Jiu Fu Guo <guojiufu at gcc dot gnu.org> ---
(In reply to Jiu Fu Guo from comment #0)
> In match.pd there is a pattern:
> /* ((T)(A)) + CST -> (T)(A + CST)  */
> #if GIMPLE
>   (simplify
>    (plus (convert:s SSA_NAME@0) INTEGER_CST@1)
>     (if (TREE_CODE (TREE_TYPE (@0)) == INTEGER_TYPE
>          && TREE_CODE (type) == INTEGER_TYPE
>          && TYPE_PRECISION (type) > TYPE_PRECISION (TREE_TYPE (@0))
>          && int_fits_type_p (@1, TREE_TYPE (@0)))
>      /* Perform binary operation inside the cast if the constant fits
>         and (A + CST)'s range does not overflow.  *
> 
> But this pattern seems not in favor of all targets. 
> For example, the below code hits this pattern, 
> 
> long foo1 (int x)
> {
>   if (x>1000)
>     return 0;
>   int x1 = x +1;
>   return (long) x1 + 40;                                                    
> 
> }

For this code, without the pattern "((T)(A)) + CST -> (T)(A + CST)",
the final gimple code is:
  x1_4 = x_3(D) + 1;
  _1 = (long int) x1_4;
  _5 = _1 + 40;

With the pattern,
the final gimple code is:
  _4 = x_2(D) + 41;
  _3 = (long int) _4;

So, this pattern would be "reasonable".

Reply via email to