This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Fix PR tree-optimization/20940
- From: Daniel Berlin <dberlin at dberlin dot org>
- To: gcc-patches at gcc dot gnu dot org
- Date: Wed, 16 Mar 2005 11:10:27 -0500
- Subject: Fix PR tree-optimization/20940
This is a case where fold now returns non-GIMPLE, and we put it in the
RHS anyway.
Roger Sayle wants fold to be able to return anything it likes, and have
the optimizers deal with the results.
I have no problem with this :)
As a result, rather than change fold to return GIMPLE in this case, i've
added the approriate force_gimple_operand code to tree-ssa-pre.c.
Bootstrapped and regtested on i686-pc-linux-gnu.
Committed to mainline.
--Dan
2005-03-15 Daniel Berlin <dberlin@dberlin.org>
Fix PR tree-optimization/20940
* tree-ssa-pre.c (create_expression_by_pieces): Use
force_gimple_operand on result of fold.
Index: tree-ssa-pre.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-ssa-pre.c,v
retrieving revision 2.70
diff -u -p -r2.70 tree-ssa-pre.c
--- tree-ssa-pre.c 12 Mar 2005 14:07:53 -0000 2.70
+++ tree-ssa-pre.c 16 Mar 2005 16:05:44 -0000
@@ -1317,16 +1317,25 @@ create_expression_by_pieces (basic_block
case tcc_binary:
{
tree_stmt_iterator tsi;
+ tree forced_stmts;
tree genop1, genop2;
tree temp;
+ tree folded;
tree op1 = TREE_OPERAND (expr, 0);
tree op2 = TREE_OPERAND (expr, 1);
genop1 = find_or_generate_expression (block, op1, stmts);
genop2 = find_or_generate_expression (block, op2, stmts);
temp = create_tmp_var (TREE_TYPE (expr), "pretmp");
add_referenced_tmp_var (temp);
- newexpr = fold (build (TREE_CODE (expr), TREE_TYPE (expr),
- genop1, genop2));
+
+ folded = fold (build (TREE_CODE (expr), TREE_TYPE (expr),
+ genop1, genop2));
+ newexpr = force_gimple_operand (folded, &forced_stmts, false, NULL);
+ if (forced_stmts)
+ {
+ tsi = tsi_last (stmts);
+ tsi_link_after (&tsi, forced_stmts, TSI_CONTINUE_LINKING);
+ }
newexpr = build (MODIFY_EXPR, TREE_TYPE (expr),
temp, newexpr);
NECESSARY (newexpr) = 0;
@@ -1341,14 +1350,22 @@ create_expression_by_pieces (basic_block
case tcc_unary:
{
tree_stmt_iterator tsi;
+ tree forced_stmts;
tree genop1;
tree temp;
+ tree folded;
tree op1 = TREE_OPERAND (expr, 0);
genop1 = find_or_generate_expression (block, op1, stmts);
temp = create_tmp_var (TREE_TYPE (expr), "pretmp");
add_referenced_tmp_var (temp);
- newexpr = fold (build (TREE_CODE (expr), TREE_TYPE (expr),
- genop1));
+ folded = fold (build (TREE_CODE (expr), TREE_TYPE (expr),
+ genop1));
+ newexpr = force_gimple_operand (folded, &forced_stmts, false, NULL);
+ if (forced_stmts)
+ {
+ tsi = tsi_last (stmts);
+ tsi_link_after (&tsi, forced_stmts, TSI_CONTINUE_LINKING);
+ }
newexpr = build (MODIFY_EXPR, TREE_TYPE (expr),
temp, newexpr);
name = make_ssa_name (temp, newexpr);
Index: testsuite/gcc.dg/tree-ssa/pr20940.c
===================================================================
RCS file: testsuite/gcc.dg/tree-ssa/pr20940.c
diff -N testsuite/gcc.dg/tree-ssa/pr20940.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ testsuite/gcc.dg/tree-ssa/pr20940.c 16 Mar 2005 16:05:48 -0000
@@ -0,0 +1,20 @@
+/* { dg-do compile } */
+/* { dg-options "-O -ftree-pre" } */
+static int a;
+static int b;
+
+typedef int gint;
+
+int blah ()
+{
+ gint x = a;
+ gint y = b;
+
+ x *= (x < 0) ? -1 : 0;
+ y *= (y < 0) ? -1 : 0;
+
+ return (y * x);
+
+}
+
+