]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
vect: Use original LHS type for gather pattern [PR118950].
authorRobin Dapp <rdapp@ventanamicro.com>
Fri, 21 Feb 2025 06:19:40 +0000 (07:19 +0100)
committerRobin Dapp <rdapp@ventanamicro.com>
Mon, 24 Feb 2025 12:11:15 +0000 (13:11 +0100)
In PR118950 we do not zero masked elements in a gather load.
While recognizing a gather/scatter pattern we do not use the original
type of the LHS.  This matters because the type can differ with bool
patterns (e.g. _Bool vs unsigned char) and we don't notice the need
for zeroing out the padding bytes.

This patch just uses the original LHS's type.

PR middle-end/118950

gcc/ChangeLog:

* tree-vect-patterns.cc (vect_recog_gather_scatter_pattern): Use
original LHS's type.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/pr118950.c: New test.

gcc/testsuite/gcc.target/riscv/rvv/autovec/pr118950.c [new file with mode: 0644]
gcc/tree-vect-patterns.cc

diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr118950.c b/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr118950.c
new file mode 100644 (file)
index 0000000..604d426
--- /dev/null
@@ -0,0 +1,29 @@
+/* { dg-do run } */
+/* { dg-require-effective-target riscv_v_ok } */
+/* { dg-add-options riscv_v } */
+/* { dg-additional-options "-std=gnu99 -Wno-pedantic" } */
+
+unsigned char a;
+long long r;
+_Bool h = 1;
+short j[23];
+_Bool k[3][23];
+
+void b(_Bool h, short j[], _Bool k[][23]) {
+  for (int m = 0; m < 23; m += 3)
+    for (short n = 0; n < 22; n += 4)
+      a = ({
+        unsigned char o = a;
+        unsigned char p = j[n] ? h : k[m][n];
+        o > p ? o : p;
+      });
+}
+
+int main() {
+  for (int m = 0; m < 23; ++m)
+    j[m] = 10;
+  b(h, j, k);
+  r = a;
+  if (r != 1)
+    __builtin_abort ();
+}
index 6fc97d1b6ef91ee4293aee6d64beb317f5094d3f..4f0a7ea162b97b1c3ddd6f3d8b68dafb37af043f 100644 (file)
@@ -6022,7 +6022,8 @@ vect_recog_gather_scatter_pattern (vec_info *vinfo,
       else
        pattern_stmt = gimple_build_call_internal (gs_info.ifn, 4, base,
                                                   offset, scale, zero);
-      tree load_lhs = vect_recog_temp_ssa_var (gs_info.element_type, NULL);
+      tree lhs = gimple_get_lhs (stmt_info->stmt);
+      tree load_lhs = vect_recog_temp_ssa_var (TREE_TYPE (lhs), NULL);
       gimple_call_set_lhs (pattern_stmt, load_lhs);
     }
   else