Hi, On Fri, 27 Jan 2012, William J. Schmidt wrote:
> ------------------------------------------------------------------------ > int > test_switch_1 (unsigned int *index, int i) > { > switch (*index) ... > However, for the first case, temporary expression replacement has > effectively removed the assignment to D.2004_3 (single local immediate > use permits replacement), so instead we see: > > ------------------------------------------------------------------------ > ;; switch (D.2004_3) <default: <L3>, case 0: <L5>, case 1: <L1>, case 2: > <L2>> > > (insn 7 6 8 (set (reg:SI 124) > (mem:SI (reg/v/f:SI 122 [ index ]) [2 *index_2(D)+0 S4 A32])) > t1.i:4 -1 With TER there is no decl anymore to associate the pseudo with. Conceptually, what's expanded is "*index", not an assignment to a pseudo. The move into a pseudo (and the creation of that very pseudo) is done by copy_to_reg in expand_case. > It would be a nice enhancement if the REG_EXPR could be preserved in > such cases. Does anyone know if there's something that would prevent > this? The hack below works in this specific situation (TERed into a switch), and adds a REG_EXPR when an TERed SSA name ever expanded into a pseudo (i.e. also for some more generic situations). Ciao, Michael. Index: expr.c =================================================================== --- expr.c (revision 183559) +++ expr.c (working copy) @@ -8991,8 +8991,13 @@ expand_expr_real_1 (tree exp, rtx target && stmt_is_replaceable_p (SSA_NAME_DEF_STMT (exp))) g = SSA_NAME_DEF_STMT (exp); if (g) - return expand_expr_real (gimple_assign_rhs_to_tree (g), target, tmode, - modifier, NULL); + { + rtx r = expand_expr_real (gimple_assign_rhs_to_tree (g), target, + tmode, modifier, NULL); + if (REG_P (r) && !REG_EXPR (r)) + set_reg_attrs_for_decl_rtl (SSA_NAME_VAR (exp), r); + return r; + } ssa_name = exp; decl_rtl = get_rtx_for_ssa_name (ssa_name); Index: stmt.c =================================================================== --- stmt.c (revision 183559) +++ stmt.c (working copy) @@ -2381,7 +2381,11 @@ expand_case (gimple stmt) do_pending_stack_adjust (); if (MEM_P (index)) - index = copy_to_reg (index); + { + index = copy_to_reg (index); + if (TREE_CODE (index_expr) == SSA_NAME) + set_reg_attrs_for_decl_rtl (SSA_NAME_VAR (index_expr), index); + } /* We generate a binary decision tree to select the appropriate target code. This is done as follows: