From patchwork Tue Jun 27 03:24:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 113187 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp7915536vqr; Mon, 26 Jun 2023 20:26:04 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ45yOgDwjj6VqcrEhhjo795VrfTRtCMGDSL3CqYIV7fUXWd89f6mclvtySB4Rs4Bljq/03n X-Received: by 2002:a17:907:2683:b0:975:63f4:46 with SMTP id bn3-20020a170907268300b0097563f40046mr25668619ejc.57.1687836364472; Mon, 26 Jun 2023 20:26:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687836364; cv=none; d=google.com; s=arc-20160816; b=scrLsOc1Szi93Y9p+trVoxchLlvBv6QmCyqXELKEo8uuoEcrMVg373FNB9Kc4zrVs0 nc02h8a60uxli6rnpz4uJml8QrjRxJcAoXGTX+1AWo6YKX+iHymGDf2KlaITdUigqMim ILCCCUhcPdDkNARdgR3qDZHSbzv/EltFdjE3y90A0HkSFB6A3GiQYzRe71jZt6JSn+Vo x0LUpdidWrd5M/g+na/QfxhZIwvzXw5pDipOkacH0+eSY5TBFqak1NrQPgvnQ9fiuEp1 w76E0KhODBvh4Ve10j7MKXird6oYOAnPERpD7CIy8rlku5WeFQSjW499H2EedjFNi3d4 hBOA== 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:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=EZeqInexam/wToYjqG68qV2lOpiAq13nU8u48RDcxEc=; fh=XbcmRug6/SzczusyoNU1I7Lu5oY0AN2u0mWDzKoxdSs=; b=N2crNywBRBIyJwJdki2Bq3Ab/cHY2BGaPlvnaGPGV+oC7RZECsVOan585XPMi629dk DUMrzrK6AcMd6Eur2M6j9t+Z9y9BRb2aMgLaax25GUK69EWtjvKY9mVR/ie7undh4Xj3 G4okxTV0ot2a+zous/3fxbfbh0v2RB/ASPELaj9ywfw5BUhxd7M7fMAe48VoDfhYe5nI V8ar9I033nmY5CrHAlD0R5PUo01xHiBf/G99jRqSqeFToaxAHdO/sSfLLHyQKD/6kFWy Am+Rxwc/3NLh1mBEXQ3r7S0PC/hn67jU3DMIH8lY5fKVqv7gNG3VVK+q11SrKe6XK2WO z0Hg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=tEYGfnkH; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id y21-20020a50e615000000b0051a52a48ed4si3682331edm.156.2023.06.26.20.26.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Jun 2023 20:26:04 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=tEYGfnkH; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 5FBC83858D33 for ; Tue, 27 Jun 2023 03:26:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5FBC83858D33 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1687836363; bh=EZeqInexam/wToYjqG68qV2lOpiAq13nU8u48RDcxEc=; h=To:CC:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=tEYGfnkHLLtKK3PM5UcpHkviSTaGXpB3CsQ+MG4aFOVtlTDNnWWBwDao4668iGQnB 5a7Ns4UJ41nb+KCLVNKmRQiO2/QXVvxwD+KEyzPF1tcxcEXc8cBpzgo4GcanutBNje pdzej+IzRGLrO7FOWxTQD4TZeretf70wjN4FQXhk= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by sourceware.org (Postfix) with ESMTPS id 5FCDA3858D32 for ; Tue, 27 Jun 2023 03:25:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5FCDA3858D32 Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 35R2H789030153 for ; Mon, 26 Jun 2023 20:25:18 -0700 Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3re00jxxx2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Mon, 26 Jun 2023 20:25:12 -0700 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Mon, 26 Jun 2023 20:24:58 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server id 15.0.1497.48 via Frontend Transport; Mon, 26 Jun 2023 20:24:58 -0700 Received: from vpnclient.wrightpinski.org.com (unknown [10.76.242.112]) by maili.marvell.com (Postfix) with ESMTP id 785FA3F707D; Mon, 26 Jun 2023 20:24:58 -0700 (PDT) To: CC: Andrew Pinski Subject: [PATCH] Mark asm goto with outputs as volatile Date: Mon, 26 Jun 2023 20:24:49 -0700 Message-ID: <20230627032449.37404-1-apinski@marvell.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Proofpoint-GUID: 2kWZWE4doB1VsOVK2-c8jo79CbFWU7Am X-Proofpoint-ORIG-GUID: 2kWZWE4doB1VsOVK2-c8jo79CbFWU7Am X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-06-26_20,2023-06-26_03,2023-05-22_02 X-Spam-Status: No, score=-14.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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: Andrew Pinski via Gcc-patches From: Andrew Pinski Reply-To: Andrew Pinski 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?1769824703609565991?= X-GMAIL-MSGID: =?utf-8?q?1769824703609565991?= The manual references asm goto as being implicitly volatile already and that was done when asm goto could not have outputs. When outputs were added to `asm goto`, only asm goto without outputs were still being marked as volatile. Now some parts of GCC decide, removing the `asm goto` is ok if the output is not used, though not updating the CFG (this happens on both the RTL level and the gimple level). Since the biggest user of `asm goto` is the Linux kernel and they expect them to be volatile (they use them to copy to/from userspace), we should just mark the inline-asm as volatile. OK? Bootstrapped and tested on x86_64-linux-gnu. PR middle-end/110420 PR middle-end/103979 PR middle-end/98619 gcc/ChangeLog: * gimplify.cc (gimplify_asm_expr): Mark asm with labels as volatile. gcc/testsuite/ChangeLog: * gcc.c-torture/compile/asmgoto-6.c: New test. --- gcc/gimplify.cc | 7 ++++- .../gcc.c-torture/compile/asmgoto-6.c | 26 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.c-torture/compile/asmgoto-6.c diff --git a/gcc/gimplify.cc b/gcc/gimplify.cc index 0e24b915b8f..dc6a00e8bd9 100644 --- a/gcc/gimplify.cc +++ b/gcc/gimplify.cc @@ -6935,7 +6935,12 @@ gimplify_asm_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p) stmt = gimple_build_asm_vec (TREE_STRING_POINTER (ASM_STRING (expr)), inputs, outputs, clobbers, labels); - gimple_asm_set_volatile (stmt, ASM_VOLATILE_P (expr) || noutputs == 0); + /* asm is volatile if it was marked by the user as volatile or + there is no outputs or this is an asm goto. */ + gimple_asm_set_volatile (stmt, + ASM_VOLATILE_P (expr) + || noutputs == 0 + || labels); gimple_asm_set_input (stmt, ASM_INPUT_P (expr)); gimple_asm_set_inline (stmt, ASM_INLINE_P (expr)); diff --git a/gcc/testsuite/gcc.c-torture/compile/asmgoto-6.c b/gcc/testsuite/gcc.c-torture/compile/asmgoto-6.c new file mode 100644 index 00000000000..0652bd4e4e1 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/asmgoto-6.c @@ -0,0 +1,26 @@ + +/* { dg-do compile } */ +/* PR middle-end/110420 */ +/* PR middle-end/103979 */ +/* PR middle-end/98619 */ +/* Test that the middle-end does not remove the asm goto + with an output. */ + +static int t; +void g(void); + +void f(void) +{ + int __gu_val; + asm goto("#my asm " + : "=&r"(__gu_val) + : + : + : Efault); + t = __gu_val; + g(); +Efault: +} + +/* Make sure "my asm " is still in the assembly. */ +/* { dg-final { scan-assembler "my asm " } } */