[final] Handle compiler-generated asm insn 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: - adding new flag ASM_INPUT_ARTIFICIAL_P - 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 PR rtl-optimization/104596 * rtl.h (struct rtx_def): Document use of jump flag in ASM_INPUT. (ASM_INPUT_ARTIFICIAL_P): New macro. * 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. --- gcc/config/nvptx/nvptx.cc | 5 +++-- gcc/final.cc | 18 ++++++++++++------ gcc/rtl.h | 3 +++ 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/gcc/config/nvptx/nvptx.cc b/gcc/config/nvptx/nvptx.cc index 87efc23bd96a..93df3f309d18 100644 --- a/gcc/config/nvptx/nvptx.cc +++ b/gcc/config/nvptx/nvptx.cc @@ -5442,8 +5442,9 @@ 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), - DECL_SOURCE_LOCATION (cfun->decl)); + rtx asm_input = gen_rtx_ASM_INPUT (VOIDmode, ggc_strdup (comment)); + ASM_INPUT_ARTIFICIAL_P (asm_input) = 1; + return asm_input; } /* Initialize all declared regs at function entry. diff --git a/gcc/final.cc b/gcc/final.cc index a9868861bd2c..fee512869482 100644 --- a/gcc/final.cc +++ b/gcc/final.cc @@ -2642,15 +2642,21 @@ 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 (!ASM_INPUT_ARTIFICIAL_P (body)) + app_enable (); + if (!unknown_loc_p) + { + 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.line) fprintf (asm_out_file, "%s 0 \"\" 2\n", ASM_COMMENT_START); #endif } diff --git a/gcc/rtl.h b/gcc/rtl.h index 9df2fab622e7..3d7cc2be45c4 100644 --- a/gcc/rtl.h +++ b/gcc/rtl.h @@ -325,6 +325,7 @@ struct GTY((desc("0"), tag("0"), 1 in a VALUE is SP_BASED_VALUE_P in cselib.cc. 1 in a SUBREG generated by LRA for reload insns. 1 in a REG if this is a static chain register. + 1 in an ASM_INPUT if it is compiler-generated. Dumped as "/j" in RTL dumps. */ unsigned int jump : 1; /* In a CODE_LABEL, part of the two-bit alternate entry field. @@ -2592,6 +2593,8 @@ do { \ #define ASM_OPERANDS_LABEL(RTX, N) XCVECEXP (RTX, 5, N, ASM_OPERANDS) #define ASM_OPERANDS_SOURCE_LOCATION(RTX) XCUINT (RTX, 6, ASM_OPERANDS) #define ASM_INPUT_SOURCE_LOCATION(RTX) XCUINT (RTX, 1, ASM_INPUT) +#define ASM_INPUT_ARTIFICIAL_P(RTX) \ + (RTL_FLAG_CHECK1 ("ASM_INPUT_ARTIFICIAL_P", (RTX), ASM_INPUT)->jump) /* 1 if RTX is a mem that is statically allocated in read-only memory. */ #define MEM_READONLY_P(RTX) \