From 7c66a2d88e43a1200f01cfc047bb6f30afd19145 Mon Sep 17 00:00:00 2001 From: dberlin Date: Wed, 16 Mar 2005 16:20:12 +0000 Subject: [PATCH] 2005-03-16 Daniel Berlin Fix PR tree-optimization/20940 * tree-ssa-pre.c (create_expression_by_pieces): Use force_gimple_operand on result of fold. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@96560 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 7 +++++++ gcc/testsuite/gcc.dg/tree-ssa/pr20940.c | 20 ++++++++++++++++++++ gcc/tree-ssa-pre.c | 25 +++++++++++++++++++++---- 3 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr20940.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 2afc12f7ba6..e1fffe15bcf 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2005-03-16 Daniel Berlin + + Fix PR tree-optimization/20940 + + * tree-ssa-pre.c (create_expression_by_pieces): Use + force_gimple_operand on result of fold. + 2005-03-16 Andrew Pinski * config/i386/emmintrin.h (_mm_extract_epi16): Correct the number diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr20940.c b/gcc/testsuite/gcc.dg/tree-ssa/pr20940.c new file mode 100644 index 00000000000..8edc35e8a45 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr20940.c @@ -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); + +} + + diff --git a/gcc/tree-ssa-pre.c b/gcc/tree-ssa-pre.c index e179f0ce792..161d7e5a12c 100644 --- a/gcc/tree-ssa-pre.c +++ b/gcc/tree-ssa-pre.c @@ -1317,16 +1317,25 @@ create_expression_by_pieces (basic_block block, tree expr, tree stmts) 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 block, tree expr, tree stmts) 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); -- 2.11.4.GIT