aboutsummaryrefslogtreecommitdiff
path: root/gcc/gimple-fold.c
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2011-05-20 16:19:05 +0200
committerJakub Jelinek <jakub@gcc.gnu.org>2011-05-20 16:19:05 +0200
commit6c66f73369dacc9889cfaa05f8a08813e7c45f1f (patch)
tree940cae516f3f04771fe6a0abd862dd3ee83bd9da /gcc/gimple-fold.c
parent57b4d355a187943b042ca3e9a86bccf74c0e0d84 (diff)
downloadgcc-6c66f73369dacc9889cfaa05f8a08813e7c45f1f.zip
gcc-6c66f73369dacc9889cfaa05f8a08813e7c45f1f.tar.gz
gcc-6c66f73369dacc9889cfaa05f8a08813e7c45f1f.tar.bz2
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
Diffstat (limited to 'gcc/gimple-fold.c')
-rw-r--r--gcc/gimple-fold.c32
1 files changed, 27 insertions, 5 deletions
diff --git a/gcc/gimple-fold.c b/gcc/gimple-fold.c
index e5303e3..933a47b 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)