From patchwork Mon Apr 8 09:22:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kewen.Lin" X-Patchwork-Id: 88155 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 25D13385829B for ; Mon, 8 Apr 2024 09:25:00 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by sourceware.org (Postfix) with ESMTPS id 5FA903858D28 for ; Mon, 8 Apr 2024 09:22:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5FA903858D28 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=linux.ibm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linux.ibm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 5FA903858D28 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=148.163.156.1 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712568164; cv=none; b=krLvYOoP5NJeqbmLiM3CWwztaZ6JxdR2t4Gyqrkf/mWqGp/Ax88GjAPSWVpMHosvSUoErYynDzXUeFIj1KYiEKtciELFiJHaseimhJsg4AOW/GIyfqtN2asHafDKk4LhKucwqwQFBvWCmA+jLp18U17djmQ1fQNBoAmJepeF1x0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712568164; c=relaxed/simple; bh=EnRbdzIbPZikShikZ488NywYBD2vezs+VdOA4BHtEa0=; h=DKIM-Signature:Message-ID:Date:MIME-Version:To:From:Subject; b=Rv7LG6flCjFKpDtQBQEW981Y8X+dq8yW5Fpcj7rE1M5H5Gt3s9stL9BFa+Z+fjMkKkIq1jO7JFrxiBzs+/FpdxFCHTBvwfcX3nZ+UPvACG9pRI7Q5uDvnTv+uiQN/ZT/ca0ngr9aCj7x4QTZ5GOeyJGCk9+8Fm/Xv85pbGTFcW4= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0353726.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 43897RS8014965; Mon, 8 Apr 2024 09:22:40 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=message-id : date : mime-version : to : cc : from : subject : content-type : content-transfer-encoding; s=pp1; bh=tkZzvo0Q4np+/x8YdbuQUOUWYyLhBC9+9grXWqG4P6g=; b=IdFWyhS0lv41H8f5i26loy4OkywAzNOxOdwPdjQJqW6ZPlf58/GLCwDTj3Jo/kYwYeUh di0U95NbhQgKSQamrxQO9RhfeJ6JoxxQ3TR65TUSpXedbNkoeHvY2/0Ym5yzCxdCRsJP RY0Iu5fj9DXxew7bVLW1D7rWoF2gY9+YYdeEBu44ZrStuiofkn2SMaTSdi82w2bmUqEW Q6DlWwoXxfepUXLHBpelDjotHNCTFSRSruifS5dB9FfMawTbVXAzkM7ni/QXU76NyiK2 6kRmbazSAkZROLINEgU9aM9/4t5kmjZFeNlmRE8anNwreUvH2N2V1wFX0ah2tWmSbAl0 2w== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3xcdnsr14b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 08 Apr 2024 09:22:40 +0000 Received: from m0353726.ppops.net (m0353726.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 4389MdJh009702; Mon, 8 Apr 2024 09:22:39 GMT Received: from ppma23.wdc07v.mail.ibm.com (5d.69.3da9.ip4.static.sl-reverse.com [169.61.105.93]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3xcdnsr142-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 08 Apr 2024 09:22:39 +0000 Received: from pps.filterd (ppma23.wdc07v.mail.ibm.com [127.0.0.1]) by ppma23.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 4388a8R9029901; Mon, 8 Apr 2024 09:22:38 GMT Received: from smtprelay01.fra02v.mail.ibm.com ([9.218.2.227]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3xbj7ky5g1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 08 Apr 2024 09:22:38 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay01.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 4389MYsr32637222 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 8 Apr 2024 09:22:36 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 67DC120049; Mon, 8 Apr 2024 09:22:34 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2D3352005A; Mon, 8 Apr 2024 09:22:32 +0000 (GMT) Received: from [9.197.228.82] (unknown [9.197.228.82]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Mon, 8 Apr 2024 09:22:31 +0000 (GMT) Message-ID: <8bc0fa05-e254-6c85-f48b-e7d353eb9a18@linux.ibm.com> Date: Mon, 8 Apr 2024 17:22:30 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Content-Language: en-US To: GCC Patches Cc: Segher Boessenkool , David Edelsohn , Peter Bergner , Richard Biener , Andrew Pinski From: "Kewen.Lin" Subject: [PATCH] rs6000: Fix wrong align passed to build_aligned_type [PR88309] X-TM-AS-GCONF: 00 X-Proofpoint-GUID: cMS0jjm8qkRqTFfoXED1uWova2rUvoXz X-Proofpoint-ORIG-GUID: SF-83GvGHWYzWmSDIzdGxSDy_1naMbOU X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-04-08_07,2024-04-05_02,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 adultscore=0 clxscore=1015 spamscore=0 impostorscore=0 suspectscore=0 phishscore=0 mlxlogscore=999 mlxscore=0 priorityscore=1501 malwarescore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404080072 X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org 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? 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 -- 2.43.0 diff --git a/gcc/config/rs6000/rs6000-builtin.cc b/gcc/config/rs6000/rs6000-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 = 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. */ @@ -1944,7 +1944,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 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 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 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)