From d9f8faaa5026bb970b3246235eb22bf9b5e9fe3a Mon Sep 17 00:00:00 2001
From: Thomas Schwinge <tschwinge@baylibre.com>
Date: Mon, 4 Mar 2024 16:04:11 +0100
Subject: [PATCH] [WIP] New effective-target 'asm_goto_with_outputs'

After commit e16f90be2dc8af6c371fe79044c3e668fa3dda62
"testsuite: Fix up lra effective target", we get for nvptx target:

    -PASS: gcc.c-torture/compile/asmgoto-2.c   -O0  (test for excess errors)
    +ERROR: gcc.c-torture/compile/asmgoto-2.c   -O0 : no files matched glob pattern "lra1020113.c.[0-9][0-9][0-9]r.reload" for " dg-do 2 compile { target lra } "

Etc.

However, nvptx appears to support 'asm goto' with outputs, including the
new execution test case:

    PASS: gcc.dg/pr107385.c execution test

TODO gcc/testsuite/gcc.dg/pr110079.c
doesn't using 'asm_goto' with outputs, but is PASS for nvptx, and would ERROR for 'target lra'.
---
 gcc/doc/sourcebuild.texi                        | 3 +++
 gcc/testsuite/gcc.c-torture/compile/asmgoto-2.c | 2 +-
 gcc/testsuite/gcc.c-torture/compile/asmgoto-5.c | 2 +-
 gcc/testsuite/gcc.c-torture/compile/asmgoto-6.c | 3 +--
 gcc/testsuite/gcc.c-torture/compile/pr98096.c   | 2 +-
 gcc/testsuite/gcc.dg/pr100590.c                 | 2 +-
 gcc/testsuite/gcc.dg/pr107385.c                 | 2 +-
 gcc/testsuite/gcc.dg/pr108095.c                 | 2 +-
 gcc/testsuite/gcc.dg/pr110079.c                 | 2 +-
 gcc/testsuite/gcc.dg/pr97954.c                  | 2 +-
 gcc/testsuite/gcc.dg/torture/pr100329.c         | 2 +-
 gcc/testsuite/gcc.dg/torture/pr100398.c         | 2 +-
 gcc/testsuite/gcc.dg/torture/pr100519.c         | 2 +-
 gcc/testsuite/gcc.dg/torture/pr110422.c         | 2 +-
 gcc/testsuite/lib/target-supports.exp           | 9 +++++++++
 15 files changed, 25 insertions(+), 14 deletions(-)

diff --git a/gcc/doc/sourcebuild.texi b/gcc/doc/sourcebuild.texi
index b56b9c39733..a176a3c864f 100644
--- a/gcc/doc/sourcebuild.texi
+++ b/gcc/doc/sourcebuild.texi
@@ -2863,6 +2863,9 @@ Target supports weak undefined symbols
 @item R_flag_in_section
 Target supports the 'R' flag in .section directive in assembly inputs.
 
+@item asm_goto_with_outputs
+Target supports 'asm goto' with outputs.
+
 @item automatic_stack_alignment
 Target supports automatic stack alignment.
 
diff --git a/gcc/testsuite/gcc.c-torture/compile/asmgoto-2.c b/gcc/testsuite/gcc.c-torture/compile/asmgoto-2.c
index 43e597bc59f..234c90e5295 100644
--- a/gcc/testsuite/gcc.c-torture/compile/asmgoto-2.c
+++ b/gcc/testsuite/gcc.c-torture/compile/asmgoto-2.c
@@ -1,5 +1,5 @@
 /* This test should be switched off for a new target with less than 4 allocatable registers */
-/* { dg-do compile { target lra } } */
+/* { dg-do compile { target asm_goto_with_outputs } } */
 int
 foo (void)
 {
diff --git a/gcc/testsuite/gcc.c-torture/compile/asmgoto-5.c b/gcc/testsuite/gcc.c-torture/compile/asmgoto-5.c
index e1574a2903a..af1ba5a7001 100644
--- a/gcc/testsuite/gcc.c-torture/compile/asmgoto-5.c
+++ b/gcc/testsuite/gcc.c-torture/compile/asmgoto-5.c
@@ -1,5 +1,5 @@
 /* Test to generate output reload in asm goto on x86_64.  */
-/* { dg-do compile { target lra } } */
+/* { dg-do compile { target asm_goto_with_outputs } } */
 /* { dg-skip-if "no O0" { { i?86-*-* x86_64-*-* } && { ! ia32 } } { "-O0" } { "" } } */
 
 #if defined __x86_64__
diff --git a/gcc/testsuite/gcc.c-torture/compile/asmgoto-6.c b/gcc/testsuite/gcc.c-torture/compile/asmgoto-6.c
index 6799b83c20a..cb3c7d711a6 100644
--- a/gcc/testsuite/gcc.c-torture/compile/asmgoto-6.c
+++ b/gcc/testsuite/gcc.c-torture/compile/asmgoto-6.c
@@ -1,5 +1,4 @@
-
-/* { dg-do compile { target lra } } */
+/* { dg-do compile { target asm_goto_with_outputs } } */
 /* PR middle-end/110420 */
 /* PR middle-end/103979 */
 /* PR middle-end/98619 */
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr98096.c b/gcc/testsuite/gcc.c-torture/compile/pr98096.c
index bba3fa5c619..3a1b6159c2e 100644
--- a/gcc/testsuite/gcc.c-torture/compile/pr98096.c
+++ b/gcc/testsuite/gcc.c-torture/compile/pr98096.c
@@ -1,6 +1,6 @@
 /* Test for correct naming of label operands in asm goto in case of presence of
    input/output operands. */
-/* { dg-do compile { target lra } } */
+/* { dg-do compile { target asm_goto_with_outputs } } */
 int i, j;
 int f(void) {
   asm goto ("# %0 %2" : "+r" (i) ::: jmp);
diff --git a/gcc/testsuite/gcc.dg/pr100590.c b/gcc/testsuite/gcc.dg/pr100590.c
index 8d1e1a0d306..64cb717ed0e 100644
--- a/gcc/testsuite/gcc.dg/pr100590.c
+++ b/gcc/testsuite/gcc.dg/pr100590.c
@@ -1,5 +1,5 @@
 /* PR rtl-optimization/100590 */
-/* { dg-do compile { target lra } } */
+/* { dg-do compile { target asm_goto_with_outputs } } */
 /* { dg-options "-O1 -fno-dce -w" } */
 
 int
diff --git a/gcc/testsuite/gcc.dg/pr107385.c b/gcc/testsuite/gcc.dg/pr107385.c
index 0cc0655d848..690ad3c1b5e 100644
--- a/gcc/testsuite/gcc.dg/pr107385.c
+++ b/gcc/testsuite/gcc.dg/pr107385.c
@@ -1,5 +1,5 @@
 /* PR middle-end/107385 */
-/* { dg-do run { target lra } } */
+/* { dg-do run { target asm_goto_with_outputs } } */
 /* { dg-options "-O2" } */
 
 __attribute__((noipa)) int
diff --git a/gcc/testsuite/gcc.dg/pr108095.c b/gcc/testsuite/gcc.dg/pr108095.c
index 0a487cf614a..115ea73e39b 100644
--- a/gcc/testsuite/gcc.dg/pr108095.c
+++ b/gcc/testsuite/gcc.dg/pr108095.c
@@ -1,5 +1,5 @@
 /* PR tree-optimization/108095 */
-/* { dg-do compile { target lra } } */
+/* { dg-do compile { target asm_goto_with_outputs } } */
 /* { dg-options "-Os -g" } */
 
 int v;
diff --git a/gcc/testsuite/gcc.dg/pr110079.c b/gcc/testsuite/gcc.dg/pr110079.c
index 1682f9c2344..e8ec6666b23 100644
--- a/gcc/testsuite/gcc.dg/pr110079.c
+++ b/gcc/testsuite/gcc.dg/pr110079.c
@@ -1,5 +1,5 @@
 /* PR rtl-optimization/110079 */
-/* { dg-do compile { target lra } } */
+/* { dg-do compile { target asm_goto_with_outputs } } */
 /* { dg-options "-O2" } */
 /* { dg-additional-options "-freorder-blocks-and-partition" { target freorder } } */
 
diff --git a/gcc/testsuite/gcc.dg/pr97954.c b/gcc/testsuite/gcc.dg/pr97954.c
index 0be60f500b6..619bed3b40c 100644
--- a/gcc/testsuite/gcc.dg/pr97954.c
+++ b/gcc/testsuite/gcc.dg/pr97954.c
@@ -1,5 +1,5 @@
 /* PR rtl-optimization/97954 */
-/* { dg-do compile { target lra } } */
+/* { dg-do compile { target asm_goto_with_outputs } } */
 /* { dg-options "-O2" } */
 
 int
diff --git a/gcc/testsuite/gcc.dg/torture/pr100329.c b/gcc/testsuite/gcc.dg/torture/pr100329.c
index 2a4331ba712..5759131a6ca 100644
--- a/gcc/testsuite/gcc.dg/torture/pr100329.c
+++ b/gcc/testsuite/gcc.dg/torture/pr100329.c
@@ -1,4 +1,4 @@
-/* { dg-do compile { target lra } } */
+/* { dg-do compile { target asm_goto_with_outputs } } */
 /* { dg-additional-options "--param tree-reassoc-width=2" } */
 
 unsigned int a0;
diff --git a/gcc/testsuite/gcc.dg/torture/pr100398.c b/gcc/testsuite/gcc.dg/torture/pr100398.c
index 4fc1168d22f..eeeaf98e15b 100644
--- a/gcc/testsuite/gcc.dg/torture/pr100398.c
+++ b/gcc/testsuite/gcc.dg/torture/pr100398.c
@@ -1,4 +1,4 @@
-/* { dg-do compile { target lra } } */
+/* { dg-do compile { target asm_goto_with_outputs } } */
 
 int
 test5_limit (void)
diff --git a/gcc/testsuite/gcc.dg/torture/pr100519.c b/gcc/testsuite/gcc.dg/torture/pr100519.c
index 89dff668a97..b82ce46c529 100644
--- a/gcc/testsuite/gcc.dg/torture/pr100519.c
+++ b/gcc/testsuite/gcc.dg/torture/pr100519.c
@@ -1,4 +1,4 @@
-/* { dg-do compile { target lra } } */
+/* { dg-do compile { target asm_goto_with_outputs } } */
 /* { dg-additional-options "--param tree-reassoc-width=2" } */
 
 unsigned int foo_a1, foo_a2;
diff --git a/gcc/testsuite/gcc.dg/torture/pr110422.c b/gcc/testsuite/gcc.dg/torture/pr110422.c
index 2a653bdfce3..34de7a2980f 100644
--- a/gcc/testsuite/gcc.dg/torture/pr110422.c
+++ b/gcc/testsuite/gcc.dg/torture/pr110422.c
@@ -1,4 +1,4 @@
-/* { dg-do compile { target lra } } */
+/* { dg-do compile { target asm_goto_with_outputs } } */
 
 struct T { int x; };
 int foo(void) {
diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp
index 5a1f0ed5a28..158dc51a71f 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -13211,6 +13211,15 @@ proc check_effective_target_lra { } {
     } {-O2 -fdump-rtl-reload-details}] ;# LRA notes requires a detailed dump.
 }
 
+# Return 1 if 'asm goto' with outputs is supported, 0 otherwise.
+
+proc check_effective_target_asm_goto_with_outputs { } {
+    if { [istarget nvptx-*-*] } {
+	return 1
+    }
+    return [check_effective_target_lra]
+}
+
 # Test whether optimizations are enabled ('__OPTIMIZE__') per the
 # 'current_compiler_flags' (thus don't cache).
 
-- 
2.34.1

