]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/113670 - gather/scatter to/from hard registers
authorRichard Biener <rguenther@suse.de>
Wed, 31 Jan 2024 08:09:50 +0000 (09:09 +0100)
committerRichard Biener <rguenther@suse.de>
Thu, 21 Mar 2024 12:59:28 +0000 (13:59 +0100)
The following makes sure we're not taking the address of hard
registers when vectorizing appearant gathers or scatters to/from
them.

PR tree-optimization/113670
* tree-vect-data-refs.cc (vect_check_gather_scatter):
Make sure we can take the address of the reference base.

* gcc.target/i386/pr113670.c: New testcase.

(cherry picked from commit 924137b9012cee5603482242de08fbf0b2030f6a)

gcc/testsuite/gcc.target/i386/pr113670.c [new file with mode: 0644]
gcc/tree-vect-data-refs.cc

diff --git a/gcc/testsuite/gcc.target/i386/pr113670.c b/gcc/testsuite/gcc.target/i386/pr113670.c
new file mode 100644 (file)
index 0000000..8b9d374
--- /dev/null
@@ -0,0 +1,16 @@
+/* { dg-do compile } */
+/* { dg-options "-msse2 -O2 -fno-vect-cost-model" } */
+
+typedef float __attribute__ ((vector_size (16))) vec;
+typedef int __attribute__ ((vector_size (16))) ivec;
+ivec x;
+
+void
+test (void)
+{
+  register vec a asm("xmm3"), b asm("xmm4");
+  register ivec c asm("xmm5");
+  for (int i = 0; i < 4; i++)
+    c[i] = a[i] < b[i] ? -1 : 1;
+  x = c;
+}
index babd83dd8307ca1e5cb324208252cde85c7f7881..4fefd046207ffbe063eef3637dcdfeebaf6ea5ce 100644 (file)
@@ -4029,6 +4029,11 @@ vect_check_gather_scatter (stmt_vec_info stmt_info, loop_vec_info loop_vinfo,
   if (!multiple_p (pbitpos, BITS_PER_UNIT))
     return false;
 
+  /* We need to be able to form an address to the base which for example
+     isn't possible for hard registers.  */
+  if (may_be_nonaddressable_p (base))
+    return false;
+
   poly_int64 pbytepos = exact_div (pbitpos, BITS_PER_UNIT);
 
   if (TREE_CODE (base) == MEM_REF)