Bug 20913 - copy-prop does not fold conditionals
Summary: copy-prop does not fold conditionals
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.1.0
: P2 enhancement
Target Milestone: 4.1.0
Assignee: Kazu Hirata
URL:
Keywords: missed-optimization
: 20762 (view as bug list)
Depends on:
Blocks:
 
Reported: 2005-04-09 03:53 UTC by Kazu Hirata
Modified: 2005-04-13 18:16 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2005-04-11 06:40:52


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Kazu Hirata 2005-04-09 03:53:33 UTC
Consider:

int
foo (int a, int b, int c, int d)
{
  int x, y;

  b = a;
  if (a == b)
    x = c;
  else
    x = d;

  if (x == c)
    return a;
  else
    return b;
}

Run ./cc1 -quiet -O2 -fno-tree-dominator-opts.

Here is the result.

foo (a, b, c, d)
{
  int y;
  int x;
  int D.1145;

<bb 0>:
  b_4 = a_3;
  x_11 = c_5;

  # x_1 = PHI <c_5(0)>;
<L2>:;
  if (x_1 == c_5) goto <L3>; else goto <L4>;

<L3>:;
  a_8 = a_3;
  goto <bb 4> (<L5>);

<L4>:;
  b_7 = a_3;

  # a_2 = PHI <a_3(2), a_3(3)>;
<L5>:;
  return a_3;

}

Note that x == c, but the copy-prop doesn't fold the "if" statement.

This is because find_taken_edge no longer folds conditionals.
Comment 1 Andrew Pinski 2005-04-11 06:40:51 UTC
Confirmed.
Comment 2 Kazu Hirata 2005-04-12 23:13:53 UTC
*** Bug 20762 has been marked as a duplicate of this bug. ***
Comment 3 Kazu Hirata 2005-04-13 14:56:59 UTC
Patch posted:
http://gcc.gnu.org/ml/gcc-patches/2005-04/msg01457.html
Comment 4 GCC Commits 2005-04-13 15:29:05 UTC
Subject: Bug 20913

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	kazu@gcc.gnu.org	2005-04-13 15:28:55

Modified files:
	gcc            : ChangeLog tree-ssa-copy.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/gcc.dg/tree-ssa: pr20913.c 

Log message:
	gcc/
	PR tree-optimization/20913
	* tree-ssa-copy.c (copy_prop_visit_cond_stmt): Fold COND_EXPR.
	
	testsuite/
	PR tree-optimization/20913
	* gcc.dg/tree-ssa/pr20913.c: New.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.8274&r2=2.8275
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/tree-ssa-copy.c.diff?cvsroot=gcc&r1=2.25&r2=2.26
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.5337&r2=1.5338
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/tree-ssa/pr20913.c.diff?cvsroot=gcc&r1=NONE&r2=1.1

Comment 5 GCC Commits 2005-04-13 15:33:32 UTC
Subject: Bug 20913

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	kazu@gcc.gnu.org	2005-04-13 15:33:18

Modified files:
	gcc            : ChangeLog tree-vrp.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/gcc.dg/tree-ssa: pr20702.c 

Log message:
	gcc/
	PR tree-optimization/20913
	* tree-ssa-copy.c (copy_prop_visit_cond_stmt): Fold COND_EXPR.
	
	testsuite/
	PR tree-optimization/20913
	* gcc.dg/tree-ssa/pr20913.c: New.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.8275&r2=2.8276
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/tree-vrp.c.diff?cvsroot=gcc&r1=2.5&r2=2.6
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.5338&r2=1.5339
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/tree-ssa/pr20702.c.diff?cvsroot=gcc&r1=NONE&r2=1.1

Comment 6 Kazu Hirata 2005-04-13 18:14:08 UTC
Just checked in a patch.