]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[PR tree-optimization/107312] Make range_true_and_false work with 1-bit signed types.
authorAldy Hernandez <aldyh@redhat.com>
Wed, 19 Oct 2022 12:27:46 +0000 (14:27 +0200)
committerAldy Hernandez <aldyh@redhat.com>
Wed, 19 Oct 2022 14:00:48 +0000 (16:00 +0200)
range_true_and_false() returns a range of [0,1], which for a 1-bit
signed integer gets passed to the irange setter as [0, -1].  These
endpoints are out of order and cause an ICE.  Through some dumb luck,
the legacy code swaps out of order endpoints, because old VRP would
sometimes pass endpoints reversed, depending on the setter to fix
them.  This swapping does not happen for non-legacy, hence the ICE.

The right thing to do (apart from killing legacy and 1-bit signed
integers ;-)), is to avoid passing out of order endpoints for 1-bit
signed integers.  For that matter, a range of [-1, 0] (signed) or
[0, 1] (unsigned) is just varying.

PR tree-optimization/107312

gcc/ChangeLog:

* range.h (range_true_and_false): Special case 1-bit signed types.
* value-range.cc (range_tests_misc): New test.

gcc/testsuite/ChangeLog:

* gcc.target/i386/pr107312.c: New test.

gcc/range.h
gcc/testsuite/gcc.target/i386/pr107312.c [new file with mode: 0644]
gcc/value-range.cc

index 8138d6f55151295d5cf6d8a80a56c8b6586641bc..ba3a6b2516fb97f472a5073938e4c119dfdf4b1b 100644 (file)
@@ -50,6 +50,8 @@ static inline int_range<1>
 range_true_and_false (tree type)
 {
   unsigned prec = TYPE_PRECISION (type);
+  if (prec == 1)
+    return int_range<2> (type);
   return int_range<2> (type, wi::zero (prec), wi::one (prec));
 }
 
diff --git a/gcc/testsuite/gcc.target/i386/pr107312.c b/gcc/testsuite/gcc.target/i386/pr107312.c
new file mode 100644 (file)
index 0000000..b4180e3
--- /dev/null
@@ -0,0 +1,11 @@
+// { dg-do compile }
+// { dg-options "-mavx512vbmi -O1 -ftree-loop-vectorize" }
+
+void
+foo (_Float16 *r, short int *a)
+{
+  int i;
+
+  for (i = 0; i < 32; ++i)
+    r[i] = !!a[i];
+}
index 90d5e6606843acca28a5f0c9759c7375e8a268b7..511cd0ad7679394ad60e861162a3ba7a158e9f55 100644 (file)
@@ -3437,6 +3437,8 @@ range_tests_misc ()
     max.union_ (min);
     ASSERT_TRUE (max.varying_p ());
   }
+  // Test that we can set a range of true+false for a 1-bit signed int.
+  r0 = range_true_and_false (one_bit_type);
 
   // Test inversion of 1-bit signed integers.
   {