Bug 37892 - phi-translation and SCCVN do not optimize *&
Summary: phi-translation and SCCVN do not optimize *&
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.4.0
: P3 enhancement
Target Milestone: 4.5.0
Assignee: Richard Biener
URL:
Keywords: alias, missed-optimization
Depends on:
Blocks: 8781 33344
  Show dependency treegraph
 
Reported: 2008-10-22 18:15 UTC by Richard Biener
Modified: 2009-04-04 09:35 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
patch for phi-translation (603 bytes, patch)
2008-10-22 18:16 UTC, Richard Biener
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Richard Biener 2008-10-22 18:15:30 UTC
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.
Comment 1 Richard Biener 2008-10-22 18:16:36 UTC
Created attachment 16528 [details]
patch for phi-translation

Patch fixing the phi-translation deficiency, adding a simple optimization to
remove *& pairs.
Comment 2 Andrew Pinski 2008-10-22 19:38:03 UTC
This seem related to PR 33344.
Comment 3 Richard Biener 2009-04-04 09:34:44 UTC
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

Comment 4 Richard Biener 2009-04-04 09:35:36 UTC
Fixed.