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] Assign result of get_string_lenth to a SSA_NAME (PR tree-optimization/83552).


On Fri, Dec 22, 2017 at 04:18:05PM +0100, Martin Liška wrote:
> In order to fix the PR, I save temporary expression to a SSA_NAME that
> is then used in the gcall.

You need to do that only if (!is_gimple_val (arg1_len)).
Can you please emit the additional stmt only if that isn't true?

> --- a/gcc/tree-ssa-strlen.c
> +++ b/gcc/tree-ssa-strlen.c
> @@ -3005,12 +3005,17 @@ fold_strstr_to_strncmp (tree rhs1, tree rhs2, gimple *stmt)
>  	    {
>  	      gimple_stmt_iterator gsi = gsi_for_stmt (call_stmt);
>  	      tree strncmp_decl = builtin_decl_explicit (BUILT_IN_STRNCMP);
> +
> +	      tree arg1_len_tmp = make_ssa_name (TREE_TYPE (arg1_len));
> +	      gassign *arg1_stmt = gimple_build_assign (arg1_len_tmp, arg1_len);
>  	      gcall *strncmp_call = gimple_build_call (strncmp_decl, 3,
> -						      arg0, arg1, arg1_len);
> +						      arg0, arg1,
> +						      arg1_len_tmp);
>  	      tree strncmp_lhs = make_ssa_name (integer_type_node);
>  	      gimple_set_vuse (strncmp_call, gimple_vuse (call_stmt));
>  	      gimple_call_set_lhs (strncmp_call, strncmp_lhs);
>  	      gsi_remove (&gsi, true);
> +	      gsi_insert_before (&gsi, arg1_stmt, GSI_SAME_STMT);
>  	      gsi_insert_before (&gsi, strncmp_call, GSI_SAME_STMT);
>  	      tree zero = build_zero_cst (TREE_TYPE (strncmp_lhs));
>  
> 


	Jakub


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