From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2063) id 548A4384640E; Thu, 25 Apr 2024 02:35:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 548A4384640E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1714012530; bh=y3UEP5t1R2wcg3Hq9iCmCR/cJM3dvt6zl2p3QHRyIkw=; h=From:To:Subject:Date:From; b=Co5bLcN+oV0WaJzNWsGHbhbYf2nyr4yGK6xD9CWd/QvRo/n+34czO45pzpdG9+4na dTWEJ+aiJQLFJjC4913AfkymD9Uai6mLufXAbne/D5Yghgjlbx4yJSxi8faqW1Fd9y s3sUgO1FPkWbUFAzKZ6qg/NT4ocf+HKzO8Bv/fXs= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Kewen Lin To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-10393] rs6000: Fix wrong align passed to build_aligned_type [PR88309] X-Act-Checkin: gcc X-Git-Author: Kewen Lin X-Git-Refname: refs/heads/releases/gcc-12 X-Git-Oldrev: 27c17c92c32d7121b61f5ed46fd9a23954e072f3 X-Git-Newrev: 43c8cb0e003996b3a7a9f98923f602561f3f0ec7 Message-Id: <20240425023530.548A4384640E@sourceware.org> Date: Thu, 25 Apr 2024 02:35:30 +0000 (GMT) List-Id: https://gcc.gnu.org/g:43c8cb0e003996b3a7a9f98923f602561f3f0ec7 commit r12-10393-g43c8cb0e003996b3a7a9f98923f602561f3f0ec7 Author: Kewen Lin Date: Mon Apr 8 21:01:36 2024 -0500 rs6000: Fix wrong align passed to build_aligned_type [PR88309] 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 gcc/ChangeLog: * config/rs6000/rs6000-builtin.cc (rs6000_gimple_fold_builtin): Fix wrong align passed to function build_aligned_type. * tree-ssa-loop-prefetch.cc (is_miss_rate_acceptable): Add an assertion to ensure align_unit should be positive. * tree.cc (build_qualified_type): Update function comments. gcc/testsuite/ChangeLog: * gcc.target/powerpc/pr88309.c: New test. Diff: --- gcc/config/rs6000/rs6000-builtin.cc | 4 ++-- gcc/testsuite/gcc.target/powerpc/pr88309.c | 27 +++++++++++++++++++++++++++ gcc/tree-ssa-loop-prefetch.cc | 2 ++ gcc/tree.cc | 3 ++- 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/gcc/config/rs6000/rs6000-builtin.cc b/gcc/config/rs6000/rs6000-builtin.cc index cc385a2b277..39a07a27c86 100644 --- a/gcc/config/rs6000/rs6000-builtin.cc +++ b/gcc/config/rs6000/rs6000-builtin.cc @@ -1920,7 +1920,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. */ @@ -1964,7 +1964,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 index 00000000000..c0078cf2b8c --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/pr88309.c @@ -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 + +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)); + } +} diff --git a/gcc/tree-ssa-loop-prefetch.cc b/gcc/tree-ssa-loop-prefetch.cc index aebd7c9206f..543e142f85d 100644 --- a/gcc/tree-ssa-loop-prefetch.cc +++ b/gcc/tree-ssa-loop-prefetch.cc @@ -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; diff --git a/gcc/tree.cc b/gcc/tree.cc index e6593de87b6..ead4c1421cd 100644 --- a/gcc/tree.cc +++ b/gcc/tree.cc @@ -5649,7 +5649,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)