aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaolo Bonzini <bonzini@gnu.org>2009-01-23 15:57:19 +0000
committerPaolo Bonzini <bonzini@gcc.gnu.org>2009-01-23 15:57:19 +0000
commit9bacafeb4c9efa2344620a8fdb79a2ea5aadfbad (patch)
treeaacb078bea4cd0815736d26fb8837d2a3a40112b
parent63e505333c7eae301e810d9b84d12a2149e81970 (diff)
downloadgcc-9bacafeb4c9efa2344620a8fdb79a2ea5aadfbad.zip
gcc-9bacafeb4c9efa2344620a8fdb79a2ea5aadfbad.tar.gz
gcc-9bacafeb4c9efa2344620a8fdb79a2ea5aadfbad.tar.bz2
re PR middle-end/38932 (ICE in set_value_range, at tree-vrp.c:398)
2008-01-23 Paolo Bonzini <bonzini@gnu.org> PR tree-optimization/38932 * fold-const.c (fold_unary_no_overflow): New. * tree.h (fold_unary_no_overflow): Declare. * tree-ssa-ccp.c (ccp_fold): Use fold_unary_no_overflow. * tree-ssa-sccvn.c (visit_reference_op_load, simplify_unary_expression): Likewise. testsuite: 2008-01-23 Paolo Bonzini <bonzini@gnu.org> PR tree-optimization/38932 * gcc.dg/pr38932.c: New. From-SVN: r143588
-rw-r--r--gcc/ChangeLog9
-rw-r--r--gcc/fold-const.c18
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gcc.dg/pr38932.c19
-rw-r--r--gcc/tree-ssa-ccp.c17
-rw-r--r--gcc/tree-ssa-sccvn.c9
-rw-r--r--gcc/tree.h1
7 files changed, 59 insertions, 19 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 2cfe41a..2697a7f 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,12 @@
+2008-01-23 Paolo Bonzini <bonzini@gnu.org>
+
+ PR tree-optimization/38932
+ * fold-const.c (fold_unary_ignore_overflow): New.
+ * tree.h (fold_unary_ignore_overflow): Declare.
+ * tree-ssa-ccp.c (ccp_fold): Use fold_unary_ignore_overflow.
+ * tree-ssa-sccvn.c (visit_reference_op_load,
+ simplify_unary_expression): Likewise.
+
2009-01-22 Adam Nemet <anemet@caviumnetworks.com>
* c-decl.c (finish_struct): Move code to set DECL_PACKED after
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index eb7d7c9..da4d50d 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -8628,6 +8628,24 @@ fold_unary (enum tree_code code, tree type, tree op0)
} /* switch (code) */
}
+
+/* If the operation was a conversion do _not_ mark a resulting constant
+ with TREE_OVERFLOW if the original constant was not. These conversions
+ have implementation defined behavior and retaining the TREE_OVERFLOW
+ flag here would confuse later passes such as VRP. */
+tree
+fold_unary_ignore_overflow (enum tree_code code, tree type, tree op0)
+{
+ tree res = fold_unary (code, type, op0);
+ if (res
+ && TREE_CODE (res) == INTEGER_CST
+ && TREE_CODE (op0) == INTEGER_CST
+ && CONVERT_EXPR_CODE_P (code))
+ TREE_OVERFLOW (res) = TREE_OVERFLOW (op0);
+
+ return res;
+}
+
/* Fold a binary expression of code CODE and type TYPE with operands
OP0 and OP1, containing either a MIN-MAX or a MAX-MIN combination.
Return the folded expression if folding is successful. Otherwise,
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index fa590a3..6d266ae 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2008-01-23 Paolo Bonzini <bonzini@gnu.org>
+
+ PR tree-optimization/38932
+ * gcc.dg/pr38932.c: New.
+
2009-01-23 Revital Eres <eres@il.ibm.com>
* gcc.dg/sms-7.c: Fix test.
diff --git a/gcc/testsuite/gcc.dg/pr38932.c b/gcc/testsuite/gcc.dg/pr38932.c
new file mode 100644
index 0000000..4dfaffc
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr38932.c
@@ -0,0 +1,19 @@
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+/* This variable needed only to exercise FRE instead of CCP. */
+unsigned char g;
+
+extern void abort();
+
+void f (long long int p)
+{
+ g = 255;
+ if (p >= (-9223372036854775807LL - 1) - (signed char) g)
+ p = 1;
+
+ if (p)
+ abort ();
+}
+
+
diff --git a/gcc/tree-ssa-ccp.c b/gcc/tree-ssa-ccp.c
index d0fcf39..ef6890c 100644
--- a/gcc/tree-ssa-ccp.c
+++ b/gcc/tree-ssa-ccp.c
@@ -966,7 +966,6 @@ ccp_fold (gimple stmt)
so this should almost always return a simplified RHS. */
tree lhs = gimple_assign_lhs (stmt);
tree op0 = gimple_assign_rhs1 (stmt);
- tree res;
/* Simplify the operand down to a constant. */
if (TREE_CODE (op0) == SSA_NAME)
@@ -1002,20 +1001,8 @@ ccp_fold (gimple stmt)
return op0;
}
- res = fold_unary (subcode, gimple_expr_type (stmt), op0);
-
- /* If the operation was a conversion do _not_ mark a
- resulting constant with TREE_OVERFLOW if the original
- constant was not. These conversions have implementation
- defined behavior and retaining the TREE_OVERFLOW flag
- here would confuse later passes such as VRP. */
- if (res
- && TREE_CODE (res) == INTEGER_CST
- && TREE_CODE (op0) == INTEGER_CST
- && CONVERT_EXPR_CODE_P (subcode))
- TREE_OVERFLOW (res) = TREE_OVERFLOW (op0);
-
- return res;
+ return fold_unary_ignore_overflow (subcode,
+ gimple_expr_type (stmt), op0);
}
case GIMPLE_BINARY_RHS:
diff --git a/gcc/tree-ssa-sccvn.c b/gcc/tree-ssa-sccvn.c
index 78af47e..d9d5bc2 100644
--- a/gcc/tree-ssa-sccvn.c
+++ b/gcc/tree-ssa-sccvn.c
@@ -1761,7 +1761,8 @@ visit_reference_op_load (tree lhs, tree op, gimple stmt)
tree tem = valueize_expr (vn_get_expr_for (TREE_OPERAND (val, 0)));
if ((CONVERT_EXPR_P (tem)
|| TREE_CODE (tem) == VIEW_CONVERT_EXPR)
- && (tem = fold_unary (TREE_CODE (val), TREE_TYPE (val), tem)))
+ && (tem = fold_unary_ignore_overflow (TREE_CODE (val),
+ TREE_TYPE (val), tem)))
val = tem;
}
result = val;
@@ -2123,7 +2124,7 @@ simplify_binary_expression (gimple stmt)
fold_defer_overflow_warnings ();
result = fold_binary (gimple_assign_rhs_code (stmt),
- TREE_TYPE (gimple_get_lhs (stmt)), op0, op1);
+ TREE_TYPE (gimple_get_lhs (stmt)), op0, op1);
if (result)
STRIP_USELESS_TYPE_CONVERSION (result);
@@ -2182,8 +2183,8 @@ simplify_unary_expression (gimple stmt)
if (op0 == orig_op0)
return NULL_TREE;
- result = fold_unary (gimple_assign_rhs_code (stmt),
- gimple_expr_type (stmt), op0);
+ result = fold_unary_ignore_overflow (gimple_assign_rhs_code (stmt),
+ gimple_expr_type (stmt), op0);
if (result)
{
STRIP_USELESS_TYPE_CONVERSION (result);
diff --git a/gcc/tree.h b/gcc/tree.h
index 55163b6..b7300fa 100644
--- a/gcc/tree.h
+++ b/gcc/tree.h
@@ -4733,6 +4733,7 @@ extern tree native_interpret_expr (tree, const unsigned char *, int);
extern tree fold (tree);
extern tree fold_unary (enum tree_code, tree, tree);
+extern tree fold_unary_ignore_overflow (enum tree_code, tree, tree);
extern tree fold_binary (enum tree_code, tree, tree, tree);
extern tree fold_ternary (enum tree_code, tree, tree, tree, tree);
extern tree fold_build1_stat (enum tree_code, tree, tree MEM_STAT_DECL);