From: Jakub Jelinek Date: Fri, 20 May 2011 14:19:05 +0000 (+0200) Subject: re PR tree-optimization/49073 (g++ optimizer breaks do-while code) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=6c66f73369dacc9889cfaa05f8a08813e7c45f1f;p=gcc.git re PR tree-optimization/49073 (g++ optimizer breaks do-while code) PR tree-optimization/49073 * gimple-fold.c (and_comparisons_1, or_comparisons_1): Return NULL if PHI argument is SSA_NAME, whose def_stmt is dominated by the PHI. * tree-ssa-ifcombine.c (tree_ssa_ifcombine): Calculate dominators. * gcc.c-torture/execute/pr49073.c: New test. From-SVN: r173948 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 3bd18b854b8..7a99c9133bf 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2011-05-20 Jakub Jelinek + + PR tree-optimization/49073 + * gimple-fold.c (and_comparisons_1, or_comparisons_1): Return + NULL if PHI argument is SSA_NAME, whose def_stmt is dominated + by the PHI. + * tree-ssa-ifcombine.c (tree_ssa_ifcombine): Calculate dominators. + 2011-05-20 Richard Guenther PR middle-end/48849 diff --git a/gcc/gimple-fold.c b/gcc/gimple-fold.c index e5303e31f7e..933a47b0106 100644 --- a/gcc/gimple-fold.c +++ b/gcc/gimple-fold.c @@ -1,5 +1,5 @@ /* Statement simplification on GIMPLE. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010, 2011 Free Software Foundation, Inc. Split out from tree-ssa-ccp.c. This file is part of GCC. @@ -2278,8 +2278,19 @@ and_comparisons_1 (enum tree_code code1, tree op1a, tree op1b, } else if (TREE_CODE (arg) == SSA_NAME) { - tree temp = and_var_with_comparison (arg, invert, - code2, op2a, op2b); + tree temp; + gimple def_stmt = SSA_NAME_DEF_STMT (arg); + /* In simple cases we can look through PHI nodes, + but we have to be careful with loops. + See PR49073. */ + if (! dom_info_available_p (CDI_DOMINATORS) + || gimple_bb (def_stmt) == gimple_bb (stmt) + || dominated_by_p (CDI_DOMINATORS, + gimple_bb (def_stmt), + gimple_bb (stmt))) + return NULL_TREE; + temp = and_var_with_comparison (arg, invert, code2, + op2a, op2b); if (!temp) return NULL_TREE; else if (!result) @@ -2728,8 +2739,19 @@ or_comparisons_1 (enum tree_code code1, tree op1a, tree op1b, } else if (TREE_CODE (arg) == SSA_NAME) { - tree temp = or_var_with_comparison (arg, invert, - code2, op2a, op2b); + tree temp; + gimple def_stmt = SSA_NAME_DEF_STMT (arg); + /* In simple cases we can look through PHI nodes, + but we have to be careful with loops. + See PR49073. */ + if (! dom_info_available_p (CDI_DOMINATORS) + || gimple_bb (def_stmt) == gimple_bb (stmt) + || dominated_by_p (CDI_DOMINATORS, + gimple_bb (def_stmt), + gimple_bb (stmt))) + return NULL_TREE; + temp = or_var_with_comparison (arg, invert, code2, + op2a, op2b); if (!temp) return NULL_TREE; else if (!result) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index c3a1f83e2ae..5e2bffedcc6 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2011-05-20 Jakub Jelinek + + PR tree-optimization/49073 + * gcc.c-torture/execute/pr49073.c: New test. + 2011-06-19 Tobias Burnus PR fortran/18918 diff --git a/gcc/testsuite/gcc.c-torture/execute/pr49073.c b/gcc/testsuite/gcc.c-torture/execute/pr49073.c new file mode 100644 index 00000000000..92b923b8258 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr49073.c @@ -0,0 +1,26 @@ +/* PR tree-optimization/49073 */ + +extern void abort (void); +int a[] = { 1, 2, 3, 4, 5, 6, 7 }, c; + +int +main () +{ + int d = 1, i = 1; + _Bool f = 0; + do + { + d = a[i]; + if (f && d == 4) + { + ++c; + break; + } + i++; + f = (d == 3); + } + while (d < 7); + if (c != 1) + abort (); + return 0; +} diff --git a/gcc/tree-ssa-ifcombine.c b/gcc/tree-ssa-ifcombine.c index e23bb763d19..9063bfdcd55 100644 --- a/gcc/tree-ssa-ifcombine.c +++ b/gcc/tree-ssa-ifcombine.c @@ -1,5 +1,5 @@ /* Combining of if-expressions on trees. - Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc. + Copyright (C) 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc. Contributed by Richard Guenther This file is part of GCC. @@ -625,6 +625,7 @@ tree_ssa_ifcombine (void) int i; bbs = blocks_in_phiopt_order (); + calculate_dominance_info (CDI_DOMINATORS); for (i = 0; i < n_basic_blocks - NUM_FIXED_BLOCKS; ++i) {