[PATCH] Use integer_{zero,one}_node some more

Richard Biener rguenther@suse.de
Wed Mar 20 10:00:00 GMT 2024


On Wed, 20 Mar 2024, Jakub Jelinek wrote:

> Hi!
> 
> When looking at the analyzer MEM_REF invalid second arg issue, I've noticed
> tons of build_int_cst (integer_type_node, {0,1}) or build_zero_cst
> (integer_type_node) cases.
> That just wastes compile time (albeit not very much).
> 
> The following patch fixes what my sed script found.
> 
> Ok for trunk (or defer for stage1, though guess I'd need to redo it
> from scratch at that point)?

OK.

Richard.

> 2024-03-20  Jakub Jelinek  <jakub@redhat.com>
> 
> gcc/analyzer/
> 	* constraint-manager.cc (test_range, test_constraint_conditions,
> 	test_constant_comparisons, test_constraint_impl, test_purging,
> 	test_bits): Use integer_zero_node instead of
> 	build_zero_cst (integer_type_node) or
> 	build_int_cst (integer_type_node, 0) and integer_one_node instead of
> 	build_int_cst (integer_type_node, 1).
> 	* region-model.cc (region_model::get_store_value,
> 	append_interesting_constants, test_array_1,
> 	test_get_representative_tree, test_unique_constants, test_assignment,
> 	test_stack_frames, test_constraint_merging, test_widening_constraints,
> 	test_iteration_1, test_array_2): Likewise.
> gcc/cp/
> 	* coroutines.cc (expand_one_await_expression): Use
> 	integer_zero_node instead of build_int_cst (integer_type_node, 0)
> 	and integer_one_node instead of build_int_cst (integer_type_node, 1).
> gcc/fortran/
> 	* trans-array.cc (structure_alloc_comps): Use integer_zero_node
> 	instead of build_zero_cst (integer_type_node) or
> 	build_int_cst (integer_type_node, 0) and integer_one_node instead of
> 	build_int_cst (integer_type_node, 1).
> 	* trans-expr.cc (conv_scalar_char_value): Likewise.
> 	* trans-stmt.cc (gfc_trans_form_team, gfc_trans_change_team,
> 	gfc_trans_sync_team, gfc_trans_sync): Likewise.
> 	* trans-decl.cc (create_main_function): Likewise.
> 	* trans-intrinsic.cc (trans_this_image, conv_intrinsic_move_alloc):
> 	Likewise.
> 	* trans.cc (gfc_allocate_using_caf_lib, gfc_deallocate_with_status):
> 	Likewise.
> gcc/objc/
> 	* objc-next-runtime-abi-02.cc (build_v2_class_ro_t_initializer): Use
> 	integer_zero_node instead of build_int_cst (integer_type_node, 0).
> 
> --- gcc/cp/coroutines.cc.jj	2024-02-10 09:38:25.771984306 +0100
> +++ gcc/cp/coroutines.cc	2024-03-19 13:34:36.495989031 +0100
> @@ -1750,7 +1750,7 @@ expand_one_await_expression (tree *stmt,
>  				    data->coro_fp);
>    r = cp_build_init_expr (cond, r);
>    finish_switch_cond (r, sw);
> -  r = build_case_label (build_int_cst (integer_type_node, 0), NULL_TREE,
> +  r = build_case_label (integer_zero_node, NULL_TREE,
>  			create_anon_label_with_ctx (loc, actor));
>    add_stmt (r); /* case 0: */
>    /* Implement the suspend, a scope exit without clean ups.  */
> @@ -1758,7 +1758,7 @@ expand_one_await_expression (tree *stmt,
>  				    is_cont ? cont : susp);
>    r = coro_build_cvt_void_expr_stmt (r, loc);
>    add_stmt (r); /*   goto ret;  */
> -  r = build_case_label (build_int_cst (integer_type_node, 1), NULL_TREE,
> +  r = build_case_label (integer_one_node, NULL_TREE,
>  			create_anon_label_with_ctx (loc, actor));
>    add_stmt (r); /* case 1:  */
>    r = build1_loc (loc, GOTO_EXPR, void_type_node, resume_label);
> --- gcc/analyzer/constraint-manager.cc.jj	2024-02-27 16:52:23.725366127 +0100
> +++ gcc/analyzer/constraint-manager.cc	2024-03-19 13:34:36.486989157 +0100
> @@ -3374,8 +3374,8 @@ namespace selftest {
>  static void
>  test_range ()
>  {
> -  tree int_0 = build_int_cst (integer_type_node, 0);
> -  tree int_1 = build_int_cst (integer_type_node, 1);
> +  tree int_0 = integer_zero_node;
> +  tree int_1 = integer_one_node;
>    tree int_2 = build_int_cst (integer_type_node, 2);
>    tree int_5 = build_int_cst (integer_type_node, 5);
>  
> @@ -3419,7 +3419,7 @@ static void
>  test_constraint_conditions ()
>  {
>    tree int_42 = build_int_cst (integer_type_node, 42);
> -  tree int_0 = build_int_cst (integer_type_node, 0);
> +  tree int_0 = integer_zero_node;
>  
>    tree x = build_global_decl ("x", integer_type_node);
>    tree y = build_global_decl ("y", integer_type_node);
> @@ -3874,7 +3874,7 @@ test_transitivity ()
>  static void
>  test_constant_comparisons ()
>  {
> -  tree int_1 = build_int_cst (integer_type_node, 1);
> +  tree int_1 = integer_one_node;
>    tree int_3 = build_int_cst (integer_type_node, 3);
>    tree int_4 = build_int_cst (integer_type_node, 4);
>    tree int_5 = build_int_cst (integer_type_node, 5);
> @@ -4058,7 +4058,7 @@ static void
>  test_constraint_impl ()
>  {
>    tree int_42 = build_int_cst (integer_type_node, 42);
> -  tree int_0 = build_int_cst (integer_type_node, 0);
> +  tree int_0 = integer_zero_node;
>  
>    tree x = build_global_decl ("x", integer_type_node);
>    tree y = build_global_decl ("y", integer_type_node);
> @@ -4220,7 +4220,7 @@ test_many_constants ()
>  static void
>  test_purging (void)
>  {
> -  tree int_0 = build_int_cst (integer_type_node, 0);
> +  tree int_0 = integer_zero_node;
>    tree a = build_global_decl ("a", integer_type_node);
>    tree b = build_global_decl ("b", integer_type_node);
>  
> @@ -4654,7 +4654,7 @@ test_bits (void)
>  {
>    region_model_manager mgr;
>  
> -  tree int_0 = build_int_cst (integer_type_node, 0);
> +  tree int_0 = integer_zero_node;
>    tree int_0x80 = build_int_cst (integer_type_node, 0x80);
>    tree int_0xff = build_int_cst (integer_type_node, 0xff);
>    tree x = build_global_decl ("x", integer_type_node);
> --- gcc/analyzer/region-model.cc.jj	2024-03-19 13:24:49.302222817 +0100
> +++ gcc/analyzer/region-model.cc	2024-03-19 13:34:36.491989087 +0100
> @@ -2724,7 +2724,7 @@ region_model::get_store_value (const reg
>  	= cast_reg->get_original_region ()->dyn_cast_string_region ())
>        {
>  	tree string_cst = str_reg->get_string_cst ();
> -	tree byte_offset_cst = build_int_cst (integer_type_node, 0);
> +	tree byte_offset_cst = integer_zero_node;
>  	if (const svalue *char_sval
>  	    = m_mgr->maybe_get_char_from_string_cst (string_cst,
>  						     byte_offset_cst))
> @@ -7168,7 +7168,7 @@ build_real_cst_from_string (tree type, c
>  static void
>  append_interesting_constants (auto_vec<tree> *out)
>  {
> -  out->safe_push (build_int_cst (integer_type_node, 0));
> +  out->safe_push (integer_zero_node);
>    out->safe_push (build_int_cst (integer_type_node, 42));
>    out->safe_push (build_int_cst (unsigned_type_node, 0));
>    out->safe_push (build_int_cst (unsigned_type_node, 42));
> @@ -7393,7 +7393,7 @@ test_array_1 ()
>  
>    region_model_manager mgr;
>    region_model model (&mgr);
> -  tree int_0 = build_int_cst (integer_type_node, 0);
> +  tree int_0 = integer_zero_node;
>    tree a_0 = build4 (ARRAY_REF, char_type_node,
>  		     a, int_0, NULL_TREE, NULL_TREE);
>    tree char_A = build_int_cst (char_type_node, 'A');
> @@ -7450,7 +7450,7 @@ test_get_representative_tree ()
>      {
>        test_region_model_context ctxt;
>        region_model model (&mgr);
> -      tree idx = build_int_cst (integer_type_node, 0);
> +      tree idx = integer_zero_node;
>        tree a_0 = build4 (ARRAY_REF, char_type_node,
>  			 a, idx, NULL_TREE, NULL_TREE);
>        const region *a_0_reg = model.get_lvalue (a_0, &ctxt);
> @@ -7502,7 +7502,7 @@ test_get_representative_tree ()
>  static void
>  test_unique_constants ()
>  {
> -  tree int_0 = build_int_cst (integer_type_node, 0);
> +  tree int_0 = integer_zero_node;
>    tree int_42 = build_int_cst (integer_type_node, 42);
>  
>    test_region_model_context ctxt;
> @@ -7885,7 +7885,7 @@ test_bit_range_regions ()
>  static void
>  test_assignment ()
>  {
> -  tree int_0 = build_int_cst (integer_type_node, 0);
> +  tree int_0 = integer_zero_node;
>    tree x = build_global_decl ("x", integer_type_node);
>    tree y = build_global_decl ("y", integer_type_node);
>  
> @@ -7944,7 +7944,7 @@ test_stack_frames ()
>    tree int_42 = build_int_cst (integer_type_node, 42);
>    tree int_10 = build_int_cst (integer_type_node, 10);
>    tree int_5 = build_int_cst (integer_type_node, 5);
> -  tree int_0 = build_int_cst (integer_type_node, 0);
> +  tree int_0 = integer_zero_node;
>  
>    auto_vec <tree> param_types;
>    tree parent_fndecl = make_fndecl (integer_type_node,
> @@ -8627,7 +8627,7 @@ test_state_merging ()
>  static void
>  test_constraint_merging ()
>  {
> -  tree int_0 = build_int_cst (integer_type_node, 0);
> +  tree int_0 = integer_zero_node;
>    tree int_5 = build_int_cst (integer_type_node, 5);
>    tree x = build_global_decl ("x", integer_type_node);
>    tree y = build_global_decl ("y", integer_type_node);
> @@ -8674,9 +8674,9 @@ test_widening_constraints ()
>  {
>    region_model_manager mgr;
>    function_point point (program_point::origin (mgr).get_function_point ());
> -  tree int_0 = build_int_cst (integer_type_node, 0);
> +  tree int_0 = integer_zero_node;
>    tree int_m1 = build_int_cst (integer_type_node, -1);
> -  tree int_1 = build_int_cst (integer_type_node, 1);
> +  tree int_1 = integer_one_node;
>    tree int_256 = build_int_cst (integer_type_node, 256);
>    test_region_model_context ctxt;
>    const svalue *int_0_sval = mgr.get_or_create_constant_svalue (int_0);
> @@ -8790,8 +8790,8 @@ test_iteration_1 ()
>    region_model_manager mgr;
>    program_point point (program_point::origin (mgr));
>  
> -  tree int_0 = build_int_cst (integer_type_node, 0);
> -  tree int_1 = build_int_cst (integer_type_node, 1);
> +  tree int_0 = integer_zero_node;
> +  tree int_1 = integer_one_node;
>    tree int_256 = build_int_cst (integer_type_node, 256);
>    tree i = build_global_decl ("i", integer_type_node);
>  
> @@ -8944,8 +8944,8 @@ test_array_2 ()
>    /* "int i;"  */
>    tree i = build_global_decl ("i", integer_type_node);
>  
> -  tree int_0 = build_int_cst (integer_type_node, 0);
> -  tree int_1 = build_int_cst (integer_type_node, 1);
> +  tree int_0 = integer_zero_node;
> +  tree int_1 = integer_one_node;
>  
>    tree arr_0 = build4 (ARRAY_REF, integer_type_node,
>  		       arr, int_0, NULL_TREE, NULL_TREE);
> --- gcc/objc/objc-next-runtime-abi-02.cc.jj	2024-01-29 09:41:19.687393274 +0100
> +++ gcc/objc/objc-next-runtime-abi-02.cc	2024-03-19 13:34:36.535988469 +0100
> @@ -3244,7 +3244,7 @@ build_v2_class_ro_t_initializer (tree ty
>       explicitly declare the alignment padding.  */
>    /* reserved, pads alignment.  */
>    CONSTRUCTOR_APPEND_ELT (initlist, NULL_TREE,
> -			    build_int_cst (integer_type_node, 0));
> +			    integer_zero_node);
>  
>    /* ivarLayout */
>    unsigned_char_star = build_pointer_type (unsigned_char_type_node);
> --- gcc/fortran/trans-array.cc.jj	2024-03-18 08:58:46.191769237 +0100
> +++ gcc/fortran/trans-array.cc	2024-03-19 13:30:14.338665071 +0100
> @@ -10397,7 +10397,7 @@ structure_alloc_comps (gfc_symbol * der_
>  		  gfc_add_expr_to_block (&tblock, t);
>  		  if (c->attr.pdt_array)
>  		    gfc_add_modify (&tblock, gfc_conv_descriptor_version (comp),
> -				    build_zero_cst (integer_type_node));
> +				    integer_zero_node);
>  		  tmp = build3_loc (input_location, COND_EXPR, void_type_node,
>  				    cd, gfc_finish_block (&tblock),
>  				    gfc_call_free (tmp));
> --- gcc/fortran/trans-expr.cc.jj	2024-03-15 09:13:35.195543327 +0100
> +++ gcc/fortran/trans-expr.cc	2024-03-19 13:34:36.509988834 +0100
> @@ -4082,7 +4082,7 @@ conv_scalar_char_value (gfc_symbol *sym,
>        if ((*expr)->ref == NULL)
>  	{
>  	  se->expr = gfc_string_to_single_character
> -	    (build_int_cst (integer_type_node, 1),
> +	    (integer_one_node,
>  	      gfc_build_addr_expr (gfc_get_pchar_type ((*expr)->ts.kind),
>  				  gfc_get_symbol_decl
>  				  ((*expr)->symtree->n.sym)),
> @@ -4092,7 +4092,7 @@ conv_scalar_char_value (gfc_symbol *sym,
>  	{
>  	  gfc_conv_variable (se, *expr);
>  	  se->expr = gfc_string_to_single_character
> -	    (build_int_cst (integer_type_node, 1),
> +	    (integer_one_node,
>  	      gfc_build_addr_expr (gfc_get_pchar_type ((*expr)->ts.kind),
>  				  se->expr),
>  	      (*expr)->ts.kind);
> --- gcc/fortran/trans-stmt.cc.jj	2024-03-15 09:13:35.198543286 +0100
> +++ gcc/fortran/trans-stmt.cc	2024-03-19 13:34:36.532988512 +0100
> @@ -764,7 +764,7 @@ gfc_trans_form_team (gfc_code *code)
>        tmp = build_call_expr_loc (input_location,
>  				 gfor_fndecl_caf_form_team, 3,
>  				 team_id, team_type,
> -				 build_int_cst (integer_type_node, 0));
> +				 integer_zero_node);
>        gfc_add_expr_to_block (&se.pre, tmp);
>        gfc_add_block_to_block (&se.pre, &argse1.post);
>        gfc_add_block_to_block (&se.pre, &argse2.post);
> @@ -795,7 +795,7 @@ gfc_trans_change_team (gfc_code *code)
>  
>        tmp = build_call_expr_loc (input_location,
>  				 gfor_fndecl_caf_change_team, 2, team_type,
> -				 build_int_cst (integer_type_node, 0));
> +				 integer_zero_node);
>        gfc_add_expr_to_block (&argse.pre, tmp);
>        gfc_add_block_to_block (&argse.pre, &argse.post);
>        return gfc_finish_block (&argse.pre);
> @@ -846,7 +846,7 @@ gfc_trans_sync_team (gfc_code *code)
>        tmp = build_call_expr_loc (input_location,
>  				 gfor_fndecl_caf_sync_team, 2,
>  				 team_type,
> -				 build_int_cst (integer_type_node, 0));
> +				 integer_zero_node);
>        gfc_add_expr_to_block (&argse.pre, tmp);
>        gfc_add_block_to_block (&argse.pre, &argse.post);
>        return gfc_finish_block (&argse.pre);
> @@ -1357,7 +1357,7 @@ gfc_trans_sync (gfc_code *code, gfc_exec
>  	}
>        else if (code->expr1->rank == 0)
>  	{
> -	  len = build_int_cst (integer_type_node, 1);
> +	  len = integer_one_node;
>  	  images = gfc_build_addr_expr (NULL_TREE, images);
>  	}
>        else
> --- gcc/fortran/trans-decl.cc.jj	2024-03-14 14:07:34.157425953 +0100
> +++ gcc/fortran/trans-decl.cc	2024-03-19 13:34:36.499988974 +0100
> @@ -6636,7 +6636,7 @@ create_main_function (tree fndecl)
>    /* "return 0".  */
>    tmp = fold_build2_loc (input_location, MODIFY_EXPR, integer_type_node,
>  			 DECL_RESULT (ftn_main),
> -			 build_int_cst (integer_type_node, 0));
> +			 integer_zero_node);
>    tmp = build1_v (RETURN_EXPR, tmp);
>    gfc_add_expr_to_block (&body, tmp);
>  
> --- gcc/fortran/trans-intrinsic.cc.jj	2024-01-15 09:56:49.558544819 +0100
> +++ gcc/fortran/trans-intrinsic.cc	2024-03-19 13:34:36.504988904 +0100
> @@ -2562,7 +2562,7 @@ trans_this_image (gfc_se * se, gfc_expr
>    gfc_add_modify (&loop, loop_var,
>                    fold_build2_loc (input_location, PLUS_EXPR, integer_type_node,
>  				   loop_var,
> -				   build_int_cst (integer_type_node, 1)));
> +				   integer_one_node));
>  
>    /* Making the loop... actually loop!  */
>    tmp = gfc_finish_block (&loop);
> @@ -12815,7 +12815,7 @@ conv_intrinsic_move_alloc (gfc_code *cod
>  					    null_pointer_node));
>        tmp = build_call_expr_loc (input_location, gfor_fndecl_caf_sync_all,
>  				 3, null_pointer_node, null_pointer_node,
> -				 build_int_cst (integer_type_node, 0));
> +				 integer_zero_node);
>  
>        tmp = fold_build3_loc (input_location, COND_EXPR, void_type_node, cond,
>  			     tmp, build_empty_stmt (input_location));
> --- gcc/fortran/trans.cc.jj	2024-01-03 12:07:06.659671267 +0100
> +++ gcc/fortran/trans.cc	2024-03-19 13:34:36.539988413 +0100
> @@ -900,7 +900,7 @@ gfc_allocate_using_caf_lib (stmtblock_t
>      {
>        gcc_assert(errlen == NULL_TREE);
>        errmsg = null_pointer_node;
> -      errlen = build_int_cst (integer_type_node, 0);
> +      errlen = integer_zero_node;
>      }
>  
>    size = fold_convert (size_type_node, size);
> @@ -1903,7 +1903,7 @@ gfc_deallocate_with_status (tree pointer
>  	  if (descr)
>  	    cond = fold_build2_loc (input_location, EQ_EXPR, boolean_type_node,
>  				    gfc_conv_descriptor_version (descr),
> -				    build_int_cst (integer_type_node, 1));
> +				    integer_one_node);
>  	  else
>  	    cond = gfc_omp_call_is_alloc (pointer);
>  	  omp_tmp = builtin_decl_explicit (BUILT_IN_GOMP_FREE);
> @@ -1917,7 +1917,7 @@ gfc_deallocate_with_status (tree pointer
>  							 0));
>        if (flag_openmp_allocators && descr)
>  	gfc_add_modify (&non_null, gfc_conv_descriptor_version (descr),
> -			build_zero_cst (integer_type_node));
> +			integer_zero_node);
>  
>        if (status != NULL_TREE && !integer_zerop (status))
>  	{
> @@ -1946,7 +1946,7 @@ gfc_deallocate_with_status (tree pointer
>  	{
>  	  gcc_assert (errlen == NULL_TREE);
>  	  errmsg = null_pointer_node;
> -	  errlen = build_zero_cst (integer_type_node);
> +	  errlen = integer_zero_node;
>  	}
>        else
>  	{
> 
> 	Jakub
> 
> 

-- 
Richard Biener <rguenther@suse.de>
SUSE Software Solutions Germany GmbH,
Frankenstrasse 146, 90461 Nuernberg, Germany;
GF: Ivo Totev, Andrew McDonald, Werner Knoblich; (HRB 36809, AG Nuernberg)


More information about the Gcc-patches mailing list