From: Richard Guenther Date: Tue, 3 Jan 2012 12:11:41 +0000 (+0000) Subject: re PR tree-optimization/51070 (ICE verify_gimple failed) X-Git-Tag: releases/gcc-4.6.3~210 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=21473d36d5b068d4aeb4eff2983c1c54843d6fa0;p=thirdparty%2Fgcc.git re PR tree-optimization/51070 (ICE verify_gimple failed) 2012-01-03 Richard Guenther PR tree-optimization/51070 * tree-loop-distribution.c (generate_builtin): Do not replace the loop with a builtin if the partition contains statements which results are used outside of the loop. (stmt_has_scalar_dependences_outside_loop): Properly handle calls. * gcc.dg/torture/pr51070.c: New testcase. * gcc.dg/torture/pr51070-2.c: Likewise. From-SVN: r182840 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 3352bdfc8270..6e4fe5c2c0ff 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2012-01-03 Richard Guenther + + PR tree-optimization/51070 + * tree-loop-distribution.c (generate_builtin): Do not replace + the loop with a builtin if the partition contains statements which + results are used outside of the loop. + (stmt_has_scalar_dependences_outside_loop): Properly handle calls. + 2011-12-30 Michael Meissner Backport from the mainline diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index d2b3eb91a557..b6ec7b7b1b06 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2012-01-03 Richard Guenther + + PR tree-optimization/51070 + * gcc.dg/torture/pr51070.c: New testcase. + * gcc.dg/torture/pr51070-2.c: Likewise. + 2011-12-20 Dodji Seketeli PR debug/49951 diff --git a/gcc/testsuite/gcc.dg/torture/pr51070-2.c b/gcc/testsuite/gcc.dg/torture/pr51070-2.c new file mode 100644 index 000000000000..f21eb3acbd76 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr51070-2.c @@ -0,0 +1,35 @@ +/* { dg-do compile } */ +/* { dg-options "-fno-inline" } */ + +int +func_4 (int si1, int si2) +{ + return si1; +} + +int +func_14 (int left, int right) +{ + return 1; +} + +int +func_37 (int left, int right) +{ + return left; +} + +int g_92[1024]; +int g_95[1024]; +int g_224; +int g_352[1024]; +int +func_9 () +{ + for (; g_224; g_224 += 1) + { + g_95[0] = func_4 (func_37 (g_92[g_224], 0), 0); + g_92[g_224] = 0, g_352[g_224] = func_14 (0, 0); + } + return 0; +} diff --git a/gcc/testsuite/gcc.dg/torture/pr51070.c b/gcc/testsuite/gcc.dg/torture/pr51070.c new file mode 100644 index 000000000000..cc06a90c8434 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr51070.c @@ -0,0 +1,34 @@ +/* { dg-do compile } */ + +int +func_4 (int si1, int si2) +{ + return si1; +} + +int +func_14 (int left, int right) +{ + return 1; +} + +int +func_37 (int left, int right) +{ + return left; +} + +int g_92[1024]; +int g_95[1024]; +int g_224; +int g_352[1024]; +int +func_9 () +{ + for (; g_224; g_224 += 1) + { + g_95[0] = func_4 (func_37 (g_92[g_224], 0), 0); + g_92[g_224] = 0, g_352[g_224] = func_14 (0, 0); + } + return 0; +} diff --git a/gcc/tree-loop-distribution.c b/gcc/tree-loop-distribution.c index 1d6944eef963..6b9b98d6b11b 100644 --- a/gcc/tree-loop-distribution.c +++ b/gcc/tree-loop-distribution.c @@ -63,6 +63,51 @@ static bitmap remaining_stmts; predecessor a node that writes to memory. */ static bitmap upstream_mem_writes; +/* Returns true when DEF is an SSA_NAME defined in LOOP and used after + the LOOP. */ + +static bool +ssa_name_has_uses_outside_loop_p (tree def, loop_p loop) +{ + imm_use_iterator imm_iter; + use_operand_p use_p; + + FOR_EACH_IMM_USE_FAST (use_p, imm_iter, def) + if (loop != loop_containing_stmt (USE_STMT (use_p))) + return true; + + return false; +} + +/* Returns true when STMT defines a scalar variable used after the + loop. */ + +static bool +stmt_has_scalar_dependences_outside_loop (gimple stmt) +{ + tree name; + + switch (gimple_code (stmt)) + { + case GIMPLE_CALL: + case GIMPLE_ASSIGN: + name = gimple_get_lhs (stmt); + break; + + case GIMPLE_PHI: + name = gimple_phi_result (stmt); + break; + + default: + return false; + } + + return (name + && TREE_CODE (name) == SSA_NAME + && ssa_name_has_uses_outside_loop_p (name, + loop_containing_stmt (stmt))); +} + /* Update the PHI nodes of NEW_LOOP. NEW_LOOP is a duplicate of ORIG_LOOP. */ @@ -332,10 +377,18 @@ generate_builtin (struct loop *loop, bitmap partition, bool copy_p) { gimple stmt = gsi_stmt (bsi); - if (gimple_code (stmt) != GIMPLE_LABEL - && !is_gimple_debug (stmt) - && bitmap_bit_p (partition, x++) - && is_gimple_assign (stmt) + if (gimple_code (stmt) == GIMPLE_LABEL + || is_gimple_debug (stmt)) + continue; + + if (!bitmap_bit_p (partition, x++)) + continue; + + /* If the stmt has uses outside of the loop fail. */ + if (stmt_has_scalar_dependences_outside_loop (stmt)) + goto end; + + if (is_gimple_assign (stmt) && !is_gimple_reg (gimple_assign_lhs (stmt))) { /* Don't generate the builtins when there are more than @@ -826,48 +879,6 @@ fuse_partitions_with_similar_memory_accesses (struct graph *rdg, } } -/* Returns true when DEF is an SSA_NAME defined in LOOP and used after - the LOOP. */ - -static bool -ssa_name_has_uses_outside_loop_p (tree def, loop_p loop) -{ - imm_use_iterator imm_iter; - use_operand_p use_p; - - FOR_EACH_IMM_USE_FAST (use_p, imm_iter, def) - if (loop != loop_containing_stmt (USE_STMT (use_p))) - return true; - - return false; -} - -/* Returns true when STMT defines a scalar variable used after the - loop. */ - -static bool -stmt_has_scalar_dependences_outside_loop (gimple stmt) -{ - tree name; - - switch (gimple_code (stmt)) - { - case GIMPLE_ASSIGN: - name = gimple_assign_lhs (stmt); - break; - - case GIMPLE_PHI: - name = gimple_phi_result (stmt); - break; - - default: - return false; - } - - return TREE_CODE (name) == SSA_NAME - && ssa_name_has_uses_outside_loop_p (name, loop_containing_stmt (stmt)); -} - /* Returns true when STMT will be code generated in a partition of RDG different than PART and that will not be code generated as a builtin. */