+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
+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.
--- /dev/null
+/* { 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;
+}
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,
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);
*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;
}