X-Git-Url: http://git.sourceforge.jp/view?p=pf3gnuchains%2Fgcc-fork.git;a=blobdiff_plain;f=gcc%2Ftree-scalar-evolution.c;h=4ff50e618904a99b65c58ef2532931dc3c3855d3;hp=4019f78c0aeb511de65cc0449db5d38231ffd6b6;hb=10fec8206407ff88fc7c07e09dcc8fea94eaa101;hpb=012935045e8956d605ab5060190d51bff6d60424 diff --git a/gcc/tree-scalar-evolution.c b/gcc/tree-scalar-evolution.c index 4019f78c0ae..4ff50e61890 100644 --- a/gcc/tree-scalar-evolution.c +++ b/gcc/tree-scalar-evolution.c @@ -2627,3 +2627,72 @@ scev_finalize (void) BITMAP_FREE (already_instantiated); } +/* Replace ssa names for that scev can prove they are constant by the + appropriate constants. Most importantly, this takes care of final + value replacement. + + We only consider SSA names defined by phi nodes; rest is left to the + ordinary constant propagation pass. */ + +void +scev_const_prop (void) +{ + basic_block bb; + tree name, phi, type, ev; + struct loop *loop; + bitmap ssa_names_to_remove = NULL; + + if (!current_loops) + return; + + FOR_EACH_BB (bb) + { + loop = bb->loop_father; + + for (phi = phi_nodes (bb); phi; phi = PHI_CHAIN (phi)) + { + name = PHI_RESULT (phi); + + if (!is_gimple_reg (name)) + continue; + + type = TREE_TYPE (name); + + if (!POINTER_TYPE_P (type) + && !INTEGRAL_TYPE_P (type)) + continue; + + ev = resolve_mixers (loop, analyze_scalar_evolution (loop, name)); + if (!is_gimple_min_invariant (ev) + || !may_propagate_copy (name, ev)) + continue; + + /* Replace the uses of the name. */ + replace_uses_by (name, ev); + + if (!ssa_names_to_remove) + ssa_names_to_remove = BITMAP_ALLOC (NULL); + bitmap_set_bit (ssa_names_to_remove, SSA_NAME_VERSION (name)); + } + } + + /* Remove the ssa names that were replaced by constants. We do not remove them + directly in the previous cycle, since this invalidates scev cache. */ + if (ssa_names_to_remove) + { + bitmap_iterator bi; + unsigned i; + + EXECUTE_IF_SET_IN_BITMAP (ssa_names_to_remove, 0, i, bi) + { + name = ssa_name (i); + phi = SSA_NAME_DEF_STMT (name); + + gcc_assert (TREE_CODE (phi) == PHI_NODE); + remove_phi_node (phi, NULL); + } + + BITMAP_FREE (ssa_names_to_remove); + scev_reset (); + } +}