From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-x22a.google.com (mail-lj1-x22a.google.com [IPv6:2a00:1450:4864:20::22a]) by sourceware.org (Postfix) with ESMTPS id ADFCE3858D33 for ; Tue, 27 Jun 2023 07:13:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org ADFCE3858D33 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lj1-x22a.google.com with SMTP id 38308e7fff4ca-2b698dd515dso37302751fa.3 for ; Tue, 27 Jun 2023 00:13:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687850033; x=1690442033; 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=4xUbHQ7nBts9upiXcfUlVOdE1WO8yRR47a/rfJVyl4s=; b=qcNZbZQIE6B61TUCmmvT0VGfQeFvK6wINY2gey6k/1jJCm5uD0+YvLaXLrBjW6/w/E RBV1Nqmy4jlmyGbUYFgPtSzEDnAm3nIMuvASPRqk6irzClf/DSLCUbDMUlSMwDHPzFXs LLZkMZevCYmAdvGvjaAvXEta7BXFKOWj6MVAcHJFL+ysBT9FHGGCXfnTs1MAINLx1Sxm BhPWAZ3KH2wQN19dxwC8MyUqZmKqinH3q/KLx8+AT2TmKpMmfQyQDC5FjTSChJFbCeT4 a7NbthyS9EIDE+DLKMwr6NAvSOXDIIDFIFF5OpXeNrWne2QaWVi+8eNnz7fyDpWQUFsI PbOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687850033; x=1690442033; 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=4xUbHQ7nBts9upiXcfUlVOdE1WO8yRR47a/rfJVyl4s=; b=S/KZ4ykK4O5o/8YUFKat3w3EpxpBgc7UUrAp3eDBQSss9J07ISp6My9al80HKnJR7b Uyq13lIsXwXOGRQTId0biDkGNF8BWzaZOtJW5oo11wTNsfrp754lfBDx7hoL9NkrpuZq e9KMv5Nwq4f4KTgxzykvfFoI+IIgXtLGegglB5gw50+t0En18ZoZhf40mOyzSoaeqO7/ 9rchgZNoel4eCJP+0Rk7uXJZahCPf3QXQx3Yo/JyqcxTVkZz3lZbxjxZyXTKf+1CU0oL 8MoM/KgccNboUzp6tbSjlycVBtk3h0GQ6o3qsyW0PXApNdgsS7qaeHdUZpXXKKmz4X4K WA2Q== X-Gm-Message-State: AC+VfDwnc0yZ2qYUi1AA49LZWB/0Ooo9Uu/J2hhVUTlP5t4LGq7qEEQR E+a2ojT5f0qrELNG04yEXi5Y9TC3MbYpsV1sKGA= X-Google-Smtp-Source: ACHHUZ4+9TrUHlPi3lMINhXXdYk93bPLxPA1ABeyxbuEOVJmxxVoe/RNCdMm/gW/0+lO+9otLCTNE2xIjqrDelUpHY0= X-Received: by 2002:a2e:888b:0:b0:2b5:80dd:5e65 with SMTP id k11-20020a2e888b000000b002b580dd5e65mr11674756lji.48.1687850033171; Tue, 27 Jun 2023 00:13:53 -0700 (PDT) MIME-Version: 1.0 References: <20230627032449.37404-1-apinski@marvell.com> In-Reply-To: <20230627032449.37404-1-apinski@marvell.com> From: Richard Biener Date: Tue, 27 Jun 2023 09:13:41 +0200 Message-ID: Subject: Re: [PATCH] Mark asm goto with outputs as volatile To: Andrew Pinski Cc: gcc-patches@gcc.gnu.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,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: On Tue, Jun 27, 2023 at 5:26=E2=80=AFAM Andrew Pinski via Gcc-patches wrote: > > 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 happen= s > on both the RTL level and the gimple level). Since the biggest user of `a= sm 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. OK. > PR middle-end/110420 > PR middle-end/103979 > PR middle-end/98619 > > gcc/ChangeLog: > > * gimplify.cc (gimplify_asm_expr): Mark asm with labels as volati= le. > > 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 =3D gimple_build_asm_vec (TREE_STRING_POINTER (ASM_STRING (ex= pr)), > inputs, outputs, clobbers, labels); > > - gimple_asm_set_volatile (stmt, ASM_VOLATILE_P (expr) || noutputs = =3D=3D 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 =3D=3D 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/testsu= ite/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 " > + : "=3D&r"(__gu_val) > + : > + : > + : Efault); > + t =3D __gu_val; > + g(); > +Efault: > +} > + > +/* Make sure "my asm " is still in the assembly. */ > +/* { dg-final { scan-assembler "my asm " } } */ > -- > 2.31.1 >