From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lf1-x130.google.com (mail-lf1-x130.google.com [IPv6:2a00:1450:4864:20::130]) by sourceware.org (Postfix) with ESMTPS id 394B63858CD1 for ; Tue, 9 Apr 2024 06:55:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 394B63858CD1 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 394B63858CD1 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::130 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712645739; cv=none; b=CLhVzaHtWBF4182MNrlDdkp09+spyzf3Zg065uMZvjm+seXMj8rZ84Ta82GqPzE3fQtzk2dp/1LUguzdTh0dnIys0FfWNgbG9lYT+bybgQOMksmbDb1jg15kbveBGqqfDRiIkMPzoVsEXGXWwNaa8MeK+fxIql+TIGUJkfzM/5Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712645739; c=relaxed/simple; bh=IebUtFL4hf/QSHE1KDmdKRqAqNtVEs2qQ+5UlEgxWjM=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=KD9wQdxBCGJ3N4MXwYcOa2T4ceSYBEtmgzn4ajIf+I7wkQg4RJ/CC6qtPnWaZmSzmq5U0hK+kqRyXHznDy6NCZi6+6Xo6Fn7OqkkIrSLdBLcfyR3ucVIJ9V1dtoq4DBL27uHoVGPK9xktMsqXCfndF78WTaJ42RGBPflL4TRgzg= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lf1-x130.google.com with SMTP id 2adb3069b0e04-516cbf3fd3dso6069800e87.2 for ; Mon, 08 Apr 2024 23:55:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712645735; x=1713250535; darn=gcc.gnu.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=9K0Ho+vRmycRekp45LGCC9DVRViHE1YZdlgcCFuac0A=; b=UFJLIy619UnhXVTOcby7REVdnbf+f6oi+L6iJHClXm3xoVsXdR2Nz6p3pe0vPNsrcJ TM3xCBXy3+t3J/N3uBWXxug5ODFtjgUuMp4hMwBWSqg+yYD3r3SrmgaIZrtN1sPNbU0c 3AtqKYX3X0RJSunVfq7sEW+ptIB+Ffhc7/3S0v0l+YEoYv9HSxtZ0ZvnDRlvRHaUnpDN RZ4h5a5V4uy54PFWox2/5kflX6mVQZFycbiu1WEGQxTNmaSNtzmUSXdj6uQWALWozusA hL9BCURyWMDhC7Y1oLdVp8cukyaAi4rLiIwp1bNUofISAi2sez0pjGhUv3xnawYbfxpO DO5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712645735; x=1713250535; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9K0Ho+vRmycRekp45LGCC9DVRViHE1YZdlgcCFuac0A=; b=gy/iJITW191up42HV2sJP164sp1Y4NlsmoF0FTKTz4aATSP6GSwqcjkC0S3t9OYP9Z h9+r0eutqSBzDTql+4DbqCp5dBLXNM9LQJ18o/H4U+McZ6bD2Ve8ojnlbNEhvICwfMdm fIgAyuP7c/wBWvInh+wygOr17prPUH1GFMjXJ/BOnFIny9kzT1Ed40jVG9XZ4ZYwXllb C1zykZZ4IJ1FqqynzKx+t2+EUDi4OOv7DmopvKn2MR6LducYWjrMn9wbbR0nHNs5ktZo RuwTvEAIGGff2mjHNcx20oqgDbqUWA+XlJwZ33LfjJyILa3isdP1xMx4Z8Bks/o/0olV ZLDg== X-Gm-Message-State: AOJu0YxD8wEtyF0ns3JIbT7cOqbQLJXQeJWAlKHfvj/6lpsq5IIN0KLY Kwi2j/pGiqA9Je6105wYyADODagyKTl0sb2289Tvbi2XBIB5nn65Bph4G9QyOqPll/wuyqIdglG ghksJMRwfT9zoJGZh8ks9Su17V5PpJnRq X-Google-Smtp-Source: AGHT+IHpSz1ZRdV80yxGFULit75k2AqIgDNXiHIMNehXeVRIY8o4aaSGEQlcYh1qzmSQYIkyy2yEhZKvDzJbQJVxoo8= X-Received: by 2002:ac2:494b:0:b0:515:d1c1:c1f8 with SMTP id o11-20020ac2494b000000b00515d1c1c1f8mr7611607lfi.64.1712645734198; Mon, 08 Apr 2024 23:55:34 -0700 (PDT) MIME-Version: 1.0 References: <8bc0fa05-e254-6c85-f48b-e7d353eb9a18@linux.ibm.com> <2c7f198d-6e07-fbdf-0f41-17504bc61017@linux.ibm.com> In-Reply-To: <2c7f198d-6e07-fbdf-0f41-17504bc61017@linux.ibm.com> From: Richard Biener Date: Tue, 9 Apr 2024 08:55:22 +0200 Message-ID: Subject: Re: [PATCH] rs6000: Fix wrong align passed to build_aligned_type [PR88309] To: "Kewen.Lin" Cc: GCC Patches , Segher Boessenkool , David Edelsohn , Peter Bergner , Andrew Pinski Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,KAM_SHORT,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Tue, Apr 9, 2024 at 4:07=E2=80=AFAM Kewen.Lin wrot= e: > > on 2024/4/8 18:47, Richard Biener wrote: > > On Mon, Apr 8, 2024 at 11:22=E2=80=AFAM Kewen.Lin = wrote: > >> > >> Hi, > >> > >> 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. > >> > >> Bootstrapped and regtested on x86_64-redhat-linux, > >> powerpc64-linux-gnu P8/P9 and powerpc64le-linux-gnu P9 and P10. > >> > >> Is it (the generic part code change) ok for trunk? > > > > OK > > Thanks, pushed as r14-9850, is it also ok to backport after burn-in time? Sure. > BR, > Kewen > > > > >> BR, > >> Kewen > >> ----- > >> 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. > >> --- > >> 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(-) > >> create mode 100644 gcc/testsuite/gcc.target/powerpc/pr88309.c > >> > >> diff --git a/gcc/config/rs6000/rs6000-builtin.cc b/gcc/config/rs6000/r= s6000-builtin.cc > >> index 6698274031b..e7d6204074c 100644 > >> --- a/gcc/config/rs6000/rs6000-builtin.cc > >> +++ b/gcc/config/rs6000/rs6000-builtin.cc > >> @@ -1900,7 +1900,7 @@ rs6000_gimple_fold_builtin (gimple_stmt_iterator= *gsi) > >> tree lhs_type =3D TREE_TYPE (lhs); > >> /* In GIMPLE the type of the MEM_REF specifies the alignment. = The > >> required alignment (power) is 4 bytes regardless of data typ= e. */ > >> - tree align_ltype =3D build_aligned_type (lhs_type, 4); > >> + tree align_ltype =3D 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 wil= l match > >> the type of arg1. */ > >> @@ -1944,7 +1944,7 @@ rs6000_gimple_fold_builtin (gimple_stmt_iterator= *gsi) > >> tree arg2_type =3D ptr_type_node; > >> /* In GIMPLE the type of the MEM_REF specifies the alignment. = The > >> required alignment (power) is 4 bytes regardless of data ty= pe. */ > >> - tree align_stype =3D build_aligned_type (arg0_type, 4); > >> + tree align_stype =3D 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 =3D NULL; > >> diff --git a/gcc/testsuite/gcc.target/powerpc/pr88309.c b/gcc/testsuit= e/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 =3D 0; > >> + for (;; g +=3D 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-prefetc= h.cc > >> index bbd98e03254..70073cc4fe4 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 ca= che_line_size, > >> if (delta >=3D (HOST_WIDE_INT) cache_line_size) > >> return false; > >> > >> + gcc_assert (align_unit > 0); > >> + > >> miss_positions =3D 0; > >> total_positions =3D (cache_line_size / align_unit) * distinct_iters= ; > >> max_allowed_miss_positions =3D (ACCEPTABLE_MISS_RATE * total_positi= ons) / 1000; > >> diff --git a/gcc/tree.cc b/gcc/tree.cc > >> index f801712c9dd..6f8400e6640 100644 > >> --- a/gcc/tree.cc > >> +++ b/gcc/tree.cc > >> @@ -5689,7 +5689,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) > >> -- > >> 2.43.0