From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by sourceware.org (Postfix) with ESMTPS id 2F09E3858D28 for ; Tue, 27 Jun 2023 17:23:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2F09E3858D28 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-pl1-x633.google.com with SMTP id d9443c01a7336-1b7fb1a82c4so16910965ad.1 for ; Tue, 27 Jun 2023 10:23:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687886632; x=1690478632; 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=S6WpTotMjWXsspPOJcLkdnZgbsKvl0ZWcof4iJXSzVo=; b=ZuSeB5aqcsxs9J6C35vXIl0NUxl0GSwW+czUeu+NsP61aWSgv2bPDNSFgaHBMkRa2I 9PnUfXgHE0POOWh5vO2RSKsPam7qGwXU1gwmcRL8fnUaNXqd+qc/hmjs9O7Cgermz2/H sD4A1mObnyjYxbQVRwkegoFyVdnXVGsJmKjZ+JqZBjmlpXOATK3d1qF41qBadJU3+lPZ CUuDZn7TNaU5fU3c92Wp5/jv6A8U9K3NMCRGPBHOJDWXzrsVKW48FxQpXLK44US1iIJq 4JnCCuHfQEya2ERbXuoIybhKXhT+08//BXoj7KaYeYJS3br6ZHrmC0bNnYR23edUfrac nBsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687886632; x=1690478632; 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=S6WpTotMjWXsspPOJcLkdnZgbsKvl0ZWcof4iJXSzVo=; b=MQ2DAPEeD1H/m+Sm9cJ7MHwMOLGJ0KsJwCKh1NleBe576olG0wzU5Kwr2nzwYHlDWO RKHwbcgCXrr5UD47/4brXwn1KVrdmKFqsxDYs1YsgNRa8i5gl13y+YuGufJS6gS08ipu Tzjyy7eYvEDggmM+fNQ7NMcuj/E+kfuzj7Slr3BlP494rIwt+tJE0KtKBrRLrtpt7Z54 5WA/u2yK/0lZZSqqnhN3f9LYkshucOdwfsAGQfH/pFyKhq0ayGAvpNbQQuIpw1w0YLk7 EkJO+Kj7UePwQCY+gcJ8Di6p5j84wDHvLpKPvy2vgbNyKu5m1X1orwULFuyY9Wz88n38 VE1Q== X-Gm-Message-State: AC+VfDyr88RZyCbZnt+QztJ0LY9X/t5LMRvlg0CAMvxYW8uFpzLwQhf7 38fxL6fN1srVovXB7YJfpoA8wfD6hqTBIWh+mp0= X-Google-Smtp-Source: ACHHUZ4e9kdHGK+F9fni5Vffcqbx8ZYjIMDSvQvqavKIftIU+9XcxzM1PkwKjsL5NRF+CHVgMIReQTj9UIUCyhzMVGQ= X-Received: by 2002:a17:90a:ce17:b0:263:1661:1d1a with SMTP id f23-20020a17090ace1700b0026316611d1amr2162786pju.7.1687886632043; Tue, 27 Jun 2023 10:23:52 -0700 (PDT) MIME-Version: 1.0 References: <20230627032449.37404-1-apinski@marvell.com> In-Reply-To: From: Andrew Pinski Date: Tue, 27 Jun 2023 10:23:38 -0700 Message-ID: Subject: Re: [PATCH] Mark asm goto with outputs as volatile To: Richard Biener Cc: Andrew Pinski , gcc-patches@gcc.gnu.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-7.6 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 12:14=E2=80=AFAM Richard Biener via Gcc-patches wrote: > > 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 bein= g > > marked as volatile. Now some parts of GCC decide, removing the `asm got= o` > > is ok if the output is not used, though not updating the CFG (this happ= ens > > 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. > > OK. Committed to GCC 12 and GCC 13 branches also. Thanks, Andrew > > > PR middle-end/110420 > > PR middle-end/103979 > > PR middle-end/98619 > > > > gcc/ChangeLog: > > > > * gimplify.cc (gimplify_asm_expr): Mark asm with labels as vola= tile. > > > > 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 (= expr)), > > 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/test= suite/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 > >