aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2023-03-14 09:15:38 +0100
committerJakub Jelinek <jakub@redhat.com>2023-03-14 09:15:38 +0100
commit72b52751c60abb327c73716259485d04b8eabe4f (patch)
tree1e8e901f45edcc67068d449c9151804767f9d007 /gcc
parent5159a1f1e91e03d4b82808a0062697318232543f (diff)
downloadgcc-72b52751c60abb327c73716259485d04b8eabe4f.zip
gcc-72b52751c60abb327c73716259485d04b8eabe4f.tar.gz
gcc-72b52751c60abb327c73716259485d04b8eabe4f.tar.bz2
tree-vect-patterns: Fix up ICE in upper_bound [PR109115]
As mentioned in the PR, range_of_expr returns false if the type of the expression isn't suitable for corresponding range type, but doesn't if the range is undefined for other reasons. Still, lower/upper_bound is defined only for ranges which actually have at least one pair of subranges, VR_UNDEFINED range doesn't have it. 2023-03-14 Jakub Jelinek <jakub@redhat.com> PR tree-optimization/109115 * tree-vect-patterns.cc (vect_recog_divmod_pattern): Don't use r.upper_bound () on r.undefined_p () range. * gcc.dg/pr109115.c: New test.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/testsuite/gcc.dg/pr109115.c20
-rw-r--r--gcc/tree-vect-patterns.cc2
2 files changed, 21 insertions, 1 deletions
diff --git a/gcc/testsuite/gcc.dg/pr109115.c b/gcc/testsuite/gcc.dg/pr109115.c
new file mode 100644
index 0000000..7804771
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr109115.c
@@ -0,0 +1,20 @@
+/* PR tree-optimization/109115 */
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+int a, b;
+
+int
+main ()
+{
+ unsigned short c = a, e = -1;
+ if (b)
+ {
+ unsigned d = (a ^ 1U) / a & c;
+ int f = (~d >> ~a) / e;
+ if (a)
+ f = a;
+ a = f;
+ }
+ return 0;
+}
diff --git a/gcc/tree-vect-patterns.cc b/gcc/tree-vect-patterns.cc
index 887f02b..8802141 100644
--- a/gcc/tree-vect-patterns.cc
+++ b/gcc/tree-vect-patterns.cc
@@ -3973,7 +3973,7 @@ vect_recog_divmod_pattern (vec_info *vinfo,
/* Check that no overflow will occur. If we don't have range
information we can't perform the optimization. */
- if (ranger.range_of_expr (r, oprnd0, stmt))
+ if (ranger.range_of_expr (r, oprnd0, stmt) && !r.undefined_p ())
{
wide_int max = r.upper_bound ();
wide_int one = wi::shwi (1, prec);