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.
Confirmed.
*** Bug 20762 has been marked as a duplicate of this bug. ***
Patch posted: http://gcc.gnu.org/ml/gcc-patches/2005-04/msg01457.html
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
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
Just checked in a patch.