Message ID | 20220222135513.GA1591@delia.home |
---|---|
State | New |
Headers |
Return-Path: <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 436033857823 for <patchwork@sourceware.org>; Tue, 22 Feb 2022 13:55:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 436033857823 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1645538146; bh=smKCi5Ixqy1+4OTpWMlOET8jY07ctwZNyn7UnwAU08g=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=t3fZzxlKfiIjREIoVz0ueRXQDQsrW/RwDs3Rl3EcPRmWK0GfYeGjARkgWhuKBbHpU b9Am4DuSAuua5ayhgvkXlf+XBC6ObMV1p5atnuqJ9sptle+MiSp7woeJr9AT+232NX dgUtwlK611YB0DDvmWgCByq2RDQakvms0rbBLn4o= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id 3261B385801D for <gcc-patches@gcc.gnu.org>; Tue, 22 Feb 2022 13:55:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3261B385801D Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 5B87721102 for <gcc-patches@gcc.gnu.org>; Tue, 22 Feb 2022 13:55:16 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 46EE113B98 for <gcc-patches@gcc.gnu.org>; Tue, 22 Feb 2022 13:55:16 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id Qz5CEETrFGLtbwAAMHmgww (envelope-from <tdevries@suse.de>) for <gcc-patches@gcc.gnu.org>; Tue, 22 Feb 2022 13:55:16 +0000 Date: Tue, 22 Feb 2022 14:55:14 +0100 To: gcc-patches@gcc.gnu.org Subject: [PATCH][final] Handle compiler-generated asm insn Message-ID: <20220222135513.GA1591@delia.home> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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 <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> From: Tom de Vries via Gcc-patches <gcc-patches@gcc.gnu.org> Reply-To: Tom de Vries <tdevries@suse.de> Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> |
Series |
[final] Handle compiler-generated asm insn
|
|
Commit Message
Tom de Vries
Feb. 22, 2022, 1:55 p.m. UTC
Hi, For the nvptx port, with -mptx-comment we have in pr53465.s: ... // #APP // 9 "gcc/testsuite/gcc.c-torture/execute/pr53465.c" 1 // Start: Added by -minit-regs=3: // #NO_APP mov.u32 %r26, 0; // #APP // 9 "gcc/testsuite/gcc.c-torture/execute/pr53465.c" 1 // End: Added by -minit-regs=3: // #NO_APP ... The comments where generated using the compiler-generated equivalent of: ... asm ("// Comment"); ... but both the printed location and the NO_APP/APP are unnecessary for a compiler-generated asm insn. Fix this by handling ASM_INPUT_SOURCE_LOCATION == UNKNOWN_LOCATION in final_scan_insn_1, such what we simply get: ... // Start: Added by -minit-regs=3: mov.u32 %r26, 0; // End: Added by -minit-regs=3: ... Tested on nvptx. OK for trunk? Thanks, - Tom [final] Handle compiler-generated asm insn gcc/ChangeLog: 2022-02-21 Tom de Vries <tdevries@suse.de> PR rtl-optimization/104596 * config/nvptx/nvptx.cc (gen_comment): Use gen_rtx_ASM_INPUT instead of gen_rtx_ASM_INPUT_loc. * final.cc (final_scan_insn_1): Handle ASM_INPUT_SOURCE_LOCATION == UNKNOWN_LOCATION. --- gcc/config/nvptx/nvptx.cc | 3 +-- gcc/final.cc | 17 +++++++++++------ 2 files changed, 12 insertions(+), 8 deletions(-)
Comments
On 2/22/22 14:55, Tom de Vries wrote: > Hi, > > For the nvptx port, with -mptx-comment we have in pr53465.s: > ... > // #APP > // 9 "gcc/testsuite/gcc.c-torture/execute/pr53465.c" 1 > // Start: Added by -minit-regs=3: > // #NO_APP > mov.u32 %r26, 0; > // #APP > // 9 "gcc/testsuite/gcc.c-torture/execute/pr53465.c" 1 > // End: Added by -minit-regs=3: > // #NO_APP > ... > > The comments where generated using the compiler-generated equivalent of: > ... > asm ("// Comment"); > ... > but both the printed location and the NO_APP/APP are unnecessary for a > compiler-generated asm insn. > > Fix this by handling ASM_INPUT_SOURCE_LOCATION == UNKNOWN_LOCATION in > final_scan_insn_1, such what we simply get: > ... > // Start: Added by -minit-regs=3: > mov.u32 %r26, 0; > // End: Added by -minit-regs=3: > ... > > Tested on nvptx. > > OK for trunk? > Ping. Thanks, - Tom > [final] Handle compiler-generated asm insn > > gcc/ChangeLog: > > 2022-02-21 Tom de Vries <tdevries@suse.de> > > PR rtl-optimization/104596 > * config/nvptx/nvptx.cc (gen_comment): Use gen_rtx_ASM_INPUT instead > of gen_rtx_ASM_INPUT_loc. > * final.cc (final_scan_insn_1): Handle > ASM_INPUT_SOURCE_LOCATION == UNKNOWN_LOCATION. > > --- > gcc/config/nvptx/nvptx.cc | 3 +-- > gcc/final.cc | 17 +++++++++++------ > 2 files changed, 12 insertions(+), 8 deletions(-) > > diff --git a/gcc/config/nvptx/nvptx.cc b/gcc/config/nvptx/nvptx.cc > index 858789e6df7..4124c597f24 100644 > --- a/gcc/config/nvptx/nvptx.cc > +++ b/gcc/config/nvptx/nvptx.cc > @@ -5381,8 +5381,7 @@ gen_comment (const char *s) > size_t len = strlen (ASM_COMMENT_START) + strlen (sep) + strlen (s) + 1; > char *comment = (char *) alloca (len); > snprintf (comment, len, "%s%s%s", ASM_COMMENT_START, sep, s); > - return gen_rtx_ASM_INPUT_loc (VOIDmode, ggc_strdup (comment), > - cfun->function_start_locus); > + return gen_rtx_ASM_INPUT (VOIDmode, ggc_strdup (comment)); > } > > /* Initialize all declared regs at function entry. > diff --git a/gcc/final.cc b/gcc/final.cc > index a9868861bd2..e6443ef7a4f 100644 > --- a/gcc/final.cc > +++ b/gcc/final.cc > @@ -2642,15 +2642,20 @@ final_scan_insn_1 (rtx_insn *insn, FILE *file, int optimize_p ATTRIBUTE_UNUSED, > if (string[0]) > { > expanded_location loc; > + bool unknown_loc_p > + = ASM_INPUT_SOURCE_LOCATION (body) == UNKNOWN_LOCATION; > > - app_enable (); > - loc = expand_location (ASM_INPUT_SOURCE_LOCATION (body)); > - if (*loc.file && loc.line) > - fprintf (asm_out_file, "%s %i \"%s\" 1\n", > - ASM_COMMENT_START, loc.line, loc.file); > + if (!unknown_loc_p) > + { > + app_enable (); > + loc = expand_location (ASM_INPUT_SOURCE_LOCATION (body)); > + if (*loc.file && loc.line) > + fprintf (asm_out_file, "%s %i \"%s\" 1\n", > + ASM_COMMENT_START, loc.line, loc.file); > + } > fprintf (asm_out_file, "\t%s\n", string); > #if HAVE_AS_LINE_ZERO > - if (*loc.file && loc.line) > + if (!unknown_loc_p && loc.file && *loc.file && loc.line) > fprintf (asm_out_file, "%s 0 \"\" 2\n", ASM_COMMENT_START); > #endif > }
On 3/9/22 13:50, Tom de Vries wrote: > On 2/22/22 14:55, Tom de Vries wrote: >> Hi, >> >> For the nvptx port, with -mptx-comment we have in pr53465.s: >> ... >> // #APP >> // 9 "gcc/testsuite/gcc.c-torture/execute/pr53465.c" 1 >> // Start: Added by -minit-regs=3: >> // #NO_APP >> mov.u32 %r26, 0; >> // #APP >> // 9 "gcc/testsuite/gcc.c-torture/execute/pr53465.c" 1 >> // End: Added by -minit-regs=3: >> // #NO_APP >> ... >> >> The comments where generated using the compiler-generated equivalent of: >> ... >> asm ("// Comment"); >> ... >> but both the printed location and the NO_APP/APP are unnecessary for a >> compiler-generated asm insn. >> >> Fix this by handling ASM_INPUT_SOURCE_LOCATION == UNKNOWN_LOCATION in >> final_scan_insn_1, such what we simply get: >> ... >> // Start: Added by -minit-regs=3: >> mov.u32 %r26, 0; >> // End: Added by -minit-regs=3: >> ... >> >> Tested on nvptx. >> >> OK for trunk? >> > Ping^2. Tobias just reported an ICE in PR104968, and this patch fixes it. I'd like to known whether this patch is acceptable for stage 4 or not. If not, I need to fix PR104968 in a different way. Say, disable -mcomment by default, or trying harder to propagate source info on outlined functions. Thanks, - Tom >> [final] Handle compiler-generated asm insn >> >> gcc/ChangeLog: >> >> 2022-02-21 Tom de Vries <tdevries@suse.de> >> >> PR rtl-optimization/104596 >> * config/nvptx/nvptx.cc (gen_comment): Use gen_rtx_ASM_INPUT instead >> of gen_rtx_ASM_INPUT_loc. >> * final.cc (final_scan_insn_1): Handle >> ASM_INPUT_SOURCE_LOCATION == UNKNOWN_LOCATION. >> >> --- >> gcc/config/nvptx/nvptx.cc | 3 +-- >> gcc/final.cc | 17 +++++++++++------ >> 2 files changed, 12 insertions(+), 8 deletions(-) >> >> diff --git a/gcc/config/nvptx/nvptx.cc b/gcc/config/nvptx/nvptx.cc >> index 858789e6df7..4124c597f24 100644 >> --- a/gcc/config/nvptx/nvptx.cc >> +++ b/gcc/config/nvptx/nvptx.cc >> @@ -5381,8 +5381,7 @@ gen_comment (const char *s) >> size_t len = strlen (ASM_COMMENT_START) + strlen (sep) + strlen >> (s) + 1; >> char *comment = (char *) alloca (len); >> snprintf (comment, len, "%s%s%s", ASM_COMMENT_START, sep, s); >> - return gen_rtx_ASM_INPUT_loc (VOIDmode, ggc_strdup (comment), >> - cfun->function_start_locus); >> + return gen_rtx_ASM_INPUT (VOIDmode, ggc_strdup (comment)); >> } >> /* Initialize all declared regs at function entry. >> diff --git a/gcc/final.cc b/gcc/final.cc >> index a9868861bd2..e6443ef7a4f 100644 >> --- a/gcc/final.cc >> +++ b/gcc/final.cc >> @@ -2642,15 +2642,20 @@ final_scan_insn_1 (rtx_insn *insn, FILE *file, >> int optimize_p ATTRIBUTE_UNUSED, >> if (string[0]) >> { >> expanded_location loc; >> + bool unknown_loc_p >> + = ASM_INPUT_SOURCE_LOCATION (body) == UNKNOWN_LOCATION; >> - app_enable (); >> - loc = expand_location (ASM_INPUT_SOURCE_LOCATION (body)); >> - if (*loc.file && loc.line) >> - fprintf (asm_out_file, "%s %i \"%s\" 1\n", >> - ASM_COMMENT_START, loc.line, loc.file); >> + if (!unknown_loc_p) >> + { >> + app_enable (); >> + loc = expand_location (ASM_INPUT_SOURCE_LOCATION (body)); >> + if (*loc.file && loc.line) >> + fprintf (asm_out_file, "%s %i \"%s\" 1\n", >> + ASM_COMMENT_START, loc.line, loc.file); >> + } >> fprintf (asm_out_file, "\t%s\n", string); >> #if HAVE_AS_LINE_ZERO >> - if (*loc.file && loc.line) >> + if (!unknown_loc_p && loc.file && *loc.file && loc.line) >> fprintf (asm_out_file, "%s 0 \"\" 2\n", ASM_COMMENT_START); >> #endif >> }
On Thu, Mar 17, 2022 at 4:10 PM Tom de Vries via Gcc-patches <gcc-patches@gcc.gnu.org> wrote: > > On 3/9/22 13:50, Tom de Vries wrote: > > On 2/22/22 14:55, Tom de Vries wrote: > >> Hi, > >> > >> For the nvptx port, with -mptx-comment we have in pr53465.s: > >> ... > >> // #APP > >> // 9 "gcc/testsuite/gcc.c-torture/execute/pr53465.c" 1 > >> // Start: Added by -minit-regs=3: > >> // #NO_APP > >> mov.u32 %r26, 0; > >> // #APP > >> // 9 "gcc/testsuite/gcc.c-torture/execute/pr53465.c" 1 > >> // End: Added by -minit-regs=3: > >> // #NO_APP > >> ... > >> > >> The comments where generated using the compiler-generated equivalent of: > >> ... > >> asm ("// Comment"); > >> ... > >> but both the printed location and the NO_APP/APP are unnecessary for a > >> compiler-generated asm insn. > >> > >> Fix this by handling ASM_INPUT_SOURCE_LOCATION == UNKNOWN_LOCATION in > >> final_scan_insn_1, such what we simply get: > >> ... > >> // Start: Added by -minit-regs=3: > >> mov.u32 %r26, 0; > >> // End: Added by -minit-regs=3: > >> ... > >> > >> Tested on nvptx. > >> > >> OK for trunk? > >> > > > > Ping^2. > > Tobias just reported an ICE in PR104968, and this patch fixes it. > > I'd like to known whether this patch is acceptable for stage 4 or not. > > If not, I need to fix PR104968 in a different way. Say, disable > -mcomment by default, or trying harder to propagate source info on > outlined functions. Usually targets use UNSPECs to emit compiler-generated "asm" instructions. I think an unknown location is a reasonable but not the best way to identify 'compiler-generated', we might lose the location through optimization. (why does it not use the INSN_LOCATION?) Rather than a location I'd use sth like DECL_ARTIFICIAL to disable 'user-mangling', do we have something like that for ASM or an insn in general? If not maybe there's an unused bit on ASMs we can enable this way. IIRC some of the Ada hardening GIMPLE passes also emit ASMs that could 'benefit' from this. Richard. > Thanks, > - Tom > > >> [final] Handle compiler-generated asm insn > >> > >> gcc/ChangeLog: > >> > >> 2022-02-21 Tom de Vries <tdevries@suse.de> > >> > >> PR rtl-optimization/104596 > >> * config/nvptx/nvptx.cc (gen_comment): Use gen_rtx_ASM_INPUT instead > >> of gen_rtx_ASM_INPUT_loc. > >> * final.cc (final_scan_insn_1): Handle > >> ASM_INPUT_SOURCE_LOCATION == UNKNOWN_LOCATION. > >> > >> --- > >> gcc/config/nvptx/nvptx.cc | 3 +-- > >> gcc/final.cc | 17 +++++++++++------ > >> 2 files changed, 12 insertions(+), 8 deletions(-) > >> > >> diff --git a/gcc/config/nvptx/nvptx.cc b/gcc/config/nvptx/nvptx.cc > >> index 858789e6df7..4124c597f24 100644 > >> --- a/gcc/config/nvptx/nvptx.cc > >> +++ b/gcc/config/nvptx/nvptx.cc > >> @@ -5381,8 +5381,7 @@ gen_comment (const char *s) > >> size_t len = strlen (ASM_COMMENT_START) + strlen (sep) + strlen > >> (s) + 1; > >> char *comment = (char *) alloca (len); > >> snprintf (comment, len, "%s%s%s", ASM_COMMENT_START, sep, s); > >> - return gen_rtx_ASM_INPUT_loc (VOIDmode, ggc_strdup (comment), > >> - cfun->function_start_locus); > >> + return gen_rtx_ASM_INPUT (VOIDmode, ggc_strdup (comment)); > >> } > >> /* Initialize all declared regs at function entry. > >> diff --git a/gcc/final.cc b/gcc/final.cc > >> index a9868861bd2..e6443ef7a4f 100644 > >> --- a/gcc/final.cc > >> +++ b/gcc/final.cc > >> @@ -2642,15 +2642,20 @@ final_scan_insn_1 (rtx_insn *insn, FILE *file, > >> int optimize_p ATTRIBUTE_UNUSED, > >> if (string[0]) > >> { > >> expanded_location loc; > >> + bool unknown_loc_p > >> + = ASM_INPUT_SOURCE_LOCATION (body) == UNKNOWN_LOCATION; > >> - app_enable (); > >> - loc = expand_location (ASM_INPUT_SOURCE_LOCATION (body)); > >> - if (*loc.file && loc.line) > >> - fprintf (asm_out_file, "%s %i \"%s\" 1\n", > >> - ASM_COMMENT_START, loc.line, loc.file); > >> + if (!unknown_loc_p) > >> + { > >> + app_enable (); > >> + loc = expand_location (ASM_INPUT_SOURCE_LOCATION (body)); > >> + if (*loc.file && loc.line) > >> + fprintf (asm_out_file, "%s %i \"%s\" 1\n", > >> + ASM_COMMENT_START, loc.line, loc.file); > >> + } > >> fprintf (asm_out_file, "\t%s\n", string); > >> #if HAVE_AS_LINE_ZERO > >> - if (*loc.file && loc.line) > >> + if (!unknown_loc_p && loc.file && *loc.file && loc.line) > >> fprintf (asm_out_file, "%s 0 \"\" 2\n", ASM_COMMENT_START); > >> #endif > >> }
On 3/21/22 08:58, Richard Biener wrote: > On Thu, Mar 17, 2022 at 4:10 PM Tom de Vries via Gcc-patches > <gcc-patches@gcc.gnu.org> wrote: >> >> On 3/9/22 13:50, Tom de Vries wrote: >>> On 2/22/22 14:55, Tom de Vries wrote: >>>> Hi, >>>> >>>> For the nvptx port, with -mptx-comment we have in pr53465.s: >>>> ... >>>> // #APP >>>> // 9 "gcc/testsuite/gcc.c-torture/execute/pr53465.c" 1 >>>> // Start: Added by -minit-regs=3: >>>> // #NO_APP >>>> mov.u32 %r26, 0; >>>> // #APP >>>> // 9 "gcc/testsuite/gcc.c-torture/execute/pr53465.c" 1 >>>> // End: Added by -minit-regs=3: >>>> // #NO_APP >>>> ... >>>> >>>> The comments where generated using the compiler-generated equivalent of: >>>> ... >>>> asm ("// Comment"); >>>> ... >>>> but both the printed location and the NO_APP/APP are unnecessary for a >>>> compiler-generated asm insn. >>>> >>>> Fix this by handling ASM_INPUT_SOURCE_LOCATION == UNKNOWN_LOCATION in >>>> final_scan_insn_1, such what we simply get: >>>> ... >>>> // Start: Added by -minit-regs=3: >>>> mov.u32 %r26, 0; >>>> // End: Added by -minit-regs=3: >>>> ... >>>> >>>> Tested on nvptx. >>>> >>>> OK for trunk? >>>> >>> >> >> Ping^2. >> >> Tobias just reported an ICE in PR104968, and this patch fixes it. >> >> I'd like to known whether this patch is acceptable for stage 4 or not. >> >> If not, I need to fix PR104968 in a different way. Say, disable >> -mcomment by default, or trying harder to propagate source info on >> outlined functions. > Hi, thanks for the review. > Usually targets use UNSPECs to emit compiler-generated "asm" > instructions. Ack. [ I could go down that route eventually, but for now I'm hoping to implement this without having to change the port. ] > I think an unknown location is a reasonable but not > the best way to identify 'compiler-generated', we might lose > the location through optimization. (why does it not use > the INSN_LOCATION?) > I don't know. FWIW, at the time that ASM_INPUT_SOURCE_LOCATION was introduced (2007), there was no INSN_LOCATION yet (introduced in 2012), only INSN_LOCATOR, my guess is that it has something to do with that. > Rather than a location I'd use sth like DECL_ARTIFICIAL to > disable 'user-mangling', do we have something like that for > ASM or an insn in general? Haven't found it. > If not maybe there's an unused > bit on ASMs we can enable this way. Done. I've used the jump flag for that. Updated, untested patch attached. Is this what you meant? Thanks, - Tom
On Mon, Mar 21, 2022 at 12:50 PM Tom de Vries <tdevries@suse.de> wrote: > > On 3/21/22 08:58, Richard Biener wrote: > > On Thu, Mar 17, 2022 at 4:10 PM Tom de Vries via Gcc-patches > > <gcc-patches@gcc.gnu.org> wrote: > >> > >> On 3/9/22 13:50, Tom de Vries wrote: > >>> On 2/22/22 14:55, Tom de Vries wrote: > >>>> Hi, > >>>> > >>>> For the nvptx port, with -mptx-comment we have in pr53465.s: > >>>> ... > >>>> // #APP > >>>> // 9 "gcc/testsuite/gcc.c-torture/execute/pr53465.c" 1 > >>>> // Start: Added by -minit-regs=3: > >>>> // #NO_APP > >>>> mov.u32 %r26, 0; > >>>> // #APP > >>>> // 9 "gcc/testsuite/gcc.c-torture/execute/pr53465.c" 1 > >>>> // End: Added by -minit-regs=3: > >>>> // #NO_APP > >>>> ... > >>>> > >>>> The comments where generated using the compiler-generated equivalent of: > >>>> ... > >>>> asm ("// Comment"); > >>>> ... > >>>> but both the printed location and the NO_APP/APP are unnecessary for a > >>>> compiler-generated asm insn. > >>>> > >>>> Fix this by handling ASM_INPUT_SOURCE_LOCATION == UNKNOWN_LOCATION in > >>>> final_scan_insn_1, such what we simply get: > >>>> ... > >>>> // Start: Added by -minit-regs=3: > >>>> mov.u32 %r26, 0; > >>>> // End: Added by -minit-regs=3: > >>>> ... > >>>> > >>>> Tested on nvptx. > >>>> > >>>> OK for trunk? > >>>> > >>> > >> > >> Ping^2. > >> > >> Tobias just reported an ICE in PR104968, and this patch fixes it. > >> > >> I'd like to known whether this patch is acceptable for stage 4 or not. > >> > >> If not, I need to fix PR104968 in a different way. Say, disable > >> -mcomment by default, or trying harder to propagate source info on > >> outlined functions. > > > > Hi, > > thanks for the review. > > > Usually targets use UNSPECs to emit compiler-generated "asm" > > instructions. > > Ack. [ I could go down that route eventually, but for now I'm hoping to > implement this without having to change the port. ] > > > I think an unknown location is a reasonable but not > > the best way to identify 'compiler-generated', we might lose > > the location through optimization. (why does it not use > > the INSN_LOCATION?) > > > > I don't know. FWIW, at the time that ASM_INPUT_SOURCE_LOCATION was > introduced (2007), there was no INSN_LOCATION yet (introduced in 2012), > only INSN_LOCATOR, my guess is that it has something to do with that. > > > Rather than a location I'd use sth like DECL_ARTIFICIAL to > > disable 'user-mangling', do we have something like that for > > ASM or an insn in general? > > Haven't found it. > > > If not maybe there's an unused > > bit on ASMs we can enable this way. > > Done. I've used the jump flag for that. > > Updated, untested patch attached. > > Is this what you meant? Hmm. I now read that ASM_INPUT is in every PATTERN of an insn and wonder how this all works out there. That is, by default the ASM_INPUT would be artificial (for regular define_insn) but asm("") in source would mark them ASM_INPUT_USER_P or so. But then I know nothing here. I did expect us to look at ASM_OPERANDS instead of just ASM_INPUT (but the code you are changing is about ASM_INPUT). That said, the comments should probably explicitely say this is about ASM_INPUT in an ASM_OPERANDS instruction template, not some other pattern. But yes, this was kind-of what I meant. Any considerations from others? Thanks, Richard. > > Thanks, > - Tom
On 3/21/22 14:49, Richard Biener wrote: > On Mon, Mar 21, 2022 at 12:50 PM Tom de Vries <tdevries@suse.de> wrote: >> >> On 3/21/22 08:58, Richard Biener wrote: >>> On Thu, Mar 17, 2022 at 4:10 PM Tom de Vries via Gcc-patches >>> <gcc-patches@gcc.gnu.org> wrote: >>>> >>>> On 3/9/22 13:50, Tom de Vries wrote: >>>>> On 2/22/22 14:55, Tom de Vries wrote: >>>>>> Hi, >>>>>> >>>>>> For the nvptx port, with -mptx-comment we have in pr53465.s: >>>>>> ... >>>>>> // #APP >>>>>> // 9 "gcc/testsuite/gcc.c-torture/execute/pr53465.c" 1 >>>>>> // Start: Added by -minit-regs=3: >>>>>> // #NO_APP >>>>>> mov.u32 %r26, 0; >>>>>> // #APP >>>>>> // 9 "gcc/testsuite/gcc.c-torture/execute/pr53465.c" 1 >>>>>> // End: Added by -minit-regs=3: >>>>>> // #NO_APP >>>>>> ... >>>>>> >>>>>> The comments where generated using the compiler-generated equivalent of: >>>>>> ... >>>>>> asm ("// Comment"); >>>>>> ... >>>>>> but both the printed location and the NO_APP/APP are unnecessary for a >>>>>> compiler-generated asm insn. >>>>>> >>>>>> Fix this by handling ASM_INPUT_SOURCE_LOCATION == UNKNOWN_LOCATION in >>>>>> final_scan_insn_1, such what we simply get: >>>>>> ... >>>>>> // Start: Added by -minit-regs=3: >>>>>> mov.u32 %r26, 0; >>>>>> // End: Added by -minit-regs=3: >>>>>> ... >>>>>> >>>>>> Tested on nvptx. >>>>>> >>>>>> OK for trunk? >>>>>> >>>>> >>>> >>>> Ping^2. >>>> >>>> Tobias just reported an ICE in PR104968, and this patch fixes it. >>>> >>>> I'd like to known whether this patch is acceptable for stage 4 or not. >>>> >>>> If not, I need to fix PR104968 in a different way. Say, disable >>>> -mcomment by default, or trying harder to propagate source info on >>>> outlined functions. >>> >> >> Hi, >> >> thanks for the review. >> >>> Usually targets use UNSPECs to emit compiler-generated "asm" >>> instructions. >> >> Ack. [ I could go down that route eventually, but for now I'm hoping to >> implement this without having to change the port. ] >> >>> I think an unknown location is a reasonable but not >>> the best way to identify 'compiler-generated', we might lose >>> the location through optimization. (why does it not use >>> the INSN_LOCATION?) >>> >> >> I don't know. FWIW, at the time that ASM_INPUT_SOURCE_LOCATION was >> introduced (2007), there was no INSN_LOCATION yet (introduced in 2012), >> only INSN_LOCATOR, my guess is that it has something to do with that. >> >>> Rather than a location I'd use sth like DECL_ARTIFICIAL to >>> disable 'user-mangling', do we have something like that for >>> ASM or an insn in general? >> >> Haven't found it. >> >>> If not maybe there's an unused >>> bit on ASMs we can enable this way. >> >> Done. I've used the jump flag for that. >> >> Updated, untested patch attached. >> >> Is this what you meant? > > Hmm. I now read that ASM_INPUT is in every PATTERN of an insn Maybe I misunderstand, but that sounds incorrect to me. That is, can you point me to where you read that? Maybe you're referring to the fact that an ASM_INPUT may occur inside an ASM_OPERANDS, as "a convenient way to hold a string" (quoting rtl.def)? > and wonder how this all works out there. That is, by default the > ASM_INPUT would be artificial (for regular define_insn) but asm("") > in source would mark them ASM_INPUT_USER_P or so. > If you're suggesting to make it by default artificial, then that doesn't sound like a bad idea to me. In this iteration I haven't implemented this (yet), but instead explicitly marked as artificial some other uses of ASM_INPUT. > But then I know nothing here. I did expect us to look at > ASM_OPERANDS instead of just ASM_INPUT (but the code you > are changing is about ASM_INPUT). > I extended the rationale in the commit log a bit to include a description of what the rtl-equivalent of 'asm ("// Comment")' looks like, and there's no ASM_OPERANDS there. > That said, the comments should probably explicitely say this > is about ASM_INPUT in an ASM_OPERANDS instruction > template, not some other pattern. > AFAIU, this isn't about an ASM_INPUT in an ASM_OPERANDS instruction template, so at this point I haven't updated the comment. Thanks, - Tom
On 3/21/2022 10:14 AM, Tom de Vries via Gcc-patches wrote: > On 3/21/22 14:49, Richard Biener wrote: >> On Mon, Mar 21, 2022 at 12:50 PM Tom de Vries <tdevries@suse.de> wrote: >>> >>> On 3/21/22 08:58, Richard Biener wrote: >>>> On Thu, Mar 17, 2022 at 4:10 PM Tom de Vries via Gcc-patches >>>> <gcc-patches@gcc.gnu.org> wrote: >>>>> >>>>> On 3/9/22 13:50, Tom de Vries wrote: >>>>>> On 2/22/22 14:55, Tom de Vries wrote: >>>>>>> Hi, >>>>>>> >>>>>>> For the nvptx port, with -mptx-comment we have in pr53465.s: >>>>>>> ... >>>>>>> // #APP >>>>>>> // 9 "gcc/testsuite/gcc.c-torture/execute/pr53465.c" 1 >>>>>>> // Start: Added by -minit-regs=3: >>>>>>> // #NO_APP >>>>>>> mov.u32 %r26, 0; >>>>>>> // #APP >>>>>>> // 9 "gcc/testsuite/gcc.c-torture/execute/pr53465.c" 1 >>>>>>> // End: Added by -minit-regs=3: >>>>>>> // #NO_APP >>>>>>> ... >>>>>>> >>>>>>> The comments where generated using the compiler-generated >>>>>>> equivalent of: >>>>>>> ... >>>>>>> asm ("// Comment"); >>>>>>> ... >>>>>>> but both the printed location and the NO_APP/APP are unnecessary >>>>>>> for a >>>>>>> compiler-generated asm insn. >>>>>>> >>>>>>> Fix this by handling ASM_INPUT_SOURCE_LOCATION == >>>>>>> UNKNOWN_LOCATION in >>>>>>> final_scan_insn_1, such what we simply get: >>>>>>> ... >>>>>>> // Start: Added by -minit-regs=3: >>>>>>> mov.u32 %r26, 0; >>>>>>> // End: Added by -minit-regs=3: >>>>>>> ... >>>>>>> >>>>>>> Tested on nvptx. >>>>>>> >>>>>>> OK for trunk? >>>>>>> >>>>>> >>>>> >>>>> Ping^2. >>>>> >>>>> Tobias just reported an ICE in PR104968, and this patch fixes it. >>>>> >>>>> I'd like to known whether this patch is acceptable for stage 4 or >>>>> not. >>>>> >>>>> If not, I need to fix PR104968 in a different way. Say, disable >>>>> -mcomment by default, or trying harder to propagate source info on >>>>> outlined functions. >>>> >>> >>> Hi, >>> >>> thanks for the review. >>> >>>> Usually targets use UNSPECs to emit compiler-generated "asm" >>>> instructions. >>> >>> Ack. [ I could go down that route eventually, but for now I'm hoping to >>> implement this without having to change the port. ] >>> >>>> I think an unknown location is a reasonable but not >>>> the best way to identify 'compiler-generated', we might lose >>>> the location through optimization. (why does it not use >>>> the INSN_LOCATION?) >>>> >>> >>> I don't know. FWIW, at the time that ASM_INPUT_SOURCE_LOCATION was >>> introduced (2007), there was no INSN_LOCATION yet (introduced in 2012), >>> only INSN_LOCATOR, my guess is that it has something to do with that. >>> >>>> Rather than a location I'd use sth like DECL_ARTIFICIAL to >>>> disable 'user-mangling', do we have something like that for >>>> ASM or an insn in general? >>> >>> Haven't found it. >>> >>>> If not maybe there's an unused >>>> bit on ASMs we can enable this way. >>> >>> Done. I've used the jump flag for that. >>> >>> Updated, untested patch attached. >>> >>> Is this what you meant? >> >> Hmm. I now read that ASM_INPUT is in every PATTERN of an insn > > Maybe I misunderstand, but that sounds incorrect to me. That is, can > you point me to where you read that? > > Maybe you're referring to the fact that an ASM_INPUT may occur inside > an ASM_OPERANDS, as "a convenient way to hold a string" (quoting > rtl.def)? > >> and wonder how this all works out there. That is, by default the >> ASM_INPUT would be artificial (for regular define_insn) but asm("") >> in source would mark them ASM_INPUT_USER_P or so. >> > > If you're suggesting to make it by default artificial, then that > doesn't sound like a bad idea to me. In this iteration I haven't > implemented this (yet), but instead explicitly marked as artificial > some other uses of ASM_INPUT. > >> But then I know nothing here. I did expect us to look at >> ASM_OPERANDS instead of just ASM_INPUT (but the code you >> are changing is about ASM_INPUT). >> > > I extended the rationale in the commit log a bit to include a > description of what the rtl-equivalent of 'asm ("// Comment")' looks > like, and there's no ASM_OPERANDS there. > >> That said, the comments should probably explicitely say this >> is about ASM_INPUT in an ASM_OPERANDS instruction >> template, not some other pattern. >> > > AFAIU, this isn't about an ASM_INPUT in an ASM_OPERANDS instruction > template, so at this point I haven't updated the comment. > > Thanks, > - Tom > > 0015-final-Handle-compiler-generated-asm-insn.patch > > [final] Handle compiler-generated asm insn > > For the nvptx port, with -mptx-comment we have for test-case pr53465.c at > mach: > ... > (insn 66 43 65 3 (asm_input ("// Start: Added by -minit-regs=3:")) -1 > (nil)) > (insn 65 66 67 3 (set (reg/v:SI 26 [ d ]) > (const_int 0 [0])) 6 {*movsi_insn} > (nil)) > (insn 67 65 44 3 (asm_input ("// End: Added by -minit-regs=3:")) -1 > (nil)) > ... > and in pr53465.s: > ... > // #APP > // 9 "gcc/testsuite/gcc.c-torture/execute/pr53465.c" 1 > // Start: Added by -minit-regs=3: > // #NO_APP > mov.u32 %r26, 0; > // #APP > // 9 "gcc/testsuite/gcc.c-torture/execute/pr53465.c" 1 > // End: Added by -minit-regs=3: > // #NO_APP > ... > > [ The comment insns were modelled after: > ... > asm ("// Comment"); > ... > which expands to: > ... > (insn 5 2 6 2 (parallel [ > (asm_input/v ("// Comment") test.c:4) > (clobber (mem:BLK (scratch) [0 A8])) > ]) "test.c":4:3 -1 > (nil)) > ... > Note btw the differences: the comment insn has no clobber, and ASM_INPUT is > not volatile. ] > > Both the printed location and the NO_APP/APP are unnecessary for a > compiler-generated asm insn. > > Fix this by: > - adding new flag ASM_INPUT_ARTIFICIAL_P > - setting it in common code where that is appropriate > - in gen_comment: > - setting ASM_INPUT_ARTIFICIAL_P to 1 > - setting ASM_INPUT_SOURCE_LOCATION to UNKNOWN_LOCATION, > - in final_scan_insn_1: > - handling ASM_INPUT_SOURCE_LOCATION == UNKNOWN_LOCATION and > ASM_INPUT_ARTIFICIAL_P > such what we simply get: > ... > // Start: Added by -minit-regs=3: > mov.u32 %r26, 0; > // End: Added by -minit-regs=3: > ... > > Tested on nvptx. > > gcc/ChangeLog: > > 2022-02-21 Tom de Vries<tdevries@suse.de> > > PR rtl-optimization/104596 > * rtl.h (struct rtx_def): Document use of jump flag in ASM_INPUT. > (ASM_INPUT_ARTIFICIAL_P): New macro. > * cfgexpand.cc (expand_asm_stmt): Use ASM_INPUT_ARTIFICIAL_P. > * emit-rtl.cc (gen_blockage): Same. > * config/nvptx/nvptx.cc (gen_comment): Use gen_rtx_ASM_INPUT instead > of gen_rtx_ASM_INPUT_loc. Set ASM_INPUT_ARTIFICIAL_P. > * final.cc (final_scan_insn_1): Handle > ASM_INPUT_SOURCE_LOCATION == UNKNOWN_LOCATION and > ASM_INPUT_ARTIFICIAL_P. This looks pretty reasonable to me. The only part that wasn't clear was the setting of ASM_INPUT_ARTIFICIAL_P in cfgexpand.cc, but I trust that it was needed and reasonable. If you still want to go forward with this Tom, go ahead. jeff
diff --git a/gcc/config/nvptx/nvptx.cc b/gcc/config/nvptx/nvptx.cc index 858789e6df7..4124c597f24 100644 --- a/gcc/config/nvptx/nvptx.cc +++ b/gcc/config/nvptx/nvptx.cc @@ -5381,8 +5381,7 @@ gen_comment (const char *s) size_t len = strlen (ASM_COMMENT_START) + strlen (sep) + strlen (s) + 1; char *comment = (char *) alloca (len); snprintf (comment, len, "%s%s%s", ASM_COMMENT_START, sep, s); - return gen_rtx_ASM_INPUT_loc (VOIDmode, ggc_strdup (comment), - cfun->function_start_locus); + return gen_rtx_ASM_INPUT (VOIDmode, ggc_strdup (comment)); } /* Initialize all declared regs at function entry. diff --git a/gcc/final.cc b/gcc/final.cc index a9868861bd2..e6443ef7a4f 100644 --- a/gcc/final.cc +++ b/gcc/final.cc @@ -2642,15 +2642,20 @@ final_scan_insn_1 (rtx_insn *insn, FILE *file, int optimize_p ATTRIBUTE_UNUSED, if (string[0]) { expanded_location loc; + bool unknown_loc_p + = ASM_INPUT_SOURCE_LOCATION (body) == UNKNOWN_LOCATION; - app_enable (); - loc = expand_location (ASM_INPUT_SOURCE_LOCATION (body)); - if (*loc.file && loc.line) - fprintf (asm_out_file, "%s %i \"%s\" 1\n", - ASM_COMMENT_START, loc.line, loc.file); + if (!unknown_loc_p) + { + app_enable (); + loc = expand_location (ASM_INPUT_SOURCE_LOCATION (body)); + if (*loc.file && loc.line) + fprintf (asm_out_file, "%s %i \"%s\" 1\n", + ASM_COMMENT_START, loc.line, loc.file); + } fprintf (asm_out_file, "\t%s\n", string); #if HAVE_AS_LINE_ZERO - if (*loc.file && loc.line) + if (!unknown_loc_p && loc.file && *loc.file && loc.line) fprintf (asm_out_file, "%s 0 \"\" 2\n", ASM_COMMENT_START); #endif }