]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR tree-optimization/33142 (wrong code with VRP through ABS_EXPR)
authorRichard Guenther <rguenther@suse.de>
Wed, 22 Aug 2007 08:43:53 +0000 (08:43 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Wed, 22 Aug 2007 08:43:53 +0000 (08:43 +0000)
2007-08-22  Richard Guenther  <rguenther@suse.de>

PR tree-optimization/33142
* tree-vrp.c (extract_range_from_unary_expr): Compare with
TYPE_MIN/MAX_VALUE using tree_int_cst_equal.

* gcc.c-torture/execute/pr33142.c: New testcase.

From-SVN: r127691

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/execute/pr33142.c [new file with mode: 0644]
gcc/tree-vrp.c

index 426528bc924b4a074af003782ce91b21a141872a..a6caeb639e7691edbfcb0cd2ed1fd426a9fe5c6f 100644 (file)
@@ -1,3 +1,9 @@
+2007-08-22  Richard Guenther  <rguenther@suse.de>
+
+       PR tree-optimization/33142
+       * tree-vrp.c (extract_range_from_unary_expr): Compare with
+       TYPE_MIN/MAX_VALUE using tree_int_cst_equal.
+
 2007-08-21  Adam Nemet  <anemet@caviumnetworks.com>
 
        * config/mips/predicates.md (const_call_insn_operand): Invoke
index a3c554d2321924380574583e5ee0757276ee8ce3..68aec998e280e4e55ce45d064cfe513e48eda038 100644 (file)
@@ -1,3 +1,8 @@
+2007-08-22  Richard Guenther  <rguenther@suse.de>
+
+       PR tree-optimization/33142
+       * gcc.c-torture/execute/pr33142.c: New testcase.
+
 2007-08-20  Jakub Jelinek  <jakub@redhat.com>
 
        PR c++/32992
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr33142.c b/gcc/testsuite/gcc.c-torture/execute/pr33142.c
new file mode 100644 (file)
index 0000000..7bfc5b5
--- /dev/null
@@ -0,0 +1,16 @@
+int abs(int j);
+extern void abort(void);
+
+__attribute__((noinline)) int lisp_atan2(long dy, long dx) {
+    if (dx <= 0)
+        if (dy > 0)
+            return abs(dx) <= abs(dy);
+    return 0;
+}
+
+int main() {   
+    volatile long dy = 63, dx = -77;
+    if (lisp_atan2(dy, dx))
+        abort();
+    return 0;
+}
index f5b22eac0b7a45eb18d5e06ff83489cf74d7ca1c..8d479c1eed33bdf3bd9381b74225b7a99048db41 100644 (file)
@@ -1523,11 +1523,11 @@ extract_range_from_unary_expr (value_range_t *vr, tree expr)
          -~[MIN, MIN] == ~[MIN, MIN]
          -[MIN, 0] == [0, MAX]  for -fno-wrapv
          -[MIN, 0] == [0, MIN]  for -fwrapv (will be set to varying later)  */
-      min = vr0.max == TYPE_MIN_VALUE (TREE_TYPE (expr))
+      min = tree_int_cst_equal (vr0.max, TYPE_MIN_VALUE (TREE_TYPE (expr)))
            ? TYPE_MIN_VALUE (TREE_TYPE (expr))
            : fold_unary_to_constant (code, TREE_TYPE (expr), vr0.max);
 
-      max = vr0.min == TYPE_MIN_VALUE (TREE_TYPE (expr))
+      max = tree_int_cst_equal (vr0.min, TYPE_MIN_VALUE (TREE_TYPE (expr)))
            ? (vr0.type == VR_ANTI_RANGE || flag_wrapv
               ? TYPE_MIN_VALUE (TREE_TYPE (expr))
               : TYPE_MAX_VALUE (TREE_TYPE (expr)))
@@ -1540,9 +1540,9 @@ extract_range_from_unary_expr (value_range_t *vr, tree expr)
          useful range.  */
       if (flag_wrapv
          && ((vr0.type == VR_RANGE
-              && vr0.min == TYPE_MIN_VALUE (TREE_TYPE (expr)))
+              && tree_int_cst_equal (vr0.min, TYPE_MIN_VALUE (TREE_TYPE (expr))))
              || (vr0.type == VR_ANTI_RANGE
-                 && vr0.min != TYPE_MIN_VALUE (TREE_TYPE (expr))
+                 && !tree_int_cst_equal (vr0.min, TYPE_MIN_VALUE (TREE_TYPE (expr)))
                  && !range_includes_zero_p (&vr0))))
        {
          set_value_range_to_varying (vr);
@@ -1551,7 +1551,7 @@ extract_range_from_unary_expr (value_range_t *vr, tree expr)
        
       /* ABS_EXPR may flip the range around, if the original range
         included negative values.  */
-      min = (vr0.min == TYPE_MIN_VALUE (TREE_TYPE (expr)))
+      min = (tree_int_cst_equal (vr0.min, TYPE_MIN_VALUE (TREE_TYPE (expr))))
            ? TYPE_MAX_VALUE (TREE_TYPE (expr))
            : fold_unary_to_constant (code, TREE_TYPE (expr), vr0.min);
 
@@ -1575,7 +1575,7 @@ extract_range_from_unary_expr (value_range_t *vr, tree expr)
                 or ~[-INF + 1, min (abs(MIN), abs(MAX))] when
                 flag_wrapv is set and the original anti-range doesn't include
                 TYPE_MIN_VALUE, remember -TYPE_MIN_VALUE = TYPE_MIN_VALUE.  */
-             min = (flag_wrapv && vr0.min != type_min_value
+             min = (flag_wrapv && !tree_int_cst_equal (vr0.min, type_min_value)
                     ? int_const_binop (PLUS_EXPR,
                                        type_min_value,
                                        integer_one_node, 0)