]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR middle-end/38932 (ICE in set_value_range, at tree-vrp.c:398)
authorPaolo Bonzini <bonzini@gnu.org>
Fri, 23 Jan 2009 15:57:19 +0000 (15:57 +0000)
committerPaolo Bonzini <bonzini@gcc.gnu.org>
Fri, 23 Jan 2009 15:57:19 +0000 (15:57 +0000)
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

gcc/ChangeLog
gcc/fold-const.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr38932.c [new file with mode: 0644]
gcc/tree-ssa-ccp.c
gcc/tree-ssa-sccvn.c
gcc/tree.h

index 2cfe41ae88e132d53021dbcc77003b0afe14927a..2697a7fd18932bb065be916c0204b0dfbaf6b844 100644 (file)
@@ -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
index eb7d7c91210d643b9425f9956ac130d210213b7e..da4d50d5e9496e4931d239c7631362d0405f662e 100644 (file)
@@ -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,
index fa590a3a18c127cdb496228f587f4bdb6c9f78dc..6d266aefe400323ece5c73555ebb26a044cffcc7 100644 (file)
@@ -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 (file)
index 0000000..4dfaffc
--- /dev/null
@@ -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 ();
+}
+
+
index d0fcf3937a73ea9f890159baa2a376162c8932dd..ef6890c65c3024dd33992df2aadc089b4127e2ee 100644 (file)
@@ -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:
index 78af47ed5ebca88cf654b5331da119783e982ad8..d9d5bc27d763826e8c98c10431be5ee6d7f04b90 100644 (file)
@@ -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);
index 55163b6c1b7a5b7a0ca8e4eb015ef9a296a26f95..b7300fa8b876a0c1382c6fbebc7132cd77cc6d50 100644 (file)
@@ -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);