tree-scalar-evolution.c (follow_ssa_edge_expr): Turn into CASE_CONVERT.

* tree-scalar-evolution.c (follow_ssa_edge_expr) <NOP_EXPR>: Turn
	into CASE_CONVERT.
	<PLUS_EXPR>: Strip useless type conversions instead of type nops.
	Propagate the type of the first operand.
	<ASSERT_EXPR>: Simplify.
	(follow_ssa_edge_in_rhs): Use gimple_expr_type to get the type.
	Rewrite using the RHS code as discriminant.
	<NOP_EXPR>: Turn into CASE_CONVERT.
	<PLUS_EXPR>: Propagate the type of the first operand.

From-SVN: r147716
This commit is contained in:
Eric Botcazou 2009-05-19 19:14:42 +00:00 committed by Eric Botcazou
parent c8036448d1
commit 5aefc6a0f0
5 changed files with 95 additions and 47 deletions

View File

@ -1,3 +1,15 @@
2009-05-19 Eric Botcazou <ebotcazou@adacore.com>
* tree-scalar-evolution.c (follow_ssa_edge_expr) <NOP_EXPR>: Turn
into CASE_CONVERT.
<PLUS_EXPR>: Strip useless type conversions instead of type nops.
Propagate the type of the first operand.
<ASSERT_EXPR>: Simplify.
(follow_ssa_edge_in_rhs): Use gimple_expr_type to get the type.
Rewrite using the RHS code as discriminant.
<NOP_EXPR>: Turn into CASE_CONVERT.
<PLUS_EXPR>: Propagate the type of the first operand.
2009-05-19 Steve Ellcey <sje@cup.hp.com> 2009-05-19 Steve Ellcey <sje@cup.hp.com>
* config/ia64/ia64-protos.h (ia64_dconst_0_5): New. * config/ia64/ia64-protos.h (ia64_dconst_0_5): New.

View File

@ -1,3 +1,7 @@
2009-05-19 Eric Botcazou <ebotcazou@adacore.com>
* gnat.dg/loop_optimization6.ad[sb]: New test.
2009-05-19 Richard Guenther <rguenther@suse.de> 2009-05-19 Richard Guenther <rguenther@suse.de>
* gcc.c-torture/compile/20090519-1.c: New testcase. * gcc.c-torture/compile/20090519-1.c: New testcase.

View File

@ -0,0 +1,25 @@
-- { dg-do compile }
-- { dg-options "-O -gnatp -fdump-tree-optimized" }
package body Loop_Optimization6 is
procedure Foo is
begin
for I in 1 .. 1_000_000 loop
A := A + 1;
end loop;
end Foo;
procedure Bar is
begin
for J in 1 .. 1_000 loop
Foo;
end loop;
end Bar;
procedure Main is
begin
Bar;
end;
end Loop_Optimization6;
-- { dg-final { scan-tree-dump-not "goto" "optimized"} }

View File

@ -0,0 +1,4 @@
package Loop_Optimization6 is
A : Integer := 0;
procedure Main;
end Loop_Optimization6;

View File

@ -1141,11 +1141,10 @@ static t_bool
follow_ssa_edge_expr (struct loop *loop, gimple at_stmt, tree expr, follow_ssa_edge_expr (struct loop *loop, gimple at_stmt, tree expr,
gimple halting_phi, tree *evolution_of_loop, int limit) gimple halting_phi, tree *evolution_of_loop, int limit)
{ {
t_bool res = t_false; enum tree_code code = TREE_CODE (expr);
tree rhs0, rhs1; tree type = TREE_TYPE (expr), rhs0, rhs1;
tree type = TREE_TYPE (expr); t_bool res;
enum tree_code code;
/* The EXPR is one of the following cases: /* The EXPR is one of the following cases:
- an SSA_NAME, - an SSA_NAME,
- an INTEGER_CST, - an INTEGER_CST,
@ -1154,10 +1153,10 @@ follow_ssa_edge_expr (struct loop *loop, gimple at_stmt, tree expr,
- a MINUS_EXPR, - a MINUS_EXPR,
- an ASSERT_EXPR, - an ASSERT_EXPR,
- other cases are not yet handled. */ - other cases are not yet handled. */
code = TREE_CODE (expr);
switch (code) switch (code)
{ {
case NOP_EXPR: CASE_CONVERT:
/* This assignment is under the form "a_1 = (cast) rhs. */ /* This assignment is under the form "a_1 = (cast) rhs. */
res = follow_ssa_edge_expr (loop, at_stmt, TREE_OPERAND (expr, 0), res = follow_ssa_edge_expr (loop, at_stmt, TREE_OPERAND (expr, 0),
halting_phi, evolution_of_loop, limit); halting_phi, evolution_of_loop, limit);
@ -1168,43 +1167,42 @@ follow_ssa_edge_expr (struct loop *loop, gimple at_stmt, tree expr,
/* This assignment is under the form "a_1 = 7". */ /* This assignment is under the form "a_1 = 7". */
res = t_false; res = t_false;
break; break;
case SSA_NAME: case SSA_NAME:
/* This assignment is under the form: "a_1 = b_2". */ /* This assignment is under the form: "a_1 = b_2". */
res = follow_ssa_edge res = follow_ssa_edge
(loop, SSA_NAME_DEF_STMT (expr), halting_phi, evolution_of_loop, limit); (loop, SSA_NAME_DEF_STMT (expr), halting_phi, evolution_of_loop, limit);
break; break;
case POINTER_PLUS_EXPR: case POINTER_PLUS_EXPR:
case PLUS_EXPR: case PLUS_EXPR:
case MINUS_EXPR: case MINUS_EXPR:
/* This case is under the form "rhs0 +- rhs1". */ /* This case is under the form "rhs0 +- rhs1". */
rhs0 = TREE_OPERAND (expr, 0); rhs0 = TREE_OPERAND (expr, 0);
rhs1 = TREE_OPERAND (expr, 1); rhs1 = TREE_OPERAND (expr, 1);
STRIP_TYPE_NOPS (rhs0); type = TREE_TYPE (rhs0);
STRIP_TYPE_NOPS (rhs1); STRIP_USELESS_TYPE_CONVERSION (rhs0);
return follow_ssa_edge_binary (loop, at_stmt, type, rhs0, code, rhs1, STRIP_USELESS_TYPE_CONVERSION (rhs1);
halting_phi, evolution_of_loop, limit); res = follow_ssa_edge_binary (loop, at_stmt, type, rhs0, code, rhs1,
halting_phi, evolution_of_loop, limit);
break;
case ASSERT_EXPR: case ASSERT_EXPR:
{ /* This assignment is of the form: "a_1 = ASSERT_EXPR <a_2, ...>"
/* This assignment is of the form: "a_1 = ASSERT_EXPR <a_2, ...>" It must be handled as a copy assignment of the form a_1 = a_2. */
It must be handled as a copy assignment of the form a_1 = a_2. */ rhs0 = ASSERT_EXPR_VAR (expr);
tree op0 = ASSERT_EXPR_VAR (expr); if (TREE_CODE (rhs0) == SSA_NAME)
if (TREE_CODE (op0) == SSA_NAME) res = follow_ssa_edge (loop, SSA_NAME_DEF_STMT (rhs0),
res = follow_ssa_edge (loop, SSA_NAME_DEF_STMT (op0), halting_phi, evolution_of_loop, limit);
halting_phi, evolution_of_loop, limit); else
else res = t_false;
res = t_false; break;
break;
}
default: default:
res = t_false; res = t_false;
break; break;
} }
return res; return res;
} }
@ -1215,34 +1213,39 @@ static t_bool
follow_ssa_edge_in_rhs (struct loop *loop, gimple stmt, follow_ssa_edge_in_rhs (struct loop *loop, gimple stmt,
gimple halting_phi, tree *evolution_of_loop, int limit) gimple halting_phi, tree *evolution_of_loop, int limit)
{ {
tree type = TREE_TYPE (gimple_assign_lhs (stmt));
enum tree_code code = gimple_assign_rhs_code (stmt); enum tree_code code = gimple_assign_rhs_code (stmt);
tree type = gimple_expr_type (stmt), rhs1, rhs2;
t_bool res;
switch (get_gimple_rhs_class (code)) switch (code)
{ {
case GIMPLE_BINARY_RHS: CASE_CONVERT:
return follow_ssa_edge_binary (loop, stmt, type, /* This assignment is under the form "a_1 = (cast) rhs. */
gimple_assign_rhs1 (stmt), code, res = follow_ssa_edge_expr (loop, stmt, gimple_assign_rhs1 (stmt),
gimple_assign_rhs2 (stmt), halting_phi, evolution_of_loop, limit);
halting_phi, evolution_of_loop, limit); *evolution_of_loop = chrec_convert (type, *evolution_of_loop, stmt);
case GIMPLE_SINGLE_RHS: break;
return follow_ssa_edge_expr (loop, stmt, gimple_assign_rhs1 (stmt),
halting_phi, evolution_of_loop, limit); case POINTER_PLUS_EXPR:
case GIMPLE_UNARY_RHS: case PLUS_EXPR:
if (code == NOP_EXPR) case MINUS_EXPR:
{ rhs1 = gimple_assign_rhs1 (stmt);
/* This assignment is under the form "a_1 = (cast) rhs. */ rhs2 = gimple_assign_rhs2 (stmt);
t_bool res type = TREE_TYPE (rhs1);
= follow_ssa_edge_expr (loop, stmt, gimple_assign_rhs1 (stmt), res = follow_ssa_edge_binary (loop, stmt, type, rhs1, code, rhs2,
halting_phi, evolution_of_loop, limit); halting_phi, evolution_of_loop, limit);
*evolution_of_loop = chrec_convert (type, *evolution_of_loop, stmt); break;
return res;
}
/* FALLTHRU */
default: default:
return t_false; if (get_gimple_rhs_class (code) == GIMPLE_SINGLE_RHS)
res = follow_ssa_edge_expr (loop, stmt, gimple_assign_rhs1 (stmt),
halting_phi, evolution_of_loop, limit);
else
res = t_false;
break;
} }
return res;
} }
/* Checks whether the I-th argument of a PHI comes from a backedge. */ /* Checks whether the I-th argument of a PHI comes from a backedge. */