Commit 25c6036a by Richard Guenther Committed by Richard Biener

re PR tree-optimization/15255 ([tree-ssa] a * 2 + a * 2 is not converted to a * 4)

2008-08-13  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/15255
	* tree-ssa-reassoc.c (linearize_expr_tree): Declare.
	(struct oecount_s): New struct and VEC types.
	(cvec): New global.
	(oecount_hash): New function.
	(oecount_eq): Likewise.
	(oecount_cmp): Likewise.
	(zero_one_operation): New function.
	(build_and_add_sum): Likewise.
	(undistribute_ops_list): Perform un-distribution of multiplication
	and division on the chain of summands.
	(should_break_up_subtract): Also break up subtracts for factors.
	(reassociate_bb): Delete dead visited statements.
	Call undistribute_ops_list.  Re-sort and optimize if it did something.
	* passes.c (init_optimization_passes): Move DSE before
	reassociation.
	* tree-ssa-loop-niter.c (stmt_dominates_stmt_p): Correctly handle
	PHI nodes.

	* gcc.dg/tree-ssa/reassoc-14.c: New testcase.
	* gcc.dg/tree-ssa/reassoc-15.c: Likewise.
	* gcc.dg/tree-ssa/reassoc-16.c: Likewise.
	* gcc.dg/torture/reassoc-1.c: Likewise.
	* gcc.dg/tree-ssa/recip-2.c: Adjust.
	* gcc.dg/tree-ssa/recip-6.c: Likewise.
	* gcc.dg/tree-ssa/recip-7.c: Likewise.
	* gfortran.dg/reassoc_4.f: Likewise.

From-SVN: r139048
parent 92464a8a
2008-08-13 Richard Guenther <rguenther@suse.de>
PR tree-optimization/15255
* tree-ssa-reassoc.c (linearize_expr_tree): Declare.
(struct oecount_s): New struct and VEC types.
(cvec): New global.
(oecount_hash): New function.
(oecount_eq): Likewise.
(oecount_cmp): Likewise.
(zero_one_operation): New function.
(build_and_add_sum): Likewise.
(undistribute_ops_list): Perform un-distribution of multiplication
and division on the chain of summands.
(should_break_up_subtract): Also break up subtracts for factors.
(reassociate_bb): Delete dead visited statements.
Call undistribute_ops_list. Re-sort and optimize if it did something.
* passes.c (init_optimization_passes): Move DSE before
reassociation.
* tree-ssa-loop-niter.c (stmt_dominates_stmt_p): Correctly handle
PHI nodes.
2008-08-12 Janis Johnson <janis187@us.ibm.com>
* doc/invoke.texi (-fipa-pta): Say the option is experimental.
......
......@@ -633,9 +633,9 @@ init_optimization_passes (void)
only examines PHIs to discover const/copy propagation
opportunities. */
NEXT_PASS (pass_phi_only_cprop);
NEXT_PASS (pass_dse);
NEXT_PASS (pass_reassoc);
NEXT_PASS (pass_dce);
NEXT_PASS (pass_dse);
NEXT_PASS (pass_forwprop);
NEXT_PASS (pass_phiopt);
NEXT_PASS (pass_object_sizes);
......
2008-08-13 Richard Guenther <rguenther@suse.de>
PR tree-optimization/15255
* gcc.dg/tree-ssa/reassoc-14.c: New testcase.
* gcc.dg/tree-ssa/reassoc-15.c: Likewise.
* gcc.dg/tree-ssa/reassoc-16.c: Likewise.
* gcc.dg/torture/reassoc-1.c: Likewise.
* gcc.dg/tree-ssa/recip-2.c: Adjust.
* gcc.dg/tree-ssa/recip-6.c: Likewise.
* gcc.dg/tree-ssa/recip-7.c: Likewise.
* gfortran.dg/reassoc_4.f: Likewise.
2008-08-12 Janis Johnson <janis187@us.ibm.com>
* gcc.target/i386/pr32000-2.c: Use dg-skip-if for target expression.
......
/* { dg-do run } */
int x;
int __attribute__((noinline))
foo(int a, int b, int w)
{
int tmp1 = a * w;
int tmp2 = b * w;
x = tmp1;
return tmp1 + tmp2;
}
extern void abort (void);
int main()
{
if (foo(1, 2, 3) != 9)
abort ();
if (x != 3)
abort ();
return 0;
}
/* { dg-do compile } */
/* { dg-options "-O2 -fdump-tree-reassoc1" } */
int test1 (int x, int y, int z, int weight)
{
int tmp1 = x * weight;
int tmp2 = y * weight;
int tmp3 = (x - y) * weight;
return tmp1 + (tmp2 + tmp3);
}
int test2 (int x, int y, int z, int weight)
{
int tmp1 = x * weight;
int tmp2 = y * weight * weight;
int tmp3 = z * weight * weight * weight;
return tmp1 + tmp2 + tmp3;
}
/* There should be one multiplication left in test1 and three in test2. */
/* { dg-final { scan-tree-dump-times "\\\*" 4 "reassoc1" } } */
/* { dg-final { cleanup-tree-dump "reassoc1" } } */
/* { dg-do compile } */
/* { dg-options "-O2 -fdump-tree-reassoc1" } */
int test3 (int x, int y, int z, int weight, int w1, int w2, int w3)
{
int wtmp1 = w1 * weight;
int wtmp2 = w2 * weight;
int wtmp3 = w3 * weight;
int tmp1 = x * wtmp1;
int tmp2 = y * wtmp2;
int tmp3 = z * wtmp3;
return tmp1 + tmp2 + tmp3;
}
/* The multiplication with weight should be un-distributed.
??? This pattern is not recognized currently. */
/* { dg-final { scan-tree-dump-times "\\\*" 4 "reassoc1" } } */
/* { dg-final { cleanup-tree-dump "reassoc1" } } */
/* { dg-do compile } */
/* { dg-options "-O2 -ffast-math -fdump-tree-reassoc1" } */
double test1 (double x, double y, double z, double weight)
{
double tmp1 = x / weight;
double tmp2 = y / weight;
double tmp3 = -x / weight;
return tmp1 + tmp2 + tmp3;
}
/* The division should be un-distributed and all references to x should
be gone. */
/* { dg-final { scan-tree-dump-times "/" 1 "reassoc1" } } */
/* { dg-final { cleanup-tree-dump "reassoc1" } } */
/* { dg-do compile } */
/* { dg-options "-O2 -ffast-math -fdump-tree-reassoc1" } */
double test2 (double x, double y, double ddj, int b)
{
double tmp1, tmp2, sum;
sum = 0.0;
if (b)
sum = 1.0;
tmp1 = sum/ddj;
tmp2 = x/ddj;
return tmp1 + y + tmp2;
}
/* { dg-final { scan-tree-dump-times "/" 1 "reassoc1" } } */
/* { dg-final { cleanup-tree-dump "reassoc1" } } */
/* { dg-do compile } */
/* { dg-options "-O -fdump-tree-reassoc1" } */
int
ETree_nFactorEntriesInFront (int b, int m)
{
int nent = b*b + 2*b*m;
return nent;
}
/* { dg-final { scan-tree-dump-times "\\\*" 2 "reassoc1" } } */
/* { dg-final { cleanup-tree-dump "reassoc1" } } */
/* { dg-do compile } */
/* { dg-options "-O1 -funsafe-math-optimizations -fdump-tree-recip" } */
float e(float a, float b, float c, float d, float e, float f)
float u, v, w, x, y, z;
void e(float a, float b, float c, float d, float e, float f)
{
if (a < b)
{
......@@ -20,7 +22,12 @@ float e(float a, float b, float c, float d, float e, float f)
/* This should not be left as a multiplication. */
c = 1 / c;
return a + b + c + d + e + f;
u = a;
v = b;
w = c;
x = d;
y = e;
z = f;
}
/* { dg-final { scan-tree-dump-times " / " 2 "recip" } } */
......
......@@ -5,7 +5,9 @@
extern int f2();
double f1(double y, double z, double w)
double m, n, o;
void f1(double y, double z, double w)
{
double b, c, d, e, f;
......@@ -18,7 +20,9 @@ double f1(double y, double z, double w)
e = c / y;
f = 1 / y;
return d + e + f;
m = d;
n = e;
o = f;
}
/* { dg-final { scan-tree-dump-times " / " 1 "recip" } } */
......
......@@ -5,7 +5,9 @@
extern double h();
double f(int x, double z, double w)
double m, n, o;
void f(int x, double z, double w)
{
double b, c, d, e, f;
double y = h ();
......@@ -19,7 +21,9 @@ double f(int x, double z, double w)
e = c / y;
f = 1 / y;
return d + e + f;
m = d;
n = e;
o = f;
}
/* { dg-final { scan-tree-dump-times " / " 1 "recip" } } */
......
! { dg-do compile }
! { dg-options "-O3 -ffast-math -fdump-tree-reassoc1" }
subroutine anisonl(w,vo,anisox,s,ii1,jj1,weight)
integer ii1,jj1,i1,iii1,j1,jjj1,k1,l1,m1,n1
real*8 w(3,3),vo(3,3),anisox(3,3,3,3),s(60,60),weight
!
! This routine replaces the following lines in e_c3d.f for
! an anisotropic material
!
do i1=1,3
iii1=ii1+i1-1
do j1=1,3
jjj1=jj1+j1-1
do k1=1,3
do l1=1,3
s(iii1,jjj1)=s(iii1,jjj1)
& +anisox(i1,k1,j1,l1)*w(k1,l1)*weight
do m1=1,3
s(iii1,jjj1)=s(iii1,jjj1)
& +anisox(i1,k1,m1,l1)*w(k1,l1)
& *vo(j1,m1)*weight
& +anisox(m1,k1,j1,l1)*w(k1,l1)
& *vo(i1,m1)*weight
do n1=1,3
s(iii1,jjj1)=s(iii1,jjj1)
& +anisox(m1,k1,n1,l1)
& *w(k1,l1)*vo(i1,m1)*vo(j1,n1)*weight
enddo
enddo
enddo
enddo
enddo
enddo
return
end
! There should be 22 multiplications left after un-distributing
! weigth, w(k1,l1), vo(i1,m1) and vo(j1,m1) on the innermost two
! unrolled loops.
! { dg-final { scan-tree-dump-times "\[0-9\] \\\* " 22 "reassoc1" } }
! { dg-final { cleanup-tree-dump "reassoc1" } }
......@@ -2914,6 +2914,12 @@ stmt_dominates_stmt_p (gimple s1, gimple s2)
{
gimple_stmt_iterator bsi;
if (gimple_code (s2) == GIMPLE_PHI)
return false;
if (gimple_code (s1) == GIMPLE_PHI)
return true;
for (bsi = gsi_start_bb (bb1); gsi_stmt (bsi) != s2; gsi_next (&bsi))
if (gsi_stmt (bsi) == s1)
return true;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment