Richard, this patch fixes PR52009.
Consider this test-case: ... int z; void foo (int y) { if (y == 6) z = 5; else z = 5; } ... Currently, compiling with -O2 gives us this representation at pr51879-7.c.094t.pre: ... # BLOCK 3 freq:1991 # PRED: 2 [19.9%] (true,exec) # .MEMD.1710_4 = VDEF <.MEMD.1710_3(D)> zD.1702 = 5; goto <bb 5>; # SUCC: 5 [100.0%] (fallthru,exec) # BLOCK 4 freq:8009 # PRED: 2 [80.1%] (false,exec) # .MEMD.1710_5 = VDEF <.MEMD.1710_3(D)> zD.1702 = 5; # SUCC: 5 [100.0%] (fallthru,exec) # BLOCK 5 freq:10000 # PRED: 3 [100.0%] (fallthru,exec) 4 [100.0%] (fallthru,exec) # .MEMD.1710_2 = PHI <.MEMD.1710_4(3), .MEMD.1710_5(4)> # VUSE <.MEMD.1710_2> return; ... Blocks 3 and 4 are not tail-merged. The patch allows the example to be tail-merged by: - value numbering .MEMD.1710_4 and .MEMD.1710_5 equal - comparing gimple_vdef value numbers for assignments during tail-merge Bootstrapped and reg-tested on x86_64. OK for stage1? Thanks, - Tom 2012-01-31 Tom de Vries <t...@codesourcery.com> PR tree-optimization/52009 * tree-ssa-tail-merge.c (gimple_equal_p): For GIMPLE_ASSIGN, compare value numbers of gimple_vdef. * tree-ssa-sccvn.h (struct vn_reference_s): Add vdef field. (vn_reference_insert): Add vdef parameter to prototype. * tree-ssa-sccvn.c (copy_reference_ops_from_ref): Handle MODIFY_EXPR. (vn_reference_insert): Add and handle vdef parameter. (visit_reference_op_load): Add argument to vn_reference_insert call. (visit_reference_op_store): Find value number of vdef of store. Insert value number of vdef of store. * gcc.dg/pr51879-7.c: New test.