Bug 20725 - [tcb] FRE does not remove a fully redundant load.
Summary: [tcb] FRE does not remove a fully redundant load.
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: unknown
: P2 enhancement
Target Milestone: 4.1.0
Assignee: Daniel Berlin
URL:
Keywords: missed-optimization
Depends on:
Blocks:
 
Reported: 2005-04-02 04:36 UTC by Kazu Hirata
Modified: 2005-07-23 22:49 UTC (History)
2 users (show)

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


Attachments
frefixes.diff (855 bytes, patch)
2005-04-02 14:32 UTC, Daniel Berlin
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Kazu Hirata 2005-04-02 04:36:59 UTC
Consider:

struct s {
  int *n;
};

int
foo (unsigned int i, struct s *array)
{
  int *p = array[i].n;
  if (p)
    {
      int *q = array[i].n;
      if (p != q)
	return 1;
    }
  return 0;
}

Note that the second load is unnecessary, but FRE does not remove it.

Here is the dump before FRE.

foo (i, array)
{
  int * q;
  int * p;
  int D.1142;
  struct s * D.1141;
  struct s * D.1140;
  unsigned int D.1139;

<bb 0>:
  D.1139_3 = i_2 * 4;
  D.1140_4 = (struct s *) D.1139_3;
  D.1141_6 = D.1140_4 + array_5;
  #   VUSE <TMT.0_15>;
  p_7 = D.1141_6->n;
  if (p_7 != 0B) goto <L0>; else goto <L2>;

<L0>:;
  D.1139_10 = i_2 * 4;
  D.1140_11 = (struct s *) D.1139_10;
  D.1141_12 = array_5 + D.1140_11;
  #   VUSE <TMT.0_15>;
  q_13 = D.1141_12->n;
  if (p_7 != q_13) goto <L1>; else goto <L2>;

<L1>:;
  D.1142_14 = 1;
  goto <bb 4> (<L4>);

<L2>:;
  D.1142_9 = 0;

  # D.1142_1 = PHI <1(2), 0(3)>;
<L4>:;
  return D.1142_1;

}

After FRE:

foo (i, array)
{
  int * q;
  int * p;
  int D.1142;
  struct s * D.1141;
  struct s * D.1140;
  unsigned int D.1139;

<bb 0>:
  D.1139_3 = i_2 * 4;
  D.1140_4 = (struct s *) D.1139_3;
  D.1141_6 = D.1140_4 + array_5;
  #   VUSE <TMT.0_15>;
  p_7 = D.1141_6->n;
  if (p_7 != 0B) goto <L0>; else goto <L2>;

<L0>:;
  D.1139_10 = D.1139_3;
  D.1140_11 = D.1140_4;
  D.1141_12 = D.1141_6;
  #   VUSE <TMT.0_15>;
  q_13 = D.1141_12->n;
  if (p_7 != q_13) goto <L1>; else goto <L2>;

<L1>:;
  D.1142_14 = 1;
  goto <bb 4> (<L4>);

<L2>:;
  D.1142_9 = 0;

  # D.1142_1 = PHI <1(2), 0(3)>;
<L4>:;
  return D.1142_1;

}
Comment 1 Kazu Hirata 2005-04-02 04:41:53 UTC
Danny, could you take a look?

This occurs even with your patch to tree-ssa-pre.c to fix PR 20703.
Comment 2 Daniel Berlin 2005-04-02 14:32:29 UTC
Subject: Bug 20725

Here's a patch that fixes this
After TCB merge i'll commit it.

Comment 3 Daniel Berlin 2005-04-02 14:32:30 UTC
Created attachment 8511 [details]
frefixes.diff
Comment 4 CVS Commits 2005-04-04 19:02:56 UTC
Subject: Bug 20725

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	dberlin@gcc.gnu.org	2005-04-04 19:02:18

Modified files:
	gcc            : ChangeLog tree-ssa-pre.c 
	gcc/testsuite/gcc.dg/tree-ssa: ssa-pre-1.c ssa-pre-2.c 
	                               ssa-pre-3.c ssa-pre-4.c 
	                               ssa-pre-5.c ssa-pre-6.c 
Added files:
	gcc/testsuite/gcc.dg/tree-ssa: ssa-pre-7.c ssa-pre-8.c 

Log message:
	2005-04-02  Daniel Berlin  <dberlin@dberlin.org>
	Diego Novillo <dnovillo@redhat.com>
	
	Fix PR tree-optimization/20703
	Fix PR tree-optimization/20725
	
	* tree-ssa-pre.c (phi_translate): Handle tcc_comparison.
	(create_expression_by_pieces): Ditto.
	(valid_in_set): Ditto. Also handle tcc_declaration.
	(find_or_generate_expression): Handle comparison class.
	(insert_into_preds_of_block): Ditto.
	(insert_aux): Ditto.
	(create_value_expr_from): Handle comparison class, recursively
	handle reference nodes.
	(compute_avail): Handle comparison classes, rewrite a little cleaner.
	(execute_pre): Fix spacing.
	(do_fre): Renamed to execute_fre.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.8122&r2=2.8123
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/tree-ssa-pre.c.diff?cvsroot=gcc&r1=2.72&r2=2.73
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/tree-ssa/ssa-pre-7.c.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/tree-ssa/ssa-pre-8.c.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/tree-ssa/ssa-pre-1.c.diff?cvsroot=gcc&r1=1.5&r2=1.6
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/tree-ssa/ssa-pre-2.c.diff?cvsroot=gcc&r1=1.4&r2=1.5
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/tree-ssa/ssa-pre-3.c.diff?cvsroot=gcc&r1=1.2&r2=1.3
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/tree-ssa/ssa-pre-4.c.diff?cvsroot=gcc&r1=1.2&r2=1.3
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/tree-ssa/ssa-pre-5.c.diff?cvsroot=gcc&r1=1.2&r2=1.3
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/tree-ssa/ssa-pre-6.c.diff?cvsroot=gcc&r1=1.2&r2=1.3

Comment 5 Daniel Berlin 2005-04-04 19:09:59 UTC
Fixed