Bug 21031 - Another missed forward propagation opportunity
Summary: Another missed forward propagation opportunity
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: Kazu Hirata
URL:
Keywords: missed-optimization
Depends on:
Blocks:
 
Reported: 2005-04-14 20:43 UTC by Kazu Hirata
Modified: 2005-04-15 19:05 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2005-04-14 20:50:59


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Kazu Hirata 2005-04-14 20:43:30 UTC
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.
Comment 1 Andrew Pinski 2005-04-14 20:50:59 UTC
Confirmed, I thought I saw a bug like before.
Comment 2 Kazu Hirata 2005-04-15 15:30:24 UTC
Patch posted:
http://gcc.gnu.org/ml/gcc-patches/2005-04/msg01726.html
Comment 3 GCC Commits 2005-04-15 18:42:56 UTC
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

Comment 4 Kazu Hirata 2005-04-15 18:44:09 UTC
Just checked in a patch.