Bug 22325 - missed optimization in loop
Summary: missed optimization in loop
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: Zdenek Dvorak
URL: http://gcc.gnu.org/ml/gcc-patches/200...
Keywords: missed-optimization, patch, TREE
Depends on: 18687 17640
Blocks: 20656 22366
  Show dependency treegraph
 
Reported: 2005-07-06 15:18 UTC by Andrew Pinski
Modified: 2005-07-27 13:56 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2005-07-07 20:02:45


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Pinski 2005-07-06 15:18:22 UTC
The following two functions should be the same:
int foo(int a) {
int i;
for (i=0; i<200; i++) {
a = a + 5;
}
return a;
}
int foo(int a) {
int i;
for (i=0; i<200; i++) ;
return a+5*200;
}

The RTL optimizers catch this on ppc but not on x86.
Comment 1 Andrew Pinski 2005-07-06 15:23:39 UTC
And then we can remove the empty loop which is PR 17640.
Comment 2 Andrew Pinski 2005-07-07 19:57:52 UTC
The old RTL loop optimizer is the one which catches this as shown by adding -floop-optimize2 to 
disable the old RTL loop optimizer.
Comment 3 Andrew Pinski 2005-07-07 20:02:45 UTC
Assigning to Zdenek as requested by Honza.
I will note if the start of a was a constant we do the optimization at the tree level.
Comment 4 Steven Bosscher 2005-07-07 20:06:49 UTC
This is related to Bug 18687. 
Comment 5 Andrew Pinski 2005-07-07 20:16:35 UTC
This looks related to PR 20656.
Comment 6 Andrew Pinski 2005-07-15 17:01:50 UTC
Patch posted here: <http://gcc.gnu.org/ml/gcc-patches/2005-07/msg01038.html>.
Comment 7 CVS Commits 2005-07-27 13:27:17 UTC
Subject: Bug 22325

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	rakdver@gcc.gnu.org	2005-07-27 13:26:56

Modified files:
	gcc            : ChangeLog tree-flow.h tree-scalar-evolution.c 
	                 tree-ssa-loop-ivopts.c 

Log message:
	PR tree-optimization/22325
	* tree-flow.h (compute_phi_arg_on_exit, force_expr_to_var_cost):
	Declare.
	* tree-scalar-evolution.c (scev_const_prop): Add generic final
	value replacement.
	* tree-ssa-loop-ivopts.c (force_expr_to_var_cost): Split from ...
	(force_var_cost): ... this function.
	(compute_phi_arg_on_exit): Export.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.9563&r2=2.9564
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/tree-flow.h.diff?cvsroot=gcc&r1=2.130&r2=2.131
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/tree-scalar-evolution.c.diff?cvsroot=gcc&r1=2.31&r2=2.32
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/tree-ssa-loop-ivopts.c.diff?cvsroot=gcc&r1=2.85&r2=2.86

Comment 8 Andrew Pinski 2005-07-27 13:56:16 UTC
Fixed.