This splits out more cleanups from the main patch to make that smaller. The only bigger part of the patch is making tree-stdarg track escapes/varargs for SSA names more precise by not globbing on SSA_NAME_VAR but instead using the bits [0..num_ssa_names-1] for SSA names and [num_ssa_names,max_decl_uid + num_ssa_names] for decls in its bitmap. Eventually this pass will get rewritten by Micha anyway who has pending patches to make va_arg survive until after inlining.
Bootstrapped on x86_64-unknown-linux-gnu, testing in progress. Richard. 2012-08-08 Richard Guenther <rguent...@suse.de> * tree-call-cdce.c (check_pow): Simplify. (gen_conditions_for_pow_int_base): Likewise. * tree-ssa-dom.c (propagate_rhs_into_lhs): Do not handle virtual operands here. * tree-ssa-operands.c (get_name_decl): Remove unused function. * gimplify.c (gimple_regimplify_operands): Remove dead code. * tree-vrp.c (get_value_range): Move SSA_NAME_VAR access. * tree-parloops.c (create_phi_for_local_result): Use copy_ssa_name. * value-prof.c (gimple_ic): Use duplicate_ssa_name. (gimple_stringop_fixed_value): Likewise. * tree.c (needs_to_live_in_memory): Remove SSA name handling. * tree-stdarg.c (find_va_list_reference): Store SSA_NAME_VERSIONs in the bitmap alongside shifted DECL_UIDs. (va_list_counter_struct_op): Likewise. (va_list_ptr_read): Likewise. (va_list_ptr_write): Likewise. (check_va_list_escapes): Likewise. (check_all_va_list_escapes): Likewise. (execute_optimize_stdarg): Likewise. * tree-outof-ssa.c (insert_backedge_copies): Use copy_ssa_name. Index: gcc/tree-outof-ssa.c =================================================================== *** gcc/tree-outof-ssa.c.orig 2012-08-08 13:56:23.000000000 +0200 --- gcc/tree-outof-ssa.c 2012-08-08 14:20:22.116810728 +0200 *************** insert_backedge_copies (void) *** 1030,1042 **** { gimple phi = gsi_stmt (gsi); tree result = gimple_phi_result (phi); - tree result_var; size_t i; if (!is_gimple_reg (result)) continue; - result_var = SSA_NAME_VAR (result); for (i = 0; i < gimple_phi_num_args (phi); i++) { tree arg = gimple_phi_arg_def (phi, i); --- 1030,1040 ---- *************** insert_backedge_copies (void) *** 1048,1054 **** needed. */ if ((e->flags & EDGE_DFS_BACK) && (TREE_CODE (arg) != SSA_NAME ! || SSA_NAME_VAR (arg) != result_var || trivially_conflicts_p (bb, result, arg))) { tree name; --- 1046,1052 ---- needed. */ if ((e->flags & EDGE_DFS_BACK) && (TREE_CODE (arg) != SSA_NAME ! || SSA_NAME_VAR (arg) != SSA_NAME_VAR (result) || trivially_conflicts_p (bb, result, arg))) { tree name; *************** insert_backedge_copies (void) *** 1078,1087 **** /* Create a new instance of the underlying variable of the PHI result. */ ! stmt = gimple_build_assign (result_var, gimple_phi_arg_def (phi, i)); - name = make_ssa_name (result_var, stmt); - gimple_assign_set_lhs (stmt, name); /* copy location if present. */ if (gimple_phi_arg_has_location (phi, i)) --- 1076,1084 ---- /* Create a new instance of the underlying variable of the PHI result. */ ! name = copy_ssa_name (result, NULL); ! stmt = gimple_build_assign (name, gimple_phi_arg_def (phi, i)); /* copy location if present. */ if (gimple_phi_arg_has_location (phi, i)) Index: gcc/tree-stdarg.c =================================================================== *** gcc/tree-stdarg.c.orig 2012-08-08 13:56:23.000000000 +0200 --- gcc/tree-stdarg.c 2012-08-08 14:20:22.120810730 +0200 *************** find_va_list_reference (tree *tp, int *w *** 266,276 **** tree var = *tp; if (TREE_CODE (var) == SSA_NAME) ! var = SSA_NAME_VAR (var); ! ! if (TREE_CODE (var) == VAR_DECL ! && bitmap_bit_p (va_list_vars, DECL_UID (var))) ! return var; return NULL_TREE; } --- 266,280 ---- tree var = *tp; if (TREE_CODE (var) == SSA_NAME) ! { ! if (bitmap_bit_p (va_list_vars, SSA_NAME_VERSION (var))) ! return var; ! } ! else if (TREE_CODE (var) == VAR_DECL) ! { ! if (bitmap_bit_p (va_list_vars, DECL_UID (var) + num_ssa_names)) ! return var; ! } return NULL_TREE; } *************** va_list_counter_struct_op (struct stdarg *** 347,358 **** return false; if (TREE_CODE (var) != SSA_NAME ! || bitmap_bit_p (si->va_list_vars, DECL_UID (SSA_NAME_VAR (var)))) return false; base = get_base_address (ap); if (TREE_CODE (base) != VAR_DECL ! || !bitmap_bit_p (si->va_list_vars, DECL_UID (base))) return false; if (TREE_OPERAND (ap, 1) == va_list_gpr_counter_field) --- 351,362 ---- return false; if (TREE_CODE (var) != SSA_NAME ! || bitmap_bit_p (si->va_list_vars, SSA_NAME_VERSION (var))) return false; base = get_base_address (ap); if (TREE_CODE (base) != VAR_DECL ! || !bitmap_bit_p (si->va_list_vars, DECL_UID (base) + num_ssa_names)) return false; if (TREE_OPERAND (ap, 1) == va_list_gpr_counter_field) *************** static bool *** 371,383 **** va_list_ptr_read (struct stdarg_info *si, tree ap, tree tem) { if (TREE_CODE (ap) != VAR_DECL ! || !bitmap_bit_p (si->va_list_vars, DECL_UID (ap))) return false; if (TREE_CODE (tem) != SSA_NAME ! || bitmap_bit_p (si->va_list_vars, ! DECL_UID (SSA_NAME_VAR (tem))) ! || is_global_var (SSA_NAME_VAR (tem))) return false; if (si->compute_sizes < 0) --- 375,385 ---- va_list_ptr_read (struct stdarg_info *si, tree ap, tree tem) { if (TREE_CODE (ap) != VAR_DECL ! || !bitmap_bit_p (si->va_list_vars, DECL_UID (ap) + num_ssa_names)) return false; if (TREE_CODE (tem) != SSA_NAME ! || bitmap_bit_p (si->va_list_vars, SSA_NAME_VERSION (tem))) return false; if (si->compute_sizes < 0) *************** va_list_ptr_read (struct stdarg_info *si *** 405,412 **** /* Note the temporary, as we need to track whether it doesn't escape the current function. */ ! bitmap_set_bit (si->va_list_escape_vars, ! DECL_UID (SSA_NAME_VAR (tem))); return true; } --- 407,414 ---- /* Note the temporary, as we need to track whether it doesn't escape the current function. */ ! bitmap_set_bit (si->va_list_escape_vars, SSA_NAME_VERSION (tem)); ! return true; } *************** va_list_ptr_write (struct stdarg_info *s *** 423,433 **** unsigned HOST_WIDE_INT increment; if (TREE_CODE (ap) != VAR_DECL ! || !bitmap_bit_p (si->va_list_vars, DECL_UID (ap))) return false; if (TREE_CODE (tem2) != SSA_NAME ! || bitmap_bit_p (si->va_list_vars, DECL_UID (SSA_NAME_VAR (tem2)))) return false; if (si->compute_sizes <= 0) --- 425,435 ---- unsigned HOST_WIDE_INT increment; if (TREE_CODE (ap) != VAR_DECL ! || !bitmap_bit_p (si->va_list_vars, DECL_UID (ap) + num_ssa_names)) return false; if (TREE_CODE (tem2) != SSA_NAME ! || bitmap_bit_p (si->va_list_vars, SSA_NAME_VERSION (tem2))) return false; if (si->compute_sizes <= 0) *************** check_va_list_escapes (struct stdarg_inf *** 459,481 **** if (TREE_CODE (rhs) == SSA_NAME) { ! if (! bitmap_bit_p (si->va_list_escape_vars, ! DECL_UID (SSA_NAME_VAR (rhs)))) return; } else if (TREE_CODE (rhs) == ADDR_EXPR && TREE_CODE (TREE_OPERAND (rhs, 0)) == MEM_REF && TREE_CODE (TREE_OPERAND (TREE_OPERAND (rhs, 0), 0)) == SSA_NAME) { ! if (! bitmap_bit_p (si->va_list_escape_vars, ! DECL_UID (SSA_NAME_VAR (TREE_OPERAND ! (TREE_OPERAND (rhs, 0), 0))))) return; } else return; ! if (TREE_CODE (lhs) != SSA_NAME || is_global_var (SSA_NAME_VAR (lhs))) { si->va_list_escapes = true; return; --- 461,481 ---- if (TREE_CODE (rhs) == SSA_NAME) { ! if (! bitmap_bit_p (si->va_list_escape_vars, SSA_NAME_VERSION (rhs))) return; } else if (TREE_CODE (rhs) == ADDR_EXPR && TREE_CODE (TREE_OPERAND (rhs, 0)) == MEM_REF && TREE_CODE (TREE_OPERAND (TREE_OPERAND (rhs, 0), 0)) == SSA_NAME) { ! tree ptr = TREE_OPERAND (TREE_OPERAND (rhs, 0), 0); ! if (! bitmap_bit_p (si->va_list_escape_vars, SSA_NAME_VERSION (ptr))) return; } else return; ! if (TREE_CODE (lhs) != SSA_NAME) { si->va_list_escapes = true; return; *************** check_va_list_escapes (struct stdarg_inf *** 511,518 **** return; } ! bitmap_set_bit (si->va_list_escape_vars, ! DECL_UID (SSA_NAME_VAR (lhs))); } --- 511,517 ---- return; } ! bitmap_set_bit (si->va_list_escape_vars, SSA_NAME_VERSION (lhs)); } *************** check_all_va_list_escapes (struct stdarg *** 540,546 **** FOR_EACH_SSA_TREE_OPERAND (use, stmt, iter, SSA_OP_ALL_USES) { if (! bitmap_bit_p (si->va_list_escape_vars, ! DECL_UID (SSA_NAME_VAR (use)))) continue; if (is_gimple_assign (stmt)) --- 539,545 ---- FOR_EACH_SSA_TREE_OPERAND (use, stmt, iter, SSA_OP_ALL_USES) { if (! bitmap_bit_p (si->va_list_escape_vars, ! SSA_NAME_VERSION (use))) continue; if (is_gimple_assign (stmt)) *************** check_all_va_list_escapes (struct stdarg *** 586,597 **** if (TREE_CODE (lhs) == SSA_NAME && bitmap_bit_p (si->va_list_escape_vars, ! DECL_UID (SSA_NAME_VAR (lhs)))) continue; if (TREE_CODE (lhs) == VAR_DECL && bitmap_bit_p (si->va_list_vars, ! DECL_UID (lhs))) continue; } else if (rhs_code == ADDR_EXPR --- 585,596 ---- if (TREE_CODE (lhs) == SSA_NAME && bitmap_bit_p (si->va_list_escape_vars, ! SSA_NAME_VERSION (lhs))) continue; if (TREE_CODE (lhs) == VAR_DECL && bitmap_bit_p (si->va_list_vars, ! DECL_UID (lhs) + num_ssa_names)) continue; } else if (rhs_code == ADDR_EXPR *************** check_all_va_list_escapes (struct stdarg *** 601,607 **** tree lhs = gimple_assign_lhs (stmt); if (bitmap_bit_p (si->va_list_escape_vars, ! DECL_UID (SSA_NAME_VAR (lhs)))) continue; } } --- 600,606 ---- tree lhs = gimple_assign_lhs (stmt); if (bitmap_bit_p (si->va_list_escape_vars, ! SSA_NAME_VERSION (lhs))) continue; } } *************** execute_optimize_stdarg (void) *** 722,728 **** break; } ! bitmap_set_bit (si.va_list_vars, DECL_UID (ap)); /* VA_START_BB and VA_START_AP will be only used if there is just one va_start in the function. */ --- 721,727 ---- break; } ! bitmap_set_bit (si.va_list_vars, DECL_UID (ap) + num_ssa_names); /* VA_START_BB and VA_START_AP will be only used if there is just one va_start in the function. */ Index: gcc/tree.c =================================================================== *** gcc/tree.c.orig 2012-08-08 13:56:23.000000000 +0200 --- gcc/tree.c 2012-08-08 14:49:41.511749811 +0200 *************** range_in_array_bounds_p (tree ref) *** 10155,10163 **** bool needs_to_live_in_memory (const_tree t) { - if (TREE_CODE (t) == SSA_NAME) - t = SSA_NAME_VAR (t); - return (TREE_ADDRESSABLE (t) || is_global_var (t) || (TREE_CODE (t) == RESULT_DECL --- 10155,10160 ---- Index: gcc/value-prof.c =================================================================== *** gcc/value-prof.c.orig 2012-08-08 13:56:23.000000000 +0200 --- gcc/value-prof.c 2012-08-08 14:20:22.122810729 +0200 *************** gimple_ic (gimple icall_stmt, struct cgr *** 1276,1285 **** tree result = gimple_call_lhs (icall_stmt); gimple phi = create_phi_node (result, join_bb); gimple_call_set_lhs (icall_stmt, ! make_ssa_name (SSA_NAME_VAR (result), icall_stmt)); add_phi_arg (phi, gimple_call_lhs (icall_stmt), e_ij, UNKNOWN_LOCATION); gimple_call_set_lhs (dcall_stmt, ! make_ssa_name (SSA_NAME_VAR (result), dcall_stmt)); add_phi_arg (phi, gimple_call_lhs (dcall_stmt), e_dj, UNKNOWN_LOCATION); } --- 1276,1285 ---- tree result = gimple_call_lhs (icall_stmt); gimple phi = create_phi_node (result, join_bb); gimple_call_set_lhs (icall_stmt, ! duplicate_ssa_name (result, icall_stmt)); add_phi_arg (phi, gimple_call_lhs (icall_stmt), e_ij, UNKNOWN_LOCATION); gimple_call_set_lhs (dcall_stmt, ! duplicate_ssa_name (result, dcall_stmt)); add_phi_arg (phi, gimple_call_lhs (dcall_stmt), e_dj, UNKNOWN_LOCATION); } *************** gimple_stringop_fixed_value (gimple vcal *** 1507,1516 **** tree result = gimple_call_lhs (vcall_stmt); gimple phi = create_phi_node (result, join_bb); gimple_call_set_lhs (vcall_stmt, ! make_ssa_name (SSA_NAME_VAR (result), vcall_stmt)); add_phi_arg (phi, gimple_call_lhs (vcall_stmt), e_vj, UNKNOWN_LOCATION); gimple_call_set_lhs (icall_stmt, ! make_ssa_name (SSA_NAME_VAR (result), icall_stmt)); add_phi_arg (phi, gimple_call_lhs (icall_stmt), e_ij, UNKNOWN_LOCATION); } --- 1507,1516 ---- tree result = gimple_call_lhs (vcall_stmt); gimple phi = create_phi_node (result, join_bb); gimple_call_set_lhs (vcall_stmt, ! duplicate_ssa_name (result, vcall_stmt)); add_phi_arg (phi, gimple_call_lhs (vcall_stmt), e_vj, UNKNOWN_LOCATION); gimple_call_set_lhs (icall_stmt, ! duplicate_ssa_name (result, icall_stmt)); add_phi_arg (phi, gimple_call_lhs (icall_stmt), e_ij, UNKNOWN_LOCATION); } Index: gcc/tree-parloops.c =================================================================== *** gcc/tree-parloops.c.orig 2012-08-08 13:56:23.000000000 +0200 --- gcc/tree-parloops.c 2012-08-08 14:20:22.122810729 +0200 *************** create_phi_for_local_result (void **slot *** 1008,1016 **** e = EDGE_PRED (store_bb, 1); else e = EDGE_PRED (store_bb, 0); ! local_res ! = make_ssa_name (SSA_NAME_VAR (gimple_assign_lhs (reduc->reduc_stmt)), ! NULL); locus = gimple_location (reduc->reduc_stmt); new_phi = create_phi_node (local_res, store_bb); add_phi_arg (new_phi, reduc->init, e, locus); --- 1012,1018 ---- e = EDGE_PRED (store_bb, 1); else e = EDGE_PRED (store_bb, 0); ! local_res = copy_ssa_name (gimple_assign_lhs (reduc->reduc_stmt), NULL); locus = gimple_location (reduc->reduc_stmt); new_phi = create_phi_node (local_res, store_bb); add_phi_arg (new_phi, reduc->init, e, locus); Index: gcc/tree-vrp.c =================================================================== *** gcc/tree-vrp.c.orig 2012-08-08 13:56:23.000000000 +0200 --- gcc/tree-vrp.c 2012-08-08 14:20:22.124810727 +0200 *************** get_value_range (const_tree var) *** 718,726 **** /* If VAR is a default definition of a parameter, the variable can take any value in VAR's type. */ - sym = SSA_NAME_VAR (var); if (SSA_NAME_IS_DEFAULT_DEF (var)) { if (TREE_CODE (sym) == PARM_DECL) { /* Try to use the "nonnull" attribute to create ~[0, 0] --- 718,726 ---- /* If VAR is a default definition of a parameter, the variable can take any value in VAR's type. */ if (SSA_NAME_IS_DEFAULT_DEF (var)) { + sym = SSA_NAME_VAR (var); if (TREE_CODE (sym) == PARM_DECL) { /* Try to use the "nonnull" attribute to create ~[0, 0] Index: gcc/gimplify.c =================================================================== *** gcc/gimplify.c.orig 2012-08-08 13:56:23.000000000 +0200 --- gcc/gimplify.c 2012-08-08 14:20:22.127810729 +0200 *************** void *** 8363,8369 **** gimple_regimplify_operands (gimple stmt, gimple_stmt_iterator *gsi_p) { size_t i, num_ops; ! tree orig_lhs = NULL_TREE, lhs; gimple_seq pre = NULL; gimple post_stmt = NULL; struct gimplify_ctx gctx; --- 8363,8369 ---- gimple_regimplify_operands (gimple stmt, gimple_stmt_iterator *gsi_p) { size_t i, num_ops; ! tree lhs; gimple_seq pre = NULL; gimple post_stmt = NULL; struct gimplify_ctx gctx; *************** gimple_regimplify_operands (gimple stmt, *** 8429,8435 **** and ASMs are executed before the LHS. The ordering is not important for other statements. */ num_ops = gimple_num_ops (stmt); - orig_lhs = gimple_get_lhs (stmt); for (i = num_ops; i > 0; i--) { tree op = gimple_op (stmt, i - 1); --- 8429,8434 ---- *************** gimple_regimplify_operands (gimple stmt, *** 8507,8516 **** if (need_temp) { tree temp = create_tmp_reg (TREE_TYPE (lhs), NULL); - - if (TREE_CODE (orig_lhs) == SSA_NAME) - orig_lhs = SSA_NAME_VAR (orig_lhs); - if (gimple_in_ssa_p (cfun)) temp = make_ssa_name (temp, NULL); gimple_set_lhs (stmt, temp); --- 8506,8511 ---- Index: gcc/tree-call-cdce.c =================================================================== *** gcc/tree-call-cdce.c.orig 2012-08-08 13:56:23.000000000 +0200 --- gcc/tree-call-cdce.c 2012-08-08 14:20:22.127810729 +0200 *************** check_pow (gimple pow_call) *** 203,209 **** } else if (bc == SSA_NAME) { ! tree base_val0, base_var, type; gimple base_def; int bit_sz; --- 203,209 ---- } else if (bc == SSA_NAME) { ! tree base_val0, type; gimple base_def; int bit_sz; *************** check_pow (gimple pow_call) *** 217,227 **** return false; base_val0 = gimple_assign_rhs1 (base_def); ! base_var = SSA_NAME_VAR (base_val0); ! if (!DECL_P (base_var)) ! return false; ! ! type = TREE_TYPE (base_var); if (TREE_CODE (type) != INTEGER_TYPE) return false; bit_sz = TYPE_PRECISION (type); --- 217,223 ---- return false; base_val0 = gimple_assign_rhs1 (base_def); ! type = TREE_TYPE (base_val0); if (TREE_CODE (type) != INTEGER_TYPE) return false; bit_sz = TYPE_PRECISION (type); *************** gen_conditions_for_pow_int_base (tree ba *** 448,454 **** { gimple base_def; tree base_val0; ! tree base_var, int_type; tree temp, tempn; tree cst0; gimple stmt1, stmt2; --- 444,450 ---- { gimple base_def; tree base_val0; ! tree int_type; tree temp, tempn; tree cst0; gimple stmt1, stmt2; *************** gen_conditions_for_pow_int_base (tree ba *** 457,464 **** base_def = SSA_NAME_DEF_STMT (base); base_val0 = gimple_assign_rhs1 (base_def); ! base_var = SSA_NAME_VAR (base_val0); ! int_type = TREE_TYPE (base_var); bit_sz = TYPE_PRECISION (int_type); gcc_assert (bit_sz > 0 && bit_sz <= MAX_BASE_INT_BIT_SIZE); --- 453,459 ---- base_def = SSA_NAME_DEF_STMT (base); base_val0 = gimple_assign_rhs1 (base_def); ! int_type = TREE_TYPE (base_val0); bit_sz = TYPE_PRECISION (int_type); gcc_assert (bit_sz > 0 && bit_sz <= MAX_BASE_INT_BIT_SIZE); Index: gcc/tree-ssa-dom.c =================================================================== *** gcc/tree-ssa-dom.c.orig 2012-08-08 13:56:23.000000000 +0200 --- gcc/tree-ssa-dom.c 2012-08-08 14:20:22.128810729 +0200 *************** propagate_rhs_into_lhs (gimple stmt, tre *** 2687,2704 **** /* Special cases to avoid useless calls into the folding routines, operand scanning, etc. ! First, propagation into a PHI may cause the PHI to become a degenerate, so mark the PHI as interesting. No other ! actions are necessary. ! ! Second, if we're propagating a virtual operand and the ! propagation does not change the underlying _DECL node for ! the virtual operand, then no further actions are necessary. */ ! if (gimple_code (use_stmt) == GIMPLE_PHI ! || (! is_gimple_reg (lhs) ! && TREE_CODE (rhs) == SSA_NAME ! && SSA_NAME_VAR (lhs) == SSA_NAME_VAR (rhs))) { /* Dump details. */ if (dump_file && (dump_flags & TDF_DETAILS)) { --- 2687,2699 ---- /* Special cases to avoid useless calls into the folding routines, operand scanning, etc. ! Propagation into a PHI may cause the PHI to become a degenerate, so mark the PHI as interesting. No other ! actions are necessary. */ ! if (gimple_code (use_stmt) == GIMPLE_PHI) { + tree result; + /* Dump details. */ if (dump_file && (dump_flags & TDF_DETAILS)) { *************** propagate_rhs_into_lhs (gimple stmt, tre *** 2706,2719 **** print_gimple_stmt (dump_file, use_stmt, 0, dump_flags); } ! /* Propagation into a PHI may expose new degenerate PHIs, ! so mark the result of the PHI as interesting. */ ! if (gimple_code (use_stmt) == GIMPLE_PHI) ! { ! tree result = get_lhs_or_phi_result (use_stmt); ! bitmap_set_bit (interesting_names, SSA_NAME_VERSION (result)); ! } ! continue; } --- 2701,2708 ---- print_gimple_stmt (dump_file, use_stmt, 0, dump_flags); } ! result = get_lhs_or_phi_result (use_stmt); ! bitmap_set_bit (interesting_names, SSA_NAME_VERSION (result)); continue; } Index: gcc/tree-ssa-operands.c =================================================================== *** gcc/tree-ssa-operands.c.orig 2012-08-08 14:20:21.000000000 +0200 --- gcc/tree-ssa-operands.c 2012-08-08 14:20:22.128810729 +0200 *************** static void get_expr_operands (gimple, t *** 126,142 **** /* Number of functions with initialized ssa_operands. */ static int n_initialized = 0; - /* Return the DECL_UID of the base variable of T. */ - - static inline unsigned - get_name_decl (const_tree t) - { - if (TREE_CODE (t) != SSA_NAME) - return DECL_UID (t); - else - return DECL_UID (SSA_NAME_VAR (t)); - } - /* Return true if the SSA operands cache is active. */ --- 126,131 ----