This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Improve folding of COND_EXPRs in tree-if-conv.c (PR tree-optimization/70916)


On Tue, 3 May 2016, Jakub Jelinek wrote:

> Hi!
> 
> This allows us to better fold the COND_EXPR, so that _1 = 1 ? &foo : _2;
> is folded to _1 = &foo.  There is another bug, the 1 in this case is wrong,
> but it could appear on some other code too.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

Ok.

Thanks,
Richard.

> 2016-05-03  Jakub Jelinek  <jakub@redhat.com>
> 
> 	PR tree-optimization/70916
> 	* tree-if-conv.c (constant_or_ssa_name): Removed.
> 	(fold_build_cond_expr): Use is_gimple_val instead of
> 	constant_or_ssa_name.
> 
> --- gcc/tree-if-conv.c.jj	2016-04-26 18:03:15.850034179 +0200
> +++ gcc/tree-if-conv.c	2016-05-03 11:04:19.378939463 +0200
> @@ -408,24 +408,6 @@ fold_or_predicates (location_t loc, tree
>    return fold_build2_loc (loc, TRUTH_OR_EXPR, boolean_type_node, c1, c2);
>  }
>  
> -/* Returns true if N is either a constant or a SSA_NAME.  */
> -
> -static bool
> -constant_or_ssa_name (tree n)
> -{
> -  switch (TREE_CODE (n))
> -    {
> -      case SSA_NAME:
> -      case INTEGER_CST:
> -      case REAL_CST:
> -      case COMPLEX_CST:
> -      case VECTOR_CST:
> -	return true;
> -      default:
> -	return false;
> -    }
> -}
> -
>  /* Returns either a COND_EXPR or the folded expression if the folded
>     expression is a MIN_EXPR, a MAX_EXPR, an ABS_EXPR,
>     a constant or a SSA_NAME. */
> @@ -446,22 +428,21 @@ fold_build_cond_expr (tree type, tree co
>  	  && (integer_zerop (op1)))
>  	cond = op0;
>      }
> -  cond_expr = fold_ternary (COND_EXPR, type, cond,
> -			    rhs, lhs);
> +  cond_expr = fold_ternary (COND_EXPR, type, cond, rhs, lhs);
>  
>    if (cond_expr == NULL_TREE)
>      return build3 (COND_EXPR, type, cond, rhs, lhs);
>  
>    STRIP_USELESS_TYPE_CONVERSION (cond_expr);
>  
> -  if (constant_or_ssa_name (cond_expr))
> +  if (is_gimple_val (cond_expr))
>      return cond_expr;
>  
>    if (TREE_CODE (cond_expr) == ABS_EXPR)
>      {
>        rhs1 = TREE_OPERAND (cond_expr, 1);
>        STRIP_USELESS_TYPE_CONVERSION (rhs1);
> -      if (constant_or_ssa_name (rhs1))
> +      if (is_gimple_val (rhs1))
>  	return build1 (ABS_EXPR, type, rhs1);
>      }
>  
> @@ -472,8 +453,7 @@ fold_build_cond_expr (tree type, tree co
>        STRIP_USELESS_TYPE_CONVERSION (lhs1);
>        rhs1 = TREE_OPERAND (cond_expr, 1);
>        STRIP_USELESS_TYPE_CONVERSION (rhs1);
> -      if (constant_or_ssa_name (rhs1)
> -	  && constant_or_ssa_name (lhs1))
> +      if (is_gimple_val (rhs1) && is_gimple_val (lhs1))
>  	return build2 (TREE_CODE (cond_expr), type, lhs1, rhs1);
>      }
>    return build3 (COND_EXPR, type, cond, rhs, lhs);
> 
> 	Jakub
> 
> 

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]