Consider: int foo (int a) { int b = a != 0; unsigned char c = b; if (c) return 1; else return 0; } We end up with code like this: b_3 = a_2 != 0; c_4 = (unsigned char) b_3; if (c_4 != 0) goto <L0>; else goto <L2>; We want to forward-propagate the preceding two statements into the COND_EXPR and get if (a_2 != 0) goto <L0>; else goto <L2>; Unlike forward propagation opportunities noted in PR 14754 or PR15558, this kind of opportunity occurs often in practice.
Confirmed, I thought I saw a bug like before.
Patch posted: http://gcc.gnu.org/ml/gcc-patches/2005-04/msg01726.html
Subject: Bug 21031 CVSROOT: /cvs/gcc Module name: gcc Changes by: kazu@gcc.gnu.org 2005-04-15 18:42:38 Modified files: gcc : ChangeLog tree-ssa-forwprop.c gcc/testsuite : ChangeLog Added files: gcc/testsuite/gcc.dg/tree-ssa: pr21031.c Log message: gcc/ PR tree-optimization/21031 * tree-ssa-forwprop.c (ssa_name_defined_by_comparison_p): New. (forward_propagate_into_cond_1): Call it. Forward propagate integer-integer casts into COND_EXPRs. testsuite/ PR tree-optimization/21031 * gcc.dg/tree-ssa/pr21031.c: New. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.8313&r2=2.8314 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/tree-ssa-forwprop.c.diff?cvsroot=gcc&r1=2.13&r2=2.14 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.5354&r2=1.5355 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/tree-ssa/pr21031.c.diff?cvsroot=gcc&r1=NONE&r2=1.1
Just checked in a patch.