struct X { int i; }; int foo (int x) { struct X a; struct X b; struct X *p; a.i = 1; b.i = 2; if (x) p = &a; else p = &b; return p->i; } should be optimized to return 1 or 2, removing the loads on both paths. One piece that is missing is that PHI-translation does not optimize the reference ops vector after phi-translating the operands. So we end up looking up (*(&a)).i instead of a.i. If you fix that we still have mismatched virtual operands. This will be fixed on the alias-improvements branch.
Created attachment 16528 [details] patch for phi-translation Patch fixing the phi-translation deficiency, adding a simple optimization to remove *& pairs.
This seem related to PR 33344.
Subject: Bug 37892 Author: rguenth Date: Sat Apr 4 09:34:32 2009 New Revision: 145533 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=145533 Log: 2009-04-04 Richard Guenther <rguenther@suse.de> PR tree-optimization/8781 PR tree-optimization/37892 * tree-ssa-sccvn.h (vn_reference_fold_indirect): Declare. * tree-ssa-sccvn.c (vn_reference_fold_indirect): New function. (valueize_refs): Call it for *& valueizations. (shared_reference_ops_from_ref): Rename to ... (valueize_shared_reference_ops_from_ref): ... this and valueize. (shared_reference_ops_from_call): Rename to ... (valueize_shared_reference_ops_from_call): ... this and valueize. (vn_reference_lookup): Update. (visit_reference_op_call): Likewise. * tree-ssa-pre.c (phi_translate_1): Fold *&. (eliminate): Value-replace the call address in call statements. * g++.dg/tree-ssa/pr8781.C: New testcase. * gcc.dg/tree-ssa/ssa-pre-25.c: Likewise. Added: trunk/gcc/testsuite/g++.dg/tree-ssa/pr8781.C trunk/gcc/testsuite/gcc.dg/tree-ssa/ssa-pre-25.c Modified: trunk/gcc/ChangeLog trunk/gcc/testsuite/ChangeLog trunk/gcc/tree-ssa-pre.c trunk/gcc/tree-ssa-sccvn.c trunk/gcc/tree-ssa-sccvn.h
Fixed.