From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=marvell.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=marvell.com 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding : content-type; s=pfpt0220; bh=EZeqInexam/wToYjqG68qV2lOpiAq13nU8u48RDcxEc=; b=QRgGHf7Z3hTRGhpr8M2VdDDW00L8VQaN6KFM8Mq0OJZ/7N2wA0Fe9sWZHW76CkApw/Kf NVkX/GKBDY4vUA0dOG6Sx8qxPeg7Y5BaYaThq688nfcq3Vg/LTW49smhatKLSFIG/fzA HDB+BGDpWzmOiSpYOBSIx/sipe1xjyW+73OpBkzq5lvyAnVB8+trBfv/98HlpMtJZehB uAQ4n93mMaNJsGJcc09wy3YshJenNZlHMs44KYGkTQwlrkmvLHxtt6OaE3qPwR6dTRo6 ezHH0oyBSkQIgUeujq4Us0J8CHwFU1yrZgHQIv7LPss8mookk8LwUMsDB+MIddtVZvKF mw== 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) From: Andrew Pinski 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 Content-Transfer-Encoding: 8bit Content-Type: text/plain 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 List-Id: 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 " } } */ -- 2.31.1