re PR tree-optimization/85822 (Maybe wrong code in VRP since r249150)
authorYury Gribov <tetra2005@gmail.com>
Wed, 23 May 2018 07:40:43 +0000 (07:40 +0000)
committerMartin Liska <marxin@gcc.gnu.org>
Wed, 23 May 2018 07:40:43 +0000 (07:40 +0000)
PR tree-optimization/85822

From-SVN: r260566

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/pr85822.c [new file with mode: 0644]
gcc/tree-vrp.c

index fbb0120c497ff94748f41e825214d10b167a7cc4..202b658d872b6391fd9bdae0c33ad255211405e8 100644 (file)
@@ -1,3 +1,9 @@
+2018-05-23  Yury Gribov  <tetra2005@gmail.com>
+
+       PR tree-optimization/85822
+       * tree-vrp.c (is_masked_range_test): Fix handling of negative
+       constants.
+
 2018-05-23  Richard Biener  <rguenther@suse.de>
 
        * tree-ssa-sccvn.c (vn_reference_lookup_3): Handle arbitrary
index 6bd7a1546cd4188a914ae2277fb73699dd9b5ef8..075f845977fdad6d45768c950524bebec4a2018f 100644 (file)
@@ -1,3 +1,8 @@
+2018-05-23  Yury Gribov  <tetra2005@gmail.com>
+
+       PR tree-optimization/85822
+       * c-c++-common/pr85822.c: New test.
+
 2018-05-23  Richard Biener  <rguenther@suse.de>
 
        * gcc.dg/tree-ssa/ssa-fre-65.c: New testcase.
diff --git a/gcc/testsuite/c-c++-common/pr85822.c b/gcc/testsuite/c-c++-common/pr85822.c
new file mode 100644 (file)
index 0000000..3b09188
--- /dev/null
@@ -0,0 +1,27 @@
+/* { dg-options "-O2" } */
+/* { dg-do run } */
+
+static const long long int TagTypeNumber = 0xffff000000000000ll;
+
+long long int x;
+
+void foo(void)
+{
+  x = TagTypeNumber + 1;
+}
+
+int main(int argc, char **argv)
+{
+  if (argc > 0)
+    foo ();
+
+  if ((x & TagTypeNumber) == TagTypeNumber)
+  {
+    unsigned y = (unsigned)x;
+    __builtin_printf ("v: %u\n", y);
+    if (y != 1)
+      __builtin_abort ();
+  }
+
+  return 0;
+}
index aa53db655762ce33fd3afe423b0bc6e09a180f5b..6c482dd3e46f58ab4492d24cafaa280dbb7b9b02 100644 (file)
@@ -3844,10 +3844,10 @@ register_edge_assert_for_1 (tree op, enum tree_code code,
    Such comparison can yield assertions like
      X >= XX...X00...0
      X <= XX...X11...1
-   in case of COND_OP being NE_EXPR or
+   in case of COND_OP being EQ_EXPR or
      X < XX...X00...0
      X > XX...X11...1
-   in case of EQ_EXPR.  */
+   in case of NE_EXPR.  */
 
 static bool
 is_masked_range_test (tree name, tree valt, enum tree_code cond_code,
@@ -3867,6 +3867,10 @@ is_masked_range_test (tree name, tree valt, enum tree_code cond_code,
 
   wi::tree_to_wide_ref mask = wi::to_wide (maskt);
   wide_int inv_mask = ~mask;
+  /* Must have been removed by now so don't bother optimizing.  */
+  if (mask == 0 || inv_mask == 0)
+    return false;
+
   /* Assume VALT is INTEGER_CST.  */
   wi::tree_to_wide_ref val = wi::to_wide (valt);
 
@@ -3907,9 +3911,6 @@ is_masked_range_test (tree name, tree valt, enum tree_code cond_code,
   *low = wide_int_to_tree (type, val);
   *high = wide_int_to_tree (type, val | inv_mask);
 
-  if (wi::neg_p (val, TYPE_SIGN (type)))
-    std::swap (*low, *high);
-
   return true;
 }