From patchwork Fri Jan 6 09:26:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kewen.Lin" X-Patchwork-Id: 40052 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp729809wrt; Fri, 6 Jan 2023 01:27:35 -0800 (PST) X-Google-Smtp-Source: AMrXdXtSY1pah0mhcf20b+2Fdl4LqW53wIwnhUdsQdDjMh3TUVWg8EKU0XQt5brFUvwrRZl2rwOx X-Received: by 2002:a17:907:8a24:b0:846:95f9:5b4d with SMTP id sc36-20020a1709078a2400b0084695f95b4dmr60806128ejc.42.1672997255635; Fri, 06 Jan 2023 01:27:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672997255; cv=none; d=google.com; s=arc-20160816; b=SiVpkI/7IoufaiHRtgJIPoj6/EJVmpNyMlu+e9wCK3b95S4md/6koWsLUk2uMtSXhb /JI46dl965UKt+LqB3DCusUWHA89KNV3tOJN6I9hyc9dIB8fuibJuD9pIdQE7TycQ3+S QHMFG5Q0jQ408CON0IPSyM8N5cCRT6yXPlZ33Gg230RZeyO7cnwZoNwwdLGXDyki+L7a 1sFjd1MisWjrIpNrhzam0STPbbbngYiMSFUAz8BxQs9DoztOqrGMNpWU1TtJUrMtm/HB sy42F7QeaV27Ys29foPDy25fUGAL8WsCuowd0JhrjL1dj5FTSvUN6KNDY/R2vKG+SrsX 9ESQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:cc:to:subject:content-language:user-agent :mime-version:date:message-id:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=whoUBRtL0myIFkcDw/rMSl4XNrUiPypVs2ITjy3GHGM=; b=ZOW12iFe74C23BtcE0z92EthHORYNYuuQpBYtlTG8sYkb2gmJzjs58voGPTm3ztTf9 hRKSeMTGaE4JO2lwu/bEf1Tg72bq0YwHOY5+48X9x7iwbbPkvZetqetIEt/vs76Q9YIQ PMvwmOUZOScyMFNF//Ka/EvgD993WqzBVRO1Zv3h5LLdxj3eQTd095bfqGoYRbYM/M+Q rVXRZ+nekDcs4NfoqikaH1+iUvP0N5RyIzfwMCPUgwwIdZc4NrbTnKhDpYQdvbeWrXhb wTpSzmYPrUTyFMCC3QtA71xbmp1+yGQ8TUCWvqXnL0FlqafABC0hJ8r5aQUbtJXPWviE FyHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Q3AO6NNk; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id e6-20020a17090658c600b007a953d421bbsi1029925ejs.322.2023.01.06.01.27.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Jan 2023 01:27:35 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Q3AO6NNk; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6C44B3858D35 for ; Fri, 6 Jan 2023 09:27:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6C44B3858D35 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1672997254; bh=whoUBRtL0myIFkcDw/rMSl4XNrUiPypVs2ITjy3GHGM=; h=Date:Subject:To:Cc:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=Q3AO6NNkgqcXIiw2FH1O6SORZH4dxuAxHtFhzkW3dPCcZGx1DXhyK+XaZjAOrWX0K Rx788Yx8E2UaH7U4HWDz0e28wM26cv5i1HwR2+sDYz29tYIYeCqpX9qSsFxjo22bkG iwDXQ2HwMzJNTJVd0iCnrqWr5sg+yWQEJlOGVomQ= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by sourceware.org (Postfix) with ESMTPS id BB6BC3858D28 for ; Fri, 6 Jan 2023 09:26:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BB6BC3858D28 Received: from pps.filterd (m0098416.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3068UOVV012656; Fri, 6 Jan 2023 09:26:46 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com (PPS) with ESMTPS id 3mxdk8m0u2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 06 Jan 2023 09:26:45 +0000 Received: from m0098416.ppops.net (m0098416.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 3069FHdJ010171; Fri, 6 Jan 2023 09:26:45 GMT Received: from ppma05fra.de.ibm.com (6c.4a.5195.ip4.static.sl-reverse.com [149.81.74.108]) by mx0b-001b2d01.pphosted.com (PPS) with ESMTPS id 3mxdk8m0tj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 06 Jan 2023 09:26:45 +0000 Received: from pps.filterd (ppma05fra.de.ibm.com [127.0.0.1]) by ppma05fra.de.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 3062EJGu013827; Fri, 6 Jan 2023 09:26:43 GMT Received: from smtprelay01.fra02v.mail.ibm.com ([9.218.2.227]) by ppma05fra.de.ibm.com (PPS) with ESMTPS id 3mtcq6nwme-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 06 Jan 2023 09:26:43 +0000 Received: from smtpav05.fra02v.mail.ibm.com (smtpav05.fra02v.mail.ibm.com [10.20.54.104]) by smtprelay01.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 3069QeTO46203220 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 6 Jan 2023 09:26:41 GMT Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D3B7B20043; Fri, 6 Jan 2023 09:26:40 +0000 (GMT) Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3DF0120040; Fri, 6 Jan 2023 09:26:39 +0000 (GMT) Received: from [9.197.231.22] (unknown [9.197.231.22]) by smtpav05.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 6 Jan 2023 09:26:38 +0000 (GMT) Message-ID: <11d0cb36-bbe2-7d48-cba2-9c8d4d3f08db@linux.ibm.com> Date: Fri, 6 Jan 2023 17:26:37 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.6.1 Content-Language: en-US Subject: [PATCH] rs6000: Teach rs6000_opaque_type_invalid_use_p about inline asm [PR108272] To: GCC Patches Cc: Segher Boessenkool , David Edelsohn , Peter Bergner X-TM-AS-GCONF: 00 X-Proofpoint-GUID: H-xUCIyKBJP71jVjJj9hdLZwcTfvAygb X-Proofpoint-ORIG-GUID: 7GikKdhg3E2R46ptp7Te90GR_47KEpdc X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.923,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2023-01-06_05,2023-01-05_02,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 impostorscore=0 malwarescore=0 bulkscore=0 priorityscore=1501 mlxscore=0 suspectscore=0 mlxlogscore=999 clxscore=1015 phishscore=0 lowpriorityscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2301060071 X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_MSPIKE_H2, 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: "Kewen.Lin via Gcc-patches" From: "Kewen.Lin" Reply-To: "Kewen.Lin" Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754264770250887430?= X-GMAIL-MSGID: =?utf-8?q?1754264770250887430?= Hi, As PR108272 shows, there are some invalid uses of MMA opaque types in inline asm statements. This patch is to teach the function rs6000_opaque_type_invalid_use_p for inline asm, check and error any invalid use of MMA opaque types in input and output operands. Bootstrapped and regtested on powerpc64-linux-gnu P8 and powerpc64le-linux-gnu P9 and P10. I'm going to push this next week if no objections. Kewen BR, ----- PR target/108272 gcc/ChangeLog: * config/rs6000/rs6000.cc (rs6000_opaque_type_invalid_use_p): Add the support for invalid uses in inline asm, factor out the checking and erroring to lambda function check_and_error_invalid_use. gcc/testsuite/ChangeLog: * gcc.target/powerpc/pr108272-1.c: New test. * gcc.target/powerpc/pr108272-2.c: New test. --- gcc/config/rs6000/rs6000.cc | 50 +++++++++++++++---- gcc/testsuite/gcc.target/powerpc/pr108272-1.c | 17 +++++++ gcc/testsuite/gcc.target/powerpc/pr108272-2.c | 17 +++++++ 3 files changed, 74 insertions(+), 10 deletions(-) create mode 100644 gcc/testsuite/gcc.target/powerpc/pr108272-1.c create mode 100644 gcc/testsuite/gcc.target/powerpc/pr108272-2.c -- 2.27.0 diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc index d362668ba13..46f74922755 100644 --- a/gcc/config/rs6000/rs6000.cc +++ b/gcc/config/rs6000/rs6000.cc @@ -28903,9 +28903,9 @@ constant_generates_xxspltidp (vec_const_128bit_type *vsx_const) __vector_pair built-in types. They are target specific and only available when MMA is supported. With MMA supported, it simply returns true, otherwise it checks if the given gimple - STMT is an assignment stmt and uses either of these two opaque - types unexpectedly, if yes, it would raise an error message - and returns true, otherwise it returns false. */ + STMT is an assignment or asm stmt and uses either of these two + opaque types unexpectedly, if yes, it would raise an error + message and returns true, otherwise it returns false. */ bool rs6000_opaque_type_invalid_use_p (gimple *stmt) @@ -28913,23 +28913,53 @@ rs6000_opaque_type_invalid_use_p (gimple *stmt) if (TARGET_MMA) return false; + /* If the given TYPE is one MMA opaque type, emit the corresponding + error messages and return true, otherwise return false. */ + auto check_and_error_invalid_use = [](tree type) + { + if (type == vector_quad_type_node) + { + error ("type %<__vector_quad%> requires the %qs option", "-mmma"); + return true; + } + else if (type == vector_pair_type_node) + { + error ("type %<__vector_pair%> requires the %qs option", "-mmma"); + return true; + } + return false; + }; + if (stmt) { /* The usage of MMA opaque types is very limited for now, - to check with gassign is enough so far. */ + to check with gassign and gasm is enough so far. */ if (gassign *ga = dyn_cast (stmt)) { tree lhs = gimple_assign_lhs (ga); tree type = TREE_TYPE (lhs); - if (type == vector_quad_type_node) + if (check_and_error_invalid_use (type)) + return true; + } + else if (gasm *gs = dyn_cast (stmt)) + { + unsigned ninputs = gimple_asm_ninputs (gs); + for (unsigned i = 0; i < ninputs; i++) { - error ("type %<__vector_quad%> requires the %qs option", "-mmma"); - return true; + tree op = gimple_asm_input_op (gs, i); + tree val = TREE_VALUE (op); + tree type = TREE_TYPE (val); + if (check_and_error_invalid_use (type)) + return true; } - else if (type == vector_pair_type_node) + unsigned noutputs = gimple_asm_noutputs (gs); + for (unsigned i = 0; i < noutputs; i++) { - error ("type %<__vector_pair%> requires the %qs option", "-mmma"); - return true; + tree op = gimple_asm_output_op (gs, i); + tree val = TREE_VALUE (op); + tree type = TREE_TYPE (val); + if (check_and_error_invalid_use (type)) + return true; } } } diff --git a/gcc/testsuite/gcc.target/powerpc/pr108272-1.c b/gcc/testsuite/gcc.target/powerpc/pr108272-1.c new file mode 100644 index 00000000000..b99e6a4d86d --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/pr108272-1.c @@ -0,0 +1,17 @@ +/* { dg-require-effective-target powerpc_p9modulo_ok } */ +/* If the default cpu type is power10 or later, type __vector_quad is + supported. To keep the test point available all the time, this case + specifies -mdejagnu-cpu=power9 here. */ +/* { dg-options "-mdejagnu-cpu=power9" } */ + +/* Verify there is no ICE and don't check the error messages on unsupported + type since they could be fragile and are not test points of this case. */ + +/* { dg-excess-errors "pr108272-1" } */ + +void +foo (void) +{ + __vector_quad acc; + asm("#..." : "=d"(acc)); +} diff --git a/gcc/testsuite/gcc.target/powerpc/pr108272-2.c b/gcc/testsuite/gcc.target/powerpc/pr108272-2.c new file mode 100644 index 00000000000..5ec12b85ba7 --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/pr108272-2.c @@ -0,0 +1,17 @@ +/* { dg-require-effective-target powerpc_p9modulo_ok } */ +/* If the default cpu type is power10 or later, type __vector_quad is + supported. To keep the test point available all the time, this case + specifies -mdejagnu-cpu=power9 here. */ +/* { dg-options "-mdejagnu-cpu=power9" } */ + +/* Verify there is no ICE and don't check the error messages on unsupported + type since they could be fragile and are not test points of this case. */ + +/* { dg-excess-errors "pr108272-2" } */ + +void +foo (void) +{ + __vector_quad acc; + asm("#..." :: "=d"(acc)); +}