aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Biener <rguenther@suse.de>2020-11-13 11:31:22 +0100
committerRichard Biener <rguenther@suse.de>2020-11-13 12:24:54 +0100
commitdcfd302a79a5e2ea3bb16fc4fc45a5ee31cc0eab (patch)
treebe85f1a2cea59235fefe077bbd5125b1664fa19f
parent3793ecc10fd4f8be8abd65ba41824f3cc91238e7 (diff)
downloadgcc-dcfd302a79a5e2ea3bb16fc4fc45a5ee31cc0eab.zip
gcc-dcfd302a79a5e2ea3bb16fc4fc45a5ee31cc0eab.tar.gz
gcc-dcfd302a79a5e2ea3bb16fc4fc45a5ee31cc0eab.tar.bz2
tree-optimization/97812 - fix range query in VRP assert discovery
This makes sure to properly extend the input range before seeing whether it fits the target. 2020-11-13 Richard Biener <rguenther@suse.de> PR tree-optimization/97812 * tree-vrp.c (register_edge_assert_for_2): Extend the range according to its sign before seeing whether it fits. * gcc.dg/torture/pr97812.c: New testcase.
-rw-r--r--gcc/testsuite/gcc.dg/torture/pr97812.c15
-rw-r--r--gcc/tree-vrp.c10
2 files changed, 23 insertions, 2 deletions
diff --git a/gcc/testsuite/gcc.dg/torture/pr97812.c b/gcc/testsuite/gcc.dg/torture/pr97812.c
new file mode 100644
index 0000000..4d468ad
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr97812.c
@@ -0,0 +1,15 @@
+/* { dg-do run } */
+/* { dg-additional-options "-fdisable-tree-evrp" } */
+
+unsigned char c;
+
+int main() {
+volatile short b = 4066;
+ unsigned short bp = b;
+ unsigned d = bp & 2305;
+ signed char e = d;
+ c = e ? : e;
+ if (!d)
+ __builtin_abort ();
+ return 0;
+}
diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c
index 54ce017..d661866 100644
--- a/gcc/tree-vrp.c
+++ b/gcc/tree-vrp.c
@@ -1740,8 +1740,14 @@ register_edge_assert_for_2 (tree name, edge e,
&& ((TYPE_PRECISION (TREE_TYPE (name))
> TYPE_PRECISION (TREE_TYPE (rhs1)))
|| (get_range_info (rhs1, &rmin, &rmax) == VR_RANGE
- && wi::fits_to_tree_p (rmin, TREE_TYPE (name))
- && wi::fits_to_tree_p (rmax, TREE_TYPE (name)))))
+ && wi::fits_to_tree_p
+ (widest_int::from (rmin,
+ TYPE_SIGN (TREE_TYPE (rhs1))),
+ TREE_TYPE (name))
+ && wi::fits_to_tree_p
+ (widest_int::from (rmax,
+ TYPE_SIGN (TREE_TYPE (rhs1))),
+ TREE_TYPE (name)))))
add_assert_info (asserts, rhs1, rhs1,
comp_code, fold_convert (TREE_TYPE (rhs1), val));
}