]> gcc.gnu.org Git - gcc.git/commitdiff
rs6000: Fix wrong align passed to build_aligned_type [PR88309]
authorKewen Lin <linkw@linux.ibm.com>
Tue, 9 Apr 2024 02:01:36 +0000 (21:01 -0500)
committerKewen Lin <linkw@linux.ibm.com>
Thu, 25 Apr 2024 05:09:22 +0000 (00:09 -0500)
As the comments in PR88309 show, there are two oversights
in rs6000_gimple_fold_builtin that pass align in bytes to
build_aligned_type but which actually requires align in
bits, it causes unexpected ICE or hanging in function
is_miss_rate_acceptable due to zero align_unit value.

This patch is to fix them by converting bytes to bits, add
an assertion on positive align_unit value and notes function
build_aligned_type requires align measured in bits in its
function comment.

PR target/88309

Co-authored-by: Andrew Pinski <quic_apinski@quicinc.com>
gcc/ChangeLog:

* config/rs6000/rs6000-call.c (rs6000_gimple_fold_builtin): Fix
wrong align passed to function build_aligned_type.
* tree-ssa-loop-prefetch.c (is_miss_rate_acceptable): Add an
assertion to ensure align_unit should be positive.
* tree.c (build_qualified_type): Update function comments.

gcc/testsuite/ChangeLog:

* gcc.target/powerpc/pr88309.c: New test.

(cherry picked from commit 26eb5f8fd173e2425ae7505528fc426de4b7e34c)

gcc/config/rs6000/rs6000-call.c
gcc/testsuite/gcc.target/powerpc/pr88309.c [new file with mode: 0644]
gcc/tree-ssa-loop-prefetch.c
gcc/tree.c

index 1be4797e834065be969cff4104a430b390384f36..c555f7857d13a2da375fde13fef408d1a87eb2f9 100644 (file)
@@ -12658,7 +12658,7 @@ rs6000_gimple_fold_builtin (gimple_stmt_iterator *gsi)
        tree lhs_type = TREE_TYPE (lhs);
        /* In GIMPLE the type of the MEM_REF specifies the alignment.  The
          required alignment (power) is 4 bytes regardless of data type.  */
-       tree align_ltype = build_aligned_type (lhs_type, 4);
+       tree align_ltype = build_aligned_type (lhs_type, 32);
        /* POINTER_PLUS_EXPR wants the offset to be of type 'sizetype'.  Create
           the tree using the value from arg0.  The resulting type will match
           the type of arg1.  */
@@ -12702,7 +12702,7 @@ rs6000_gimple_fold_builtin (gimple_stmt_iterator *gsi)
        tree arg2_type = ptr_type_node;
        /* In GIMPLE the type of the MEM_REF specifies the alignment.  The
           required alignment (power) is 4 bytes regardless of data type.  */
-       tree align_stype = build_aligned_type (arg0_type, 4);
+       tree align_stype = build_aligned_type (arg0_type, 32);
        /* POINTER_PLUS_EXPR wants the offset to be of type 'sizetype'.  Create
           the tree using the value from arg1.  */
        gimple_seq stmts = NULL;
diff --git a/gcc/testsuite/gcc.target/powerpc/pr88309.c b/gcc/testsuite/gcc.target/powerpc/pr88309.c
new file mode 100644 (file)
index 0000000..c0078cf
--- /dev/null
@@ -0,0 +1,27 @@
+/* { dg-require-effective-target powerpc_vsx_ok } */
+/* { dg-options "-mvsx -O2 -fprefetch-loop-arrays" } */
+
+/* Verify there is no ICE or hanging.  */
+
+#include <altivec.h>
+
+void b(float *c, vector float a, vector float, vector float)
+{
+  vector float d;
+  vector char ahbc;
+  vec_xst(vec_perm(a, d, ahbc), 0, c);
+}
+
+vector float e(vector unsigned);
+
+void f() {
+  float *dst;
+  int g = 0;
+  for (;; g += 16) {
+    vector unsigned m, i;
+    vector unsigned n, j;
+    vector unsigned k, l;
+    b(dst + g * 3, e(m), e(n), e(k));
+    b(dst + (g + 4) * 3, e(i), e(j), e(l));
+  }
+}
index 98062eb46160ddd44fea17d038ef3df2250fb768..8d73b14dfc4959609cac137a5712a8021b8d706a 100644 (file)
@@ -739,6 +739,8 @@ is_miss_rate_acceptable (unsigned HOST_WIDE_INT cache_line_size,
   if (delta >= (HOST_WIDE_INT) cache_line_size)
     return false;
 
+  gcc_assert (align_unit > 0);
+
   miss_positions = 0;
   total_positions = (cache_line_size / align_unit) * distinct_iters;
   max_allowed_miss_positions = (ACCEPTABLE_MISS_RATE * total_positions) / 1000;
index 79e03204a6e38c55add9b1b3dfff3bc07076c137..8b5b0b7508cc3f1364385b0be8d4b28143650e61 100644 (file)
@@ -6711,7 +6711,8 @@ build_qualified_type (tree type, int type_quals MEM_STAT_DECL)
   return t;
 }
 
-/* Create a variant of type T with alignment ALIGN.  */
+/* Create a variant of type T with alignment ALIGN which
+   is measured in bits.  */
 
 tree
 build_aligned_type (tree type, unsigned int align)
This page took 0.097983 seconds and 5 git commands to generate.