public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] PR 66215: S390: Fix placement of post-label NOPs with -mhotpatch
@ 2015-05-29 11:52 Dominik Vogt
  2015-05-29 12:35 ` Jakub Jelinek
  0 siblings, 1 reply; 5+ messages in thread
From: Dominik Vogt @ 2015-05-29 11:52 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 160 bytes --]

The attached patch fixes the problem reported in PR 66215.
Patches for gcc-4.8, 4.9 and 5.1 will follow.

Ciao

Dominik ^_^  ^_^

-- 

Dominik Vogt
IBM Germany

[-- Attachment #2: ChangeLog --]
[-- Type: text/plain, Size: 2132 bytes --]

gcc/ChangeLog

2015-05-29  Dominik Vogt  <vogt@linux.vnet.ibm.com>

	PR target/66215
	* config/s390/s390.c (s390_reorg): Fix placement of post-label NOPs
	with -mhotpatch=.
gcc/testsuite/ChangeLog

2015-05-29  Dominik Vogt  <vogt@linux.vnet.ibm.com>

	PR target0/66215
	* gcc.target/s390/hotpatch-1.c: Improve to detect multi-line patterns.
	* gcc.target/s390/hotpatch-2.c: Likewise.
	* gcc.target/s390/hotpatch-3.c: Likewise.
	* gcc.target/s390/hotpatch-4.c: Likewise.
	* gcc.target/s390/hotpatch-5.c: Likewise.
	* gcc.target/s390/hotpatch-6.c: Likewise.
	* gcc.target/s390/hotpatch-7.c: Likewise.
	* gcc.target/s390/hotpatch-8.c: Likewise.
	* gcc.target/s390/hotpatch-9.c: Likewise.
	* gcc.target/s390/hotpatch-14.c: Likewise.
	* gcc.target/s390/hotpatch-15.c: Likewise.
	* gcc.target/s390/hotpatch-16.c: Likewise.
	* gcc.target/s390/hotpatch-19.c:Likewise.
	* gcc.target/s390/hotpatch-25.c:Likewise.
	* gcc.target/s390/hotpatch-26.c: New file.
	* gcc.target/s390/hotpatch-27.c: New file.
	* gcc.target/s390/s390.exp: Enable torture test.
	* gcc.target/s390/hotpatch-1.c: Likewise.
	* gcc.target/s390/hotpatch-2.c: Likewise.
	* gcc.target/s390/hotpatch-3.c: Likewise.
	* gcc.target/s390/hotpatch-4.c: Likewise.
	* gcc.target/s390/hotpatch-5.c: Likewise.
	* gcc.target/s390/hotpatch-6.c: Likewise.
	* gcc.target/s390/hotpatch-7.c: Likewise.
	* gcc.target/s390/hotpatch-8.c: Likewise.
	* gcc.target/s390/hotpatch-9.c: Likewise.
	* gcc.target/s390/hotpatch-10.c: Likewise.
	* gcc.target/s390/hotpatch-11.c: Likewise.
	* gcc.target/s390/hotpatch-12.c: Likewise.
	* gcc.target/s390/hotpatch-13.c: Likewise.
	* gcc.target/s390/hotpatch-14.c: Likewise.
	* gcc.target/s390/hotpatch-15.c: Likewise.
	* gcc.target/s390/hotpatch-16.c: Likewise.
	* gcc.target/s390/hotpatch-17.c: Likewise.
	* gcc.target/s390/hotpatch-18.c: Likewise.
	* gcc.target/s390/hotpatch-19.c: Likewise.
	* gcc.target/s390/hotpatch-20.c: Likewise.
	* gcc.target/s390/hotpatch-21.c: Likewise.
	* gcc.target/s390/hotpatch-22.c: Likewise.
	* gcc.target/s390/hotpatch-23.c: Likewise.
	* gcc.target/s390/hotpatch-24.c: Likewise.
	* gcc.target/s390/hotpatch-25.c: Likewise.

[-- Attachment #3: 0001-PR-66215-S390-Fix-placement-of-post-label-NOPs-with-.patch --]
[-- Type: text/x-diff, Size: 27378 bytes --]

From c4fc2eb77035ff4f8cd78f48fa8f7b2731c19ade Mon Sep 17 00:00:00 2001
From: Dominik Vogt <vogt@linux.vnet.ibm.com>
Date: Fri, 22 May 2015 09:03:26 +0100
Subject: [PATCH] PR 66215: S390: Fix placement of post-label NOPs with
 -mhotpatch=.

---
 gcc/config/s390/s390.c                      | 27 ++++++++++++++++-----------
 gcc/testsuite/gcc.target/s390/hotpatch-1.c  |  2 +-
 gcc/testsuite/gcc.target/s390/hotpatch-10.c |  2 +-
 gcc/testsuite/gcc.target/s390/hotpatch-11.c |  2 +-
 gcc/testsuite/gcc.target/s390/hotpatch-12.c |  2 +-
 gcc/testsuite/gcc.target/s390/hotpatch-13.c |  3 +--
 gcc/testsuite/gcc.target/s390/hotpatch-14.c |  4 ++--
 gcc/testsuite/gcc.target/s390/hotpatch-15.c |  4 ++--
 gcc/testsuite/gcc.target/s390/hotpatch-16.c |  4 ++--
 gcc/testsuite/gcc.target/s390/hotpatch-17.c |  2 +-
 gcc/testsuite/gcc.target/s390/hotpatch-18.c |  2 +-
 gcc/testsuite/gcc.target/s390/hotpatch-19.c |  4 ++--
 gcc/testsuite/gcc.target/s390/hotpatch-2.c  |  4 ++--
 gcc/testsuite/gcc.target/s390/hotpatch-20.c |  2 +-
 gcc/testsuite/gcc.target/s390/hotpatch-21.c |  2 +-
 gcc/testsuite/gcc.target/s390/hotpatch-22.c |  2 +-
 gcc/testsuite/gcc.target/s390/hotpatch-23.c |  2 +-
 gcc/testsuite/gcc.target/s390/hotpatch-24.c |  2 +-
 gcc/testsuite/gcc.target/s390/hotpatch-25.c |  9 ++++-----
 gcc/testsuite/gcc.target/s390/hotpatch-26.c | 17 +++++++++++++++++
 gcc/testsuite/gcc.target/s390/hotpatch-27.c | 17 +++++++++++++++++
 gcc/testsuite/gcc.target/s390/hotpatch-28.c | 18 ++++++++++++++++++
 gcc/testsuite/gcc.target/s390/hotpatch-3.c  |  4 ++--
 gcc/testsuite/gcc.target/s390/hotpatch-4.c  |  4 ++--
 gcc/testsuite/gcc.target/s390/hotpatch-5.c  |  4 ++--
 gcc/testsuite/gcc.target/s390/hotpatch-6.c  |  4 ++--
 gcc/testsuite/gcc.target/s390/hotpatch-7.c  |  4 ++--
 gcc/testsuite/gcc.target/s390/hotpatch-8.c  |  4 ++--
 gcc/testsuite/gcc.target/s390/hotpatch-9.c  |  4 ++--
 gcc/testsuite/gcc.target/s390/s390.exp      | 13 +++++++++++--
 30 files changed, 119 insertions(+), 55 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/s390/hotpatch-26.c
 create mode 100644 gcc/testsuite/gcc.target/s390/hotpatch-27.c
 create mode 100644 gcc/testsuite/gcc.target/s390/hotpatch-28.c

diff --git a/gcc/config/s390/s390.c b/gcc/config/s390/s390.c
index 6648597..bab9460 100644
--- a/gcc/config/s390/s390.c
+++ b/gcc/config/s390/s390.c
@@ -12843,31 +12843,36 @@ s390_reorg (void)
 
       /* Insert NOPs for hotpatching. */
       for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
-	{
-	  if (NOTE_P (insn) && NOTE_KIND (insn) == NOTE_INSN_FUNCTION_BEG)
-	    break;
-	}
-      gcc_assert (insn);
-      /* Output a series of NOPs after the NOTE_INSN_FUNCTION_BEG.  */
-      while (hw_after > 0)
+	/* Emit NOPs
+	 *  1. inside the area covered by debug information to allow setting
+	 *     breakpoints at the NOPs,
+	 *  2. before any insn which results in an asm instruction,
+	 *  3. before in-function labels to avoid jumping to the NOPs, for
+	 *     example as part of a loop,
+	 *  4. before any barrier in case the function is completely empty
+	 *     (gcc_unreachable ()) and has neither internal labels nor active
+	 *     insns.  */
+	if (active_insn_p (insn) || BARRIER_P (insn) || LABEL_P (insn))
+	  break;
+      /* Output a series of NOPs before the first active insn.  */
+      while (insn && hw_after > 0)
 	{
 	  if (hw_after >= 3 && TARGET_CPU_ZARCH)
 	    {
-	      insn = emit_insn_after (gen_nop_6_byte (), insn);
+	      emit_insn_before (gen_nop_6_byte (), insn);
 	      hw_after -= 3;
 	    }
 	  else if (hw_after >= 2)
 	    {
-	      insn = emit_insn_after (gen_nop_4_byte (), insn);
+	      emit_insn_before (gen_nop_4_byte (), insn);
 	      hw_after -= 2;
 	    }
 	  else
 	    {
-	      insn = emit_insn_after (gen_nop_2_byte (), insn);
+	      emit_insn_before (gen_nop_2_byte (), insn);
 	      hw_after -= 1;
 	    }
 	}
-      gcc_assert (hw_after == 0);
     }
 }
 
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-1.c b/gcc/testsuite/gcc.target/s390/hotpatch-1.c
index b14fa90..55088b8 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-1.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-1.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch" } */
+/* { dg-options "-mzarch" } */
 
 #include <stdio.h>
 
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-10.c b/gcc/testsuite/gcc.target/s390/hotpatch-10.c
index a990c4c..d2cb9a2 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-10.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-10.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=0,0" } */
+/* { dg-options "-mzarch -mhotpatch=0,0" } */
 
 #include <stdio.h>
 
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-11.c b/gcc/testsuite/gcc.target/s390/hotpatch-11.c
index 6f8a52b..cabb9d26 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-11.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-11.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=1,0" } */
+/* { dg-options "-mzarch -mhotpatch=1,0" } */
 
 #include <stdio.h>
 
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-12.c b/gcc/testsuite/gcc.target/s390/hotpatch-12.c
index b73ca90..fc9adc3 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-12.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-12.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=999,0" } */
+/* { dg-options "-mzarch -mhotpatch=999,0" } */
 
 #include <stdio.h>
 
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-13.c b/gcc/testsuite/gcc.target/s390/hotpatch-13.c
index 150667a..b25fbd3 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-13.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-13.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch" } */
+/* { dg-options "-mzarch" } */
 
 #include <stdio.h>
 
@@ -18,4 +18,3 @@ void hp1(void)
 /* { dg-final { scan-assembler-not "nop\t0" } } */
 /* { dg-final { scan-assembler-not "brcl\t0, 0" } } */
 /* { dg-final { scan-assembler "alignment for hotpatch" } } */
-/* { dg-final { scan-assembler-times "\.align\t8" 2 } } */
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-14.c b/gcc/testsuite/gcc.target/s390/hotpatch-14.c
index c5f118c..c387d6b 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-14.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-14.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch" } */
+/* { dg-options "-mzarch" } */
 
 #include <stdio.h>
 
@@ -13,7 +13,7 @@ void hp1(void)
 
 /* Check number of occurences of certain instructions.  */
 /* { dg-final { scan-assembler-not "pre-label NOPs" } } */
-/* { dg-final { scan-assembler "post-label.*(2 halfwords)" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(2 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*nop\t0" } } */
 /* { dg-final { scan-assembler-not "nopr\t%r7" } } */
 /* { dg-final { scan-assembler-times "nop\t0" 1 } } */
 /* { dg-final { scan-assembler-not "brcl\t0, 0" } } */
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-15.c b/gcc/testsuite/gcc.target/s390/hotpatch-15.c
index ef0fb74..410106b 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-15.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-15.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch" } */
+/* { dg-options "-mzarch" } */
 
 #include <stdio.h>
 
@@ -13,7 +13,7 @@ void hp1(void)
 
 /* Check number of occurences of certain instructions.  */
 /* { dg-final { scan-assembler "pre-label.*(1 halfwords)" } } */
-/* { dg-final { scan-assembler "post-label.*(2 halfwords)" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(2 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*nop\t0" } } */
 /* { dg-final { scan-assembler-times "nopr\t%r7" 1 } } */
 /* { dg-final { scan-assembler-times "nop\t0" 1 } } */
 /* { dg-final { scan-assembler-not "brcl\t0, 0" } } */
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-16.c b/gcc/testsuite/gcc.target/s390/hotpatch-16.c
index a34bf95..fa06fff 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-16.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-16.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=0,0" } */
+/* { dg-options "-mzarch -mhotpatch=0,0" } */
 
 #include <stdio.h>
 
@@ -13,7 +13,7 @@ void hp1(void)
 
 /* Check number of occurences of certain instructions.  */
 /* { dg-final { scan-assembler "pre-label.*(1 halfwords)" } } */
-/* { dg-final { scan-assembler "post-label.*(2 halfwords)" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(2 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*nop\t0" } } */
 /* { dg-final { scan-assembler-times "nopr\t%r7" 1 } } */
 /* { dg-final { scan-assembler-times "nop\t0" 1 } } */
 /* { dg-final { scan-assembler-not "brcl\t0, 0" } } */
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-17.c b/gcc/testsuite/gcc.target/s390/hotpatch-17.c
index 66ac725..3ef7d69 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-17.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-17.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=1,2" } */
+/* { dg-options "-mzarch -mhotpatch=1,2" } */
 
 #include <stdio.h>
 
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-18.c b/gcc/testsuite/gcc.target/s390/hotpatch-18.c
index 8b076a4..c93af7f 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-18.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-18.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=1,2 -mhotpatch=0,0" } */
+/* { dg-options "-mzarch -mhotpatch=1,2 -mhotpatch=0,0" } */
 
 #include <stdio.h>
 
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-19.c b/gcc/testsuite/gcc.target/s390/hotpatch-19.c
index 6993c7e..c69b35e 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-19.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-19.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=1,2" } */
+/* { dg-options "-mzarch -mhotpatch=1,2" } */
 
 #include <stdio.h>
 
@@ -19,7 +19,7 @@ void hp1(void)
 
 /* Check number of occurences of certain instructions.  */
 /* { dg-final { scan-assembler "pre-label.*(1 halfwords)" } } */
-/* { dg-final { scan-assembler "post-label.*(2 halfwords)" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(2 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*nop\t0" } } */
 /* { dg-final { scan-assembler-times "nopr\t%r7" 1 } } */
 /* { dg-final { scan-assembler-times "nop\t0" 1 } } */
 /* { dg-final { scan-assembler-not "brcl\t0, 0" } } */
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-2.c b/gcc/testsuite/gcc.target/s390/hotpatch-2.c
index 67189f8..2a2665e 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-2.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-2.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=0,1" } */
+/* { dg-options "-mzarch -mhotpatch=0,1" } */
 
 #include <stdio.h>
 
@@ -12,7 +12,7 @@ void hp1(void)
 
 /* Check number of occurences of certain instructions.  */
 /* { dg-final { scan-assembler-not "pre-label NOPs" } } */
-/* { dg-final { scan-assembler "post-label.*(1 halfwords)" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(1 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*nopr\t" } } */
 /* { dg-final { scan-assembler-times "nopr\t%r7" 1 } } */
 /* { dg-final { scan-assembler-not "nop\t0" } } */
 /* { dg-final { scan-assembler-not "brcl\t0, 0" } } */
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-20.c b/gcc/testsuite/gcc.target/s390/hotpatch-20.c
index 09ef5ca..0a32a68 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-20.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-20.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch" } */
+/* { dg-options "-mzarch" } */
 
 #include <stdio.h>
 
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-21.c b/gcc/testsuite/gcc.target/s390/hotpatch-21.c
index e909990..f6e9099 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-21.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-21.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=0,1" } */
+/* { dg-options "-mzarch -mhotpatch=0,1" } */
 
 #include <stdio.h>
 
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-22.c b/gcc/testsuite/gcc.target/s390/hotpatch-22.c
index d89d779..21f7d7e 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-22.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-22.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=0,1 -falign-functions=1024" } */
+/* { dg-options "-mzarch -mhotpatch=0,1 -falign-functions=1024" } */
 
 #include <stdio.h>
 
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-23.c b/gcc/testsuite/gcc.target/s390/hotpatch-23.c
index 1e05d12..6e149cc 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-23.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-23.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=0,1 -falign-functions=4096" } */
+/* { dg-options "-mzarch -mhotpatch=0,1 -falign-functions=4096" } */
 
 #include <stdio.h>
 
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-24.c b/gcc/testsuite/gcc.target/s390/hotpatch-24.c
index fc64274..1e47591 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-24.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-24.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=0,1 -falign-functions=2048" } */
+/* { dg-options "-mzarch -mhotpatch=0,1 -falign-functions=2048" } */
 
 #include <stdio.h>
 
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-25.c b/gcc/testsuite/gcc.target/s390/hotpatch-25.c
index e9257e3..e6cdbb6 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-25.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-25.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch" } */
+/* { dg-options "-mzarch" } */
 
 typedef long (*fn_t)(void);
 
@@ -25,9 +25,8 @@ fn_t outer(void)
 /* { dg-final { scan-assembler "pre-label.*(1 halfwords)" } } */
 /* { dg-final { scan-assembler "pre-label.*(4 halfwords)" } } */
 /* { dg-final { scan-assembler "pre-label.*(16 halfwords)" } } */
-/* { dg-final { scan-assembler "post-label.*(2 halfwords)" } } */
-/* { dg-final { scan-assembler "post-label.*(8 halfwords)" } } */
-/* { dg-final { scan-assembler "post-label.*(32 halfwords)" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(2 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*nopr\t" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(8 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*brcl\t0, 0" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(32 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*brcl\t0, 0" } } */
 /* { dg-final { scan-assembler-times "alignment for hotpatch" 3 } } */
-/* { dg-final { scan-assembler-times "\.align\t8" 6 } } */
 /* { dg-final { scan-assembler "nopr.*\n.*nopr.*\n.*nopr.*\n.*nopr.*\n.*nopr.*\n.*nopr.*\n.*nopr.*\n.*nopr.*\n.*nopr.*\n.*nopr.*\n.*nopr.*\n.*nopr.*\n.*nopr.*\n.*nopr.*\n.*nopr.*\n.*nopr" } } */
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-26.c b/gcc/testsuite/gcc.target/s390/hotpatch-26.c
new file mode 100644
index 0000000..eb95c26
--- /dev/null
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-26.c
@@ -0,0 +1,17 @@
+/* Functional tests for the function hotpatching feature.  */
+
+/* { dg-do compile } */
+/* { dg-options "-O3 -mzarch -mhotpatch=1,2" } */
+
+__attribute__ ((noreturn)) void hp1(void)
+{
+  __builtin_unreachable ();
+}
+
+/* Check number of occurences of certain instructions.  */
+/* { dg-final { scan-assembler "pre-label NOPs" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(2 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*nop\t0" } } */
+/* { dg-final { scan-assembler-times "nopr\t%r7" 1 } } */
+/* { dg-final { scan-assembler-times "nop\t0" 1 } } */
+/* { dg-final { scan-assembler-not "brcl\t0, 0" } } */
+/* { dg-final { scan-assembler "alignment for hotpatch" } } */
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-27.c b/gcc/testsuite/gcc.target/s390/hotpatch-27.c
new file mode 100644
index 0000000..cdbd4ca
--- /dev/null
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-27.c
@@ -0,0 +1,17 @@
+/* Functional tests for the function hotpatching feature.  */
+
+/* { dg-do compile } */
+/* { dg-options "-O3 -mzarch -mhotpatch=1,2" } */
+
+__attribute__ ((noreturn)) void hp3(void)
+{
+  __builtin_unreachable ();
+}
+
+/* Check number of occurences of certain instructions.  */
+/* { dg-final { scan-assembler "pre-label NOPs" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(2 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*nop\t0" } } */
+/* { dg-final { scan-assembler-times "nopr\t%r7" 1 } } */
+/* { dg-final { scan-assembler-times "nop\t0" 1 } } */
+/* { dg-final { scan-assembler-not "brcl\t0, 0" } } */
+/* { dg-final { scan-assembler "alignment for hotpatch" } } */
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-28.c b/gcc/testsuite/gcc.target/s390/hotpatch-28.c
new file mode 100644
index 0000000..9922daa
--- /dev/null
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-28.c
@@ -0,0 +1,18 @@
+/* Functional tests for the function hotpatching feature.  */
+
+/* { dg-do compile } */
+/* { dg-options "-O3 -mzarch -mhotpatch=1,2" } */
+
+void hp1 (volatile unsigned int *i)
+{
+  for (;;)
+    (*i)++;
+}
+
+/* Check number of occurences of certain instructions.  */
+/* { dg-final { scan-assembler "pre-label NOPs" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(2 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*nop\t0" } } */
+/* { dg-final { scan-assembler-times "nopr\t%r7" 1 } } */
+/* { dg-final { scan-assembler-times "nop\t0" 1 } } */
+/* { dg-final { scan-assembler-not "brcl\t0, 0" } } */
+/* { dg-final { scan-assembler "alignment for hotpatch" } } */
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-3.c b/gcc/testsuite/gcc.target/s390/hotpatch-3.c
index ec4a978..6718591 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-3.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-3.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=0,2" } */
+/* { dg-options "-mzarch -mhotpatch=0,2" } */
 
 #include <stdio.h>
 
@@ -12,7 +12,7 @@ void hp1(void)
 
 /* Check number of occurences of certain instructions.  */
 /* { dg-final { scan-assembler-not "pre-label NOPs" } } */
-/* { dg-final { scan-assembler "post-label.*(2 halfwords)" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(2 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*nop\t0" } } */
 /* { dg-final { scan-assembler-not "nopr\t%r7" } } */
 /* { dg-final { scan-assembler-times "nop\t0" 1 } } */
 /* { dg-final { scan-assembler-not "brcl\t0, 0" } } */
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-4.c b/gcc/testsuite/gcc.target/s390/hotpatch-4.c
index d55e71d..b770d4b 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-4.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-4.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=0,3" } */
+/* { dg-options "-mzarch -mhotpatch=0,3" } */
 
 #include <stdio.h>
 
@@ -12,7 +12,7 @@ void hp1(void)
 
 /* Check number of occurences of certain instructions.  */
 /* { dg-final { scan-assembler-not "pre-label NOPs" } } */
-/* { dg-final { scan-assembler "post-label.*(3 halfwords)" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(3 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*brcl\t0, 0" } } */
 /* { dg-final { scan-assembler-not "nopr\t%r7" } } */
 /* { dg-final { scan-assembler-not "nop\t0" } } */
 /* { dg-final { scan-assembler-times "brcl\t0, 0" 1 } } */
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-5.c b/gcc/testsuite/gcc.target/s390/hotpatch-5.c
index f77d83a..f1dcd89 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-5.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-5.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=0,4" } */
+/* { dg-options "-mzarch -mhotpatch=0,4" } */
 
 #include <stdio.h>
 
@@ -12,7 +12,7 @@ void hp1(void)
 
 /* Check number of occurences of certain instructions.  */
 /* { dg-final { scan-assembler-not "pre-label NOPs" } } */
-/* { dg-final { scan-assembler "post-label.*(4 halfwords)" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(4 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*brcl\t0, 0" } } */
 /* { dg-final { scan-assembler-times "nopr\t%r7" 1 } } */
 /* { dg-final { scan-assembler-not "nop\t0" } } */
 /* { dg-final { scan-assembler-times "brcl\t0, 0" 1 } } */
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-6.c b/gcc/testsuite/gcc.target/s390/hotpatch-6.c
index 330cf5d..6203a72b 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-6.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-6.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=0,5" } */
+/* { dg-options "-mzarch -mhotpatch=0,5" } */
 
 #include <stdio.h>
 
@@ -12,7 +12,7 @@ void hp1(void)
 
 /* Check number of occurences of certain instructions.  */
 /* { dg-final { scan-assembler-not "pre-label NOPs" } } */
-/* { dg-final { scan-assembler "post-label.*(5 halfwords)" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(5 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*brcl\t0, 0" } } */
 /* { dg-final { scan-assembler-not "nopr\t%r7" } } */
 /* { dg-final { scan-assembler-times "nop\t0" 1 } } */
 /* { dg-final { scan-assembler-times "brcl\t0, 0" 1 } } */
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-7.c b/gcc/testsuite/gcc.target/s390/hotpatch-7.c
index 2f24e3cc..e201ae9 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-7.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-7.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=0,6" } */
+/* { dg-options "-mzarch -mhotpatch=0,6" } */
 
 #include <stdio.h>
 
@@ -12,7 +12,7 @@ void hp1(void)
 
 /* Check number of occurences of certain instructions.  */
 /* { dg-final { scan-assembler-not "pre-label NOPs" } } */
-/* { dg-final { scan-assembler "post-label.*(6 halfwords)" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(6 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*brcl\t0, 0" } } */
 /* { dg-final { scan-assembler-not "nopr\t%r7" } } */
 /* { dg-final { scan-assembler-not "nop\t0" } } */
 /* { dg-final { scan-assembler-times "brcl\t0, 0" 2 } } */
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-8.c b/gcc/testsuite/gcc.target/s390/hotpatch-8.c
index 7b266bd..1ea3160 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-8.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-8.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile { target { ! lp64 } } } */
-/* { dg-options "-O3 -mesa -march=g5 -mhotpatch=0,3" } */
+/* { dg-options "-mesa -march=g5 -mhotpatch=0,3" } */
 
 #include <stdio.h>
 
@@ -12,7 +12,7 @@ void hp1(void)
 
 /* Check number of occurences of certain instructions.  */
 /* { dg-final { scan-assembler-not "pre-label NOPs" } } */
-/* { dg-final { scan-assembler "post-label.*(3 halfwords)" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(3 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*nop\t0" } } */
 /* { dg-final { scan-assembler-times "nopr\t%r7" 1 } } */
 /* { dg-final { scan-assembler-times "nop\t0" 1 } } */
 /* { dg-final { scan-assembler-not "brcl\t0, 0" } } */
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-9.c b/gcc/testsuite/gcc.target/s390/hotpatch-9.c
index c0ad319..e30f276 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-9.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-9.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile { target { ! lp64 } } } */
-/* { dg-options "-O3 -mesa -march=g5 -mhotpatch=0,4" } */
+/* { dg-options "-mesa -march=g5 -mhotpatch=0,4" } */
 
 #include <stdio.h>
 
@@ -12,7 +12,7 @@ void hp1(void)
 
 /* Check number of occurences of certain instructions.  */
 /* { dg-final { scan-assembler-not "pre-label NOPs" } } */
-/* { dg-final { scan-assembler "post-label.*(4 halfwords)" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(4 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*nop\t0" } } */
 /* { dg-final { scan-assembler-not "nopr\t%r7" } } */
 /* { dg-final { scan-assembler-times "nop\t0" 2 } } */
 /* { dg-final { scan-assembler-not "brcl\t0, 0" } } */
diff --git a/gcc/testsuite/gcc.target/s390/s390.exp b/gcc/testsuite/gcc.target/s390/s390.exp
index eb1d73b..0b8f80ed 100644
--- a/gcc/testsuite/gcc.target/s390/s390.exp
+++ b/gcc/testsuite/gcc.target/s390/s390.exp
@@ -61,12 +61,21 @@ if ![info exists DEFAULT_CFLAGS] then {
 # Initialize `dg'.
 dg-init
 
+set hotpatch_tests $srcdir/$subdir/hotpatch-\[0-9\]*.c
+
 # Main loop.
-dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.\[cS\]]] \
-	"" $DEFAULT_CFLAGS
+dg-runtest [lsort [prune [glob -nocomplain $srcdir/$subdir/*.\[cS\]] \
+			 $hotpatch_tests]] "" $DEFAULT_CFLAGS
 
 dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*vector*/*.\[cS\]]] \
 	"" $DEFAULT_CFLAGS
 
+# Additional hotpatch torture tests.
+torture-init
+set HOTPATCH_TEST_OPTS [list -Os -O0 -O1 -O2 -O3]
+set-torture-options $HOTPATCH_TEST_OPTS
+gcc-dg-runtest [lsort [glob -nocomplain $hotpatch_tests]] "" $DEFAULT_CFLAGS
+torture-finish
+
 # All done.
 dg-finish
-- 
2.3.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] PR 66215: S390: Fix placement of post-label NOPs with -mhotpatch
  2015-05-29 11:52 [PATCH] PR 66215: S390: Fix placement of post-label NOPs with -mhotpatch Dominik Vogt
@ 2015-05-29 12:35 ` Jakub Jelinek
  2015-05-29 15:18   ` Dominik Vogt
  0 siblings, 1 reply; 5+ messages in thread
From: Jakub Jelinek @ 2015-05-29 12:35 UTC (permalink / raw)
  To: gcc-patches

On Fri, May 29, 2015 at 11:57:00AM +0100, Dominik Vogt wrote:
> 2015-05-29  Dominik Vogt  <vogt@linux.vnet.ibm.com>
> 
> 	PR target0/66215

Please remove the 0 above.

> 	* gcc.target/s390/hotpatch-1.c: Improve to detect multi-line patterns.
> 	* gcc.target/s390/hotpatch-2.c: Likewise.
> 	* gcc.target/s390/hotpatch-3.c: Likewise.
> 	* gcc.target/s390/hotpatch-4.c: Likewise.
> 	* gcc.target/s390/hotpatch-5.c: Likewise.
> 	* gcc.target/s390/hotpatch-6.c: Likewise.
> 	* gcc.target/s390/hotpatch-7.c: Likewise.
> 	* gcc.target/s390/hotpatch-8.c: Likewise.
> 	* gcc.target/s390/hotpatch-9.c: Likewise.
> 	* gcc.target/s390/hotpatch-14.c: Likewise.
> 	* gcc.target/s390/hotpatch-15.c: Likewise.
> 	* gcc.target/s390/hotpatch-16.c: Likewise.
> 	* gcc.target/s390/hotpatch-19.c:Likewise.
> 	* gcc.target/s390/hotpatch-25.c:Likewise.

Missing spaces after : .  Furthermore, it is very unusual
to list the same file more than once in the ChangeLog of the
same patch.  And the descriptions really don't match the changes
in the tests (e.g. hotpatch-1.c only has the -O* removal,
and -13 has also a dg-final line removal, ditto -25).  From what
I can see, some tests are new, those are ok in the ChangeLog as
is (except that hotpatch-28.c is missing),
in other tests you've removed optimization options from dg-options,
and in some tests tweaked scan-assembler regexps, and in others
removed some dg-final directives.
So IMHO you want:

	* gcc.target/s390/hotpatch-1.c: Remove optimization options from
	dg-options.
	* gcc.target/s390/hotpatch-10.c: Likewise.
	* gcc.target/s390/hotpatch-11.c: Likewise.
	* gcc.target/s390/hotpatch-12.c: Likewise.
	* gcc.target/s390/hotpatch-17.c: Likewise.
	* gcc.target/s390/hotpatch-18.c: Likewise.
	* gcc.target/s390/hotpatch-20.c: Likewise.
	* gcc.target/s390/hotpatch-21.c: Likewise.
	* gcc.target/s390/hotpatch-22.c: Likewise.
	* gcc.target/s390/hotpatch-23.c: Likewise.
	* gcc.target/s390/hotpatch-24.c: Likewise.
	* gcc.target/s390/hotpatch-2.c: Likewise.  Adjust scan-assembler
	to check for the exact nops too.
	* gcc.target/s390/hotpatch-3.c: Likewise.
	* gcc.target/s390/hotpatch-4.c: Likewise.
	* gcc.target/s390/hotpatch-5.c: Likewise.
	* gcc.target/s390/hotpatch-6.c: Likewise.
	* gcc.target/s390/hotpatch-7.c: Likewise.
	* gcc.target/s390/hotpatch-8.c: Likewise.
	* gcc.target/s390/hotpatch-9.c: Likewise.
	* gcc.target/s390/hotpatch-14.c: Likewise.
	* gcc.target/s390/hotpatch-15.c: Likewise.
	* gcc.target/s390/hotpatch-16.c: Likewise.
	* gcc.target/s390/hotpatch-19.c: Likewise.
	* gcc.target/s390/hotpatch-25.c: Likewise.  Remove
	scan-assembler-times counting number of .align directives.
	* gcc.target/s390/hotpatch-13.c: Remove optimization options from
	dg-options.  Remove scan-assembler-times counting number of .align
	directives.
	* gcc.target/s390/hotpatch-26.c: New file.
	* gcc.target/s390/hotpatch-27.c: New file.
	* gcc.target/s390/hotpatch-28.c: New file.
	* gcc.target/s390/s390.exp: Run hotpatch-*.c tests as torture tests
	using -Os -O0 -O1 -O2 -O3 options.

> +	/* Emit NOPs
> +	 *  1. inside the area covered by debug information to allow setting
> +	 *     breakpoints at the NOPs,
> +	 *  2. before any insn which results in an asm instruction,
> +	 *  3. before in-function labels to avoid jumping to the NOPs, for
> +	 *     example as part of a loop,
> +	 *  4. before any barrier in case the function is completely empty
> +	 *     (gcc_unreachable ()) and has neither internal labels nor active
> +	 *     insns.  */

I believe the the above comment isn't formatted like comments in GCC usually
are, can you please replace the *s at the beginning of lines (after
whitespace) with spaces?  Also, please use __builtin_unreachable ()
instead of gcc_unreachable ().  No need to retest the patch for ChangeLog
and comment only changes.

And I'll defer the final ack to s390 maintainers.

	Jakub

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] PR 66215: S390: Fix placement of post-label NOPs with -mhotpatch
  2015-05-29 12:35 ` Jakub Jelinek
@ 2015-05-29 15:18   ` Dominik Vogt
  2015-05-29 15:28     ` Andreas Krebbel
  2015-06-01  8:33     ` Dominik Vogt
  0 siblings, 2 replies; 5+ messages in thread
From: Dominik Vogt @ 2015-05-29 15:18 UTC (permalink / raw)
  To: gcc-patches; +Cc: Andreas Krebbel

[-- Attachment #1: Type: text/plain, Size: 89 bytes --]

No bother, new versions attached.

Ciao

Dominik ^_^  ^_^

-- 

Dominik Vogt
IBM Germany

[-- Attachment #2: ChangeLog --]
[-- Type: text/plain, Size: 1902 bytes --]

gcc/ChangeLog:
--------------
2015-05-29  Dominik Vogt  <vogt@linux.vnet.ibm.com>

	PR target/66215
	* config/s390/s390.c (s390_reorg): Fix placement of post-label NOPs
	with -mhotpatch=.

gcc/testsuite/ChangeLog:
------------------------
2015-05-29  Dominik Vogt  <vogt@linux.vnet.ibm.com>

	PR target/66215
	* gcc.target/s390/hotpatch-1.c: Remove optimization options from
	dg-options.
	* gcc.target/s390/hotpatch-10.c: Likewise.
	* gcc.target/s390/hotpatch-11.c: Likewise.
	* gcc.target/s390/hotpatch-12.c: Likewise.
	* gcc.target/s390/hotpatch-17.c: Likewise.
	* gcc.target/s390/hotpatch-18.c: Likewise.
	* gcc.target/s390/hotpatch-20.c: Likewise.
	* gcc.target/s390/hotpatch-21.c: Likewise.
	* gcc.target/s390/hotpatch-22.c: Likewise.
	* gcc.target/s390/hotpatch-23.c: Likewise.
	* gcc.target/s390/hotpatch-24.c: Likewise.
	* gcc.target/s390/hotpatch-2.c: Likewise.  Adjust scan-assembler
	to check for the exact nops too.
	* gcc.target/s390/hotpatch-3.c: Likewise.
	* gcc.target/s390/hotpatch-4.c: Likewise.
	* gcc.target/s390/hotpatch-5.c: Likewise.
	* gcc.target/s390/hotpatch-6.c: Likewise.
	* gcc.target/s390/hotpatch-7.c: Likewise.
	* gcc.target/s390/hotpatch-8.c: Likewise.
	* gcc.target/s390/hotpatch-9.c: Likewise.
	* gcc.target/s390/hotpatch-14.c: Likewise.
	* gcc.target/s390/hotpatch-15.c: Likewise.
	* gcc.target/s390/hotpatch-16.c: Likewise.
	* gcc.target/s390/hotpatch-19.c: Likewise.
	* gcc.target/s390/hotpatch-25.c: Likewise.  Remove
	scan-assembler-times counting number of .align directives.
	* gcc.target/s390/hotpatch-13.c: Remove optimization options from
	dg-options.  Remove scan-assembler-times counting number of .align
	directives.
	* gcc.target/s390/hotpatch-26.c: New file.
	* gcc.target/s390/hotpatch-27.c: New file.
	* gcc.target/s390/hotpatch-28.c: New file.
	* gcc.target/s390/s390.exp: Run hotpatch-*.c tests as torture tests
	using -Os -O0 -O1 -O2 -O3 options.

[-- Attachment #3: 0001-PR-66215-S390-Fix-placement-of-post-label-NOPs-with-.patch --]
[-- Type: text/x-diff, Size: 27386 bytes --]

From 4829941179006e5fc1537360e87bcfb09fb9da22 Mon Sep 17 00:00:00 2001
From: Dominik Vogt <vogt@linux.vnet.ibm.com>
Date: Fri, 22 May 2015 09:03:26 +0100
Subject: [PATCH] PR 66215: S390: Fix placement of post-label NOPs with
 -mhotpatch=.

---
 gcc/config/s390/s390.c                      | 28 +++++++++++++++++-----------
 gcc/testsuite/gcc.target/s390/hotpatch-1.c  |  2 +-
 gcc/testsuite/gcc.target/s390/hotpatch-10.c |  2 +-
 gcc/testsuite/gcc.target/s390/hotpatch-11.c |  2 +-
 gcc/testsuite/gcc.target/s390/hotpatch-12.c |  2 +-
 gcc/testsuite/gcc.target/s390/hotpatch-13.c |  3 +--
 gcc/testsuite/gcc.target/s390/hotpatch-14.c |  4 ++--
 gcc/testsuite/gcc.target/s390/hotpatch-15.c |  4 ++--
 gcc/testsuite/gcc.target/s390/hotpatch-16.c |  4 ++--
 gcc/testsuite/gcc.target/s390/hotpatch-17.c |  2 +-
 gcc/testsuite/gcc.target/s390/hotpatch-18.c |  2 +-
 gcc/testsuite/gcc.target/s390/hotpatch-19.c |  4 ++--
 gcc/testsuite/gcc.target/s390/hotpatch-2.c  |  4 ++--
 gcc/testsuite/gcc.target/s390/hotpatch-20.c |  2 +-
 gcc/testsuite/gcc.target/s390/hotpatch-21.c |  2 +-
 gcc/testsuite/gcc.target/s390/hotpatch-22.c |  2 +-
 gcc/testsuite/gcc.target/s390/hotpatch-23.c |  2 +-
 gcc/testsuite/gcc.target/s390/hotpatch-24.c |  2 +-
 gcc/testsuite/gcc.target/s390/hotpatch-25.c |  9 ++++-----
 gcc/testsuite/gcc.target/s390/hotpatch-26.c | 17 +++++++++++++++++
 gcc/testsuite/gcc.target/s390/hotpatch-27.c | 17 +++++++++++++++++
 gcc/testsuite/gcc.target/s390/hotpatch-28.c | 18 ++++++++++++++++++
 gcc/testsuite/gcc.target/s390/hotpatch-3.c  |  4 ++--
 gcc/testsuite/gcc.target/s390/hotpatch-4.c  |  4 ++--
 gcc/testsuite/gcc.target/s390/hotpatch-5.c  |  4 ++--
 gcc/testsuite/gcc.target/s390/hotpatch-6.c  |  4 ++--
 gcc/testsuite/gcc.target/s390/hotpatch-7.c  |  4 ++--
 gcc/testsuite/gcc.target/s390/hotpatch-8.c  |  4 ++--
 gcc/testsuite/gcc.target/s390/hotpatch-9.c  |  4 ++--
 gcc/testsuite/gcc.target/s390/s390.exp      | 13 +++++++++++--
 30 files changed, 120 insertions(+), 55 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/s390/hotpatch-26.c
 create mode 100644 gcc/testsuite/gcc.target/s390/hotpatch-27.c
 create mode 100644 gcc/testsuite/gcc.target/s390/hotpatch-28.c

diff --git a/gcc/config/s390/s390.c b/gcc/config/s390/s390.c
index 6648597..90d43b1 100644
--- a/gcc/config/s390/s390.c
+++ b/gcc/config/s390/s390.c
@@ -12843,31 +12843,37 @@ s390_reorg (void)
 
       /* Insert NOPs for hotpatching. */
       for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
-	{
-	  if (NOTE_P (insn) && NOTE_KIND (insn) == NOTE_INSN_FUNCTION_BEG)
-	    break;
-	}
-      gcc_assert (insn);
-      /* Output a series of NOPs after the NOTE_INSN_FUNCTION_BEG.  */
-      while (hw_after > 0)
+	/* Emit NOPs
+	    1. inside the area covered by debug information to allow setting
+	       breakpoints at the NOPs,
+	    2. before any insn which results in an asm instruction,
+	    3. before in-function labels to avoid jumping to the NOPs, for
+	       example as part of a loop,
+	    4. before any barrier in case the function is completely empty
+	       (__builtin_unreachable ()) and has neither internal labels nor
+	       active insns.
+	*/
+	if (active_insn_p (insn) || BARRIER_P (insn) || LABEL_P (insn))
+	  break;
+      /* Output a series of NOPs before the first active insn.  */
+      while (insn && hw_after > 0)
 	{
 	  if (hw_after >= 3 && TARGET_CPU_ZARCH)
 	    {
-	      insn = emit_insn_after (gen_nop_6_byte (), insn);
+	      emit_insn_before (gen_nop_6_byte (), insn);
 	      hw_after -= 3;
 	    }
 	  else if (hw_after >= 2)
 	    {
-	      insn = emit_insn_after (gen_nop_4_byte (), insn);
+	      emit_insn_before (gen_nop_4_byte (), insn);
 	      hw_after -= 2;
 	    }
 	  else
 	    {
-	      insn = emit_insn_after (gen_nop_2_byte (), insn);
+	      emit_insn_before (gen_nop_2_byte (), insn);
 	      hw_after -= 1;
 	    }
 	}
-      gcc_assert (hw_after == 0);
     }
 }
 
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-1.c b/gcc/testsuite/gcc.target/s390/hotpatch-1.c
index b14fa90..55088b8 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-1.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-1.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch" } */
+/* { dg-options "-mzarch" } */
 
 #include <stdio.h>
 
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-10.c b/gcc/testsuite/gcc.target/s390/hotpatch-10.c
index a990c4c..d2cb9a2 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-10.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-10.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=0,0" } */
+/* { dg-options "-mzarch -mhotpatch=0,0" } */
 
 #include <stdio.h>
 
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-11.c b/gcc/testsuite/gcc.target/s390/hotpatch-11.c
index 6f8a52b..cabb9d26 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-11.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-11.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=1,0" } */
+/* { dg-options "-mzarch -mhotpatch=1,0" } */
 
 #include <stdio.h>
 
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-12.c b/gcc/testsuite/gcc.target/s390/hotpatch-12.c
index b73ca90..fc9adc3 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-12.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-12.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=999,0" } */
+/* { dg-options "-mzarch -mhotpatch=999,0" } */
 
 #include <stdio.h>
 
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-13.c b/gcc/testsuite/gcc.target/s390/hotpatch-13.c
index 150667a..b25fbd3 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-13.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-13.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch" } */
+/* { dg-options "-mzarch" } */
 
 #include <stdio.h>
 
@@ -18,4 +18,3 @@ void hp1(void)
 /* { dg-final { scan-assembler-not "nop\t0" } } */
 /* { dg-final { scan-assembler-not "brcl\t0, 0" } } */
 /* { dg-final { scan-assembler "alignment for hotpatch" } } */
-/* { dg-final { scan-assembler-times "\.align\t8" 2 } } */
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-14.c b/gcc/testsuite/gcc.target/s390/hotpatch-14.c
index c5f118c..c387d6b 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-14.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-14.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch" } */
+/* { dg-options "-mzarch" } */
 
 #include <stdio.h>
 
@@ -13,7 +13,7 @@ void hp1(void)
 
 /* Check number of occurences of certain instructions.  */
 /* { dg-final { scan-assembler-not "pre-label NOPs" } } */
-/* { dg-final { scan-assembler "post-label.*(2 halfwords)" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(2 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*nop\t0" } } */
 /* { dg-final { scan-assembler-not "nopr\t%r7" } } */
 /* { dg-final { scan-assembler-times "nop\t0" 1 } } */
 /* { dg-final { scan-assembler-not "brcl\t0, 0" } } */
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-15.c b/gcc/testsuite/gcc.target/s390/hotpatch-15.c
index ef0fb74..410106b 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-15.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-15.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch" } */
+/* { dg-options "-mzarch" } */
 
 #include <stdio.h>
 
@@ -13,7 +13,7 @@ void hp1(void)
 
 /* Check number of occurences of certain instructions.  */
 /* { dg-final { scan-assembler "pre-label.*(1 halfwords)" } } */
-/* { dg-final { scan-assembler "post-label.*(2 halfwords)" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(2 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*nop\t0" } } */
 /* { dg-final { scan-assembler-times "nopr\t%r7" 1 } } */
 /* { dg-final { scan-assembler-times "nop\t0" 1 } } */
 /* { dg-final { scan-assembler-not "brcl\t0, 0" } } */
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-16.c b/gcc/testsuite/gcc.target/s390/hotpatch-16.c
index a34bf95..fa06fff 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-16.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-16.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=0,0" } */
+/* { dg-options "-mzarch -mhotpatch=0,0" } */
 
 #include <stdio.h>
 
@@ -13,7 +13,7 @@ void hp1(void)
 
 /* Check number of occurences of certain instructions.  */
 /* { dg-final { scan-assembler "pre-label.*(1 halfwords)" } } */
-/* { dg-final { scan-assembler "post-label.*(2 halfwords)" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(2 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*nop\t0" } } */
 /* { dg-final { scan-assembler-times "nopr\t%r7" 1 } } */
 /* { dg-final { scan-assembler-times "nop\t0" 1 } } */
 /* { dg-final { scan-assembler-not "brcl\t0, 0" } } */
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-17.c b/gcc/testsuite/gcc.target/s390/hotpatch-17.c
index 66ac725..3ef7d69 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-17.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-17.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=1,2" } */
+/* { dg-options "-mzarch -mhotpatch=1,2" } */
 
 #include <stdio.h>
 
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-18.c b/gcc/testsuite/gcc.target/s390/hotpatch-18.c
index 8b076a4..c93af7f 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-18.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-18.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=1,2 -mhotpatch=0,0" } */
+/* { dg-options "-mzarch -mhotpatch=1,2 -mhotpatch=0,0" } */
 
 #include <stdio.h>
 
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-19.c b/gcc/testsuite/gcc.target/s390/hotpatch-19.c
index 6993c7e..c69b35e 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-19.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-19.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=1,2" } */
+/* { dg-options "-mzarch -mhotpatch=1,2" } */
 
 #include <stdio.h>
 
@@ -19,7 +19,7 @@ void hp1(void)
 
 /* Check number of occurences of certain instructions.  */
 /* { dg-final { scan-assembler "pre-label.*(1 halfwords)" } } */
-/* { dg-final { scan-assembler "post-label.*(2 halfwords)" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(2 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*nop\t0" } } */
 /* { dg-final { scan-assembler-times "nopr\t%r7" 1 } } */
 /* { dg-final { scan-assembler-times "nop\t0" 1 } } */
 /* { dg-final { scan-assembler-not "brcl\t0, 0" } } */
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-2.c b/gcc/testsuite/gcc.target/s390/hotpatch-2.c
index 67189f8..2a2665e 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-2.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-2.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=0,1" } */
+/* { dg-options "-mzarch -mhotpatch=0,1" } */
 
 #include <stdio.h>
 
@@ -12,7 +12,7 @@ void hp1(void)
 
 /* Check number of occurences of certain instructions.  */
 /* { dg-final { scan-assembler-not "pre-label NOPs" } } */
-/* { dg-final { scan-assembler "post-label.*(1 halfwords)" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(1 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*nopr\t" } } */
 /* { dg-final { scan-assembler-times "nopr\t%r7" 1 } } */
 /* { dg-final { scan-assembler-not "nop\t0" } } */
 /* { dg-final { scan-assembler-not "brcl\t0, 0" } } */
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-20.c b/gcc/testsuite/gcc.target/s390/hotpatch-20.c
index 09ef5ca..0a32a68 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-20.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-20.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch" } */
+/* { dg-options "-mzarch" } */
 
 #include <stdio.h>
 
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-21.c b/gcc/testsuite/gcc.target/s390/hotpatch-21.c
index e909990..f6e9099 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-21.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-21.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=0,1" } */
+/* { dg-options "-mzarch -mhotpatch=0,1" } */
 
 #include <stdio.h>
 
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-22.c b/gcc/testsuite/gcc.target/s390/hotpatch-22.c
index d89d779..21f7d7e 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-22.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-22.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=0,1 -falign-functions=1024" } */
+/* { dg-options "-mzarch -mhotpatch=0,1 -falign-functions=1024" } */
 
 #include <stdio.h>
 
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-23.c b/gcc/testsuite/gcc.target/s390/hotpatch-23.c
index 1e05d12..6e149cc 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-23.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-23.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=0,1 -falign-functions=4096" } */
+/* { dg-options "-mzarch -mhotpatch=0,1 -falign-functions=4096" } */
 
 #include <stdio.h>
 
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-24.c b/gcc/testsuite/gcc.target/s390/hotpatch-24.c
index fc64274..1e47591 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-24.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-24.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=0,1 -falign-functions=2048" } */
+/* { dg-options "-mzarch -mhotpatch=0,1 -falign-functions=2048" } */
 
 #include <stdio.h>
 
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-25.c b/gcc/testsuite/gcc.target/s390/hotpatch-25.c
index e9257e3..e6cdbb6 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-25.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-25.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch" } */
+/* { dg-options "-mzarch" } */
 
 typedef long (*fn_t)(void);
 
@@ -25,9 +25,8 @@ fn_t outer(void)
 /* { dg-final { scan-assembler "pre-label.*(1 halfwords)" } } */
 /* { dg-final { scan-assembler "pre-label.*(4 halfwords)" } } */
 /* { dg-final { scan-assembler "pre-label.*(16 halfwords)" } } */
-/* { dg-final { scan-assembler "post-label.*(2 halfwords)" } } */
-/* { dg-final { scan-assembler "post-label.*(8 halfwords)" } } */
-/* { dg-final { scan-assembler "post-label.*(32 halfwords)" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(2 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*nopr\t" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(8 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*brcl\t0, 0" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(32 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*brcl\t0, 0" } } */
 /* { dg-final { scan-assembler-times "alignment for hotpatch" 3 } } */
-/* { dg-final { scan-assembler-times "\.align\t8" 6 } } */
 /* { dg-final { scan-assembler "nopr.*\n.*nopr.*\n.*nopr.*\n.*nopr.*\n.*nopr.*\n.*nopr.*\n.*nopr.*\n.*nopr.*\n.*nopr.*\n.*nopr.*\n.*nopr.*\n.*nopr.*\n.*nopr.*\n.*nopr.*\n.*nopr.*\n.*nopr" } } */
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-26.c b/gcc/testsuite/gcc.target/s390/hotpatch-26.c
new file mode 100644
index 0000000..eb95c26
--- /dev/null
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-26.c
@@ -0,0 +1,17 @@
+/* Functional tests for the function hotpatching feature.  */
+
+/* { dg-do compile } */
+/* { dg-options "-O3 -mzarch -mhotpatch=1,2" } */
+
+__attribute__ ((noreturn)) void hp1(void)
+{
+  __builtin_unreachable ();
+}
+
+/* Check number of occurences of certain instructions.  */
+/* { dg-final { scan-assembler "pre-label NOPs" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(2 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*nop\t0" } } */
+/* { dg-final { scan-assembler-times "nopr\t%r7" 1 } } */
+/* { dg-final { scan-assembler-times "nop\t0" 1 } } */
+/* { dg-final { scan-assembler-not "brcl\t0, 0" } } */
+/* { dg-final { scan-assembler "alignment for hotpatch" } } */
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-27.c b/gcc/testsuite/gcc.target/s390/hotpatch-27.c
new file mode 100644
index 0000000..cdbd4ca
--- /dev/null
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-27.c
@@ -0,0 +1,17 @@
+/* Functional tests for the function hotpatching feature.  */
+
+/* { dg-do compile } */
+/* { dg-options "-O3 -mzarch -mhotpatch=1,2" } */
+
+__attribute__ ((noreturn)) void hp3(void)
+{
+  __builtin_unreachable ();
+}
+
+/* Check number of occurences of certain instructions.  */
+/* { dg-final { scan-assembler "pre-label NOPs" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(2 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*nop\t0" } } */
+/* { dg-final { scan-assembler-times "nopr\t%r7" 1 } } */
+/* { dg-final { scan-assembler-times "nop\t0" 1 } } */
+/* { dg-final { scan-assembler-not "brcl\t0, 0" } } */
+/* { dg-final { scan-assembler "alignment for hotpatch" } } */
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-28.c b/gcc/testsuite/gcc.target/s390/hotpatch-28.c
new file mode 100644
index 0000000..9922daa
--- /dev/null
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-28.c
@@ -0,0 +1,18 @@
+/* Functional tests for the function hotpatching feature.  */
+
+/* { dg-do compile } */
+/* { dg-options "-O3 -mzarch -mhotpatch=1,2" } */
+
+void hp1 (volatile unsigned int *i)
+{
+  for (;;)
+    (*i)++;
+}
+
+/* Check number of occurences of certain instructions.  */
+/* { dg-final { scan-assembler "pre-label NOPs" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(2 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*nop\t0" } } */
+/* { dg-final { scan-assembler-times "nopr\t%r7" 1 } } */
+/* { dg-final { scan-assembler-times "nop\t0" 1 } } */
+/* { dg-final { scan-assembler-not "brcl\t0, 0" } } */
+/* { dg-final { scan-assembler "alignment for hotpatch" } } */
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-3.c b/gcc/testsuite/gcc.target/s390/hotpatch-3.c
index ec4a978..6718591 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-3.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-3.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=0,2" } */
+/* { dg-options "-mzarch -mhotpatch=0,2" } */
 
 #include <stdio.h>
 
@@ -12,7 +12,7 @@ void hp1(void)
 
 /* Check number of occurences of certain instructions.  */
 /* { dg-final { scan-assembler-not "pre-label NOPs" } } */
-/* { dg-final { scan-assembler "post-label.*(2 halfwords)" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(2 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*nop\t0" } } */
 /* { dg-final { scan-assembler-not "nopr\t%r7" } } */
 /* { dg-final { scan-assembler-times "nop\t0" 1 } } */
 /* { dg-final { scan-assembler-not "brcl\t0, 0" } } */
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-4.c b/gcc/testsuite/gcc.target/s390/hotpatch-4.c
index d55e71d..b770d4b 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-4.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-4.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=0,3" } */
+/* { dg-options "-mzarch -mhotpatch=0,3" } */
 
 #include <stdio.h>
 
@@ -12,7 +12,7 @@ void hp1(void)
 
 /* Check number of occurences of certain instructions.  */
 /* { dg-final { scan-assembler-not "pre-label NOPs" } } */
-/* { dg-final { scan-assembler "post-label.*(3 halfwords)" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(3 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*brcl\t0, 0" } } */
 /* { dg-final { scan-assembler-not "nopr\t%r7" } } */
 /* { dg-final { scan-assembler-not "nop\t0" } } */
 /* { dg-final { scan-assembler-times "brcl\t0, 0" 1 } } */
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-5.c b/gcc/testsuite/gcc.target/s390/hotpatch-5.c
index f77d83a..f1dcd89 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-5.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-5.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=0,4" } */
+/* { dg-options "-mzarch -mhotpatch=0,4" } */
 
 #include <stdio.h>
 
@@ -12,7 +12,7 @@ void hp1(void)
 
 /* Check number of occurences of certain instructions.  */
 /* { dg-final { scan-assembler-not "pre-label NOPs" } } */
-/* { dg-final { scan-assembler "post-label.*(4 halfwords)" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(4 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*brcl\t0, 0" } } */
 /* { dg-final { scan-assembler-times "nopr\t%r7" 1 } } */
 /* { dg-final { scan-assembler-not "nop\t0" } } */
 /* { dg-final { scan-assembler-times "brcl\t0, 0" 1 } } */
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-6.c b/gcc/testsuite/gcc.target/s390/hotpatch-6.c
index 330cf5d..6203a72b 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-6.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-6.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=0,5" } */
+/* { dg-options "-mzarch -mhotpatch=0,5" } */
 
 #include <stdio.h>
 
@@ -12,7 +12,7 @@ void hp1(void)
 
 /* Check number of occurences of certain instructions.  */
 /* { dg-final { scan-assembler-not "pre-label NOPs" } } */
-/* { dg-final { scan-assembler "post-label.*(5 halfwords)" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(5 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*brcl\t0, 0" } } */
 /* { dg-final { scan-assembler-not "nopr\t%r7" } } */
 /* { dg-final { scan-assembler-times "nop\t0" 1 } } */
 /* { dg-final { scan-assembler-times "brcl\t0, 0" 1 } } */
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-7.c b/gcc/testsuite/gcc.target/s390/hotpatch-7.c
index 2f24e3cc..e201ae9 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-7.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-7.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=0,6" } */
+/* { dg-options "-mzarch -mhotpatch=0,6" } */
 
 #include <stdio.h>
 
@@ -12,7 +12,7 @@ void hp1(void)
 
 /* Check number of occurences of certain instructions.  */
 /* { dg-final { scan-assembler-not "pre-label NOPs" } } */
-/* { dg-final { scan-assembler "post-label.*(6 halfwords)" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(6 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*brcl\t0, 0" } } */
 /* { dg-final { scan-assembler-not "nopr\t%r7" } } */
 /* { dg-final { scan-assembler-not "nop\t0" } } */
 /* { dg-final { scan-assembler-times "brcl\t0, 0" 2 } } */
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-8.c b/gcc/testsuite/gcc.target/s390/hotpatch-8.c
index 7b266bd..1ea3160 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-8.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-8.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile { target { ! lp64 } } } */
-/* { dg-options "-O3 -mesa -march=g5 -mhotpatch=0,3" } */
+/* { dg-options "-mesa -march=g5 -mhotpatch=0,3" } */
 
 #include <stdio.h>
 
@@ -12,7 +12,7 @@ void hp1(void)
 
 /* Check number of occurences of certain instructions.  */
 /* { dg-final { scan-assembler-not "pre-label NOPs" } } */
-/* { dg-final { scan-assembler "post-label.*(3 halfwords)" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(3 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*nop\t0" } } */
 /* { dg-final { scan-assembler-times "nopr\t%r7" 1 } } */
 /* { dg-final { scan-assembler-times "nop\t0" 1 } } */
 /* { dg-final { scan-assembler-not "brcl\t0, 0" } } */
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-9.c b/gcc/testsuite/gcc.target/s390/hotpatch-9.c
index c0ad319..e30f276 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-9.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-9.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile { target { ! lp64 } } } */
-/* { dg-options "-O3 -mesa -march=g5 -mhotpatch=0,4" } */
+/* { dg-options "-mesa -march=g5 -mhotpatch=0,4" } */
 
 #include <stdio.h>
 
@@ -12,7 +12,7 @@ void hp1(void)
 
 /* Check number of occurences of certain instructions.  */
 /* { dg-final { scan-assembler-not "pre-label NOPs" } } */
-/* { dg-final { scan-assembler "post-label.*(4 halfwords)" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(4 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*nop\t0" } } */
 /* { dg-final { scan-assembler-not "nopr\t%r7" } } */
 /* { dg-final { scan-assembler-times "nop\t0" 2 } } */
 /* { dg-final { scan-assembler-not "brcl\t0, 0" } } */
diff --git a/gcc/testsuite/gcc.target/s390/s390.exp b/gcc/testsuite/gcc.target/s390/s390.exp
index eb1d73b..0b8f80ed 100644
--- a/gcc/testsuite/gcc.target/s390/s390.exp
+++ b/gcc/testsuite/gcc.target/s390/s390.exp
@@ -61,12 +61,21 @@ if ![info exists DEFAULT_CFLAGS] then {
 # Initialize `dg'.
 dg-init
 
+set hotpatch_tests $srcdir/$subdir/hotpatch-\[0-9\]*.c
+
 # Main loop.
-dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.\[cS\]]] \
-	"" $DEFAULT_CFLAGS
+dg-runtest [lsort [prune [glob -nocomplain $srcdir/$subdir/*.\[cS\]] \
+			 $hotpatch_tests]] "" $DEFAULT_CFLAGS
 
 dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*vector*/*.\[cS\]]] \
 	"" $DEFAULT_CFLAGS
 
+# Additional hotpatch torture tests.
+torture-init
+set HOTPATCH_TEST_OPTS [list -Os -O0 -O1 -O2 -O3]
+set-torture-options $HOTPATCH_TEST_OPTS
+gcc-dg-runtest [lsort [glob -nocomplain $hotpatch_tests]] "" $DEFAULT_CFLAGS
+torture-finish
+
 # All done.
 dg-finish
-- 
2.3.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] PR 66215: S390: Fix placement of post-label NOPs with -mhotpatch
  2015-05-29 15:18   ` Dominik Vogt
@ 2015-05-29 15:28     ` Andreas Krebbel
  2015-06-01  8:33     ` Dominik Vogt
  1 sibling, 0 replies; 5+ messages in thread
From: Andreas Krebbel @ 2015-05-29 15:28 UTC (permalink / raw)
  To: gcc-patches

On 05/29/2015 04:14 PM, Dominik Vogt wrote:
> No bother, new versions attached.

Applied to mainline. Thanks!

-Andreas-


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] PR 66215: S390: Fix placement of post-label NOPs with -mhotpatch
  2015-05-29 15:18   ` Dominik Vogt
  2015-05-29 15:28     ` Andreas Krebbel
@ 2015-06-01  8:33     ` Dominik Vogt
  1 sibling, 0 replies; 5+ messages in thread
From: Dominik Vogt @ 2015-06-01  8:33 UTC (permalink / raw)
  To: gcc-patches; +Cc: Andreas Krebbel

[-- Attachment #1: Type: text/plain, Size: 239 bytes --]

Backports of the patch for 5.1, 4.9 and 4.8 are attached to this
message.  The ChangeLog is the same as for upstream.  (See
https://gcc.gnu.org/ml/gcc-patches/2015-05/msg02791.html ).

Ciao

Dominik ^_^  ^_^

-- 

Dominik Vogt
IBM Germany

[-- Attachment #2: hotpatch13-gcc51-0001-PR-66215-S390-Fix-placement-of-post-label-NOPs-with-.patch --]
[-- Type: text/x-diff, Size: 27286 bytes --]

From 996b1dc70c3cc95df6b1e11cea966d6d01e2ddc7 Mon Sep 17 00:00:00 2001
From: Dominik Vogt <vogt@linux.vnet.ibm.com>
Date: Fri, 22 May 2015 09:03:26 +0100
Subject: [PATCH] PR 66215: S390: Fix placement of post-label NOPs with
 -mhotpatch=.

---
 gcc/config/s390/s390.c                      | 28 +++++++++++++++++-----------
 gcc/testsuite/gcc.target/s390/hotpatch-1.c  |  2 +-
 gcc/testsuite/gcc.target/s390/hotpatch-10.c |  2 +-
 gcc/testsuite/gcc.target/s390/hotpatch-11.c |  2 +-
 gcc/testsuite/gcc.target/s390/hotpatch-12.c |  2 +-
 gcc/testsuite/gcc.target/s390/hotpatch-13.c |  3 +--
 gcc/testsuite/gcc.target/s390/hotpatch-14.c |  4 ++--
 gcc/testsuite/gcc.target/s390/hotpatch-15.c |  4 ++--
 gcc/testsuite/gcc.target/s390/hotpatch-16.c |  4 ++--
 gcc/testsuite/gcc.target/s390/hotpatch-17.c |  2 +-
 gcc/testsuite/gcc.target/s390/hotpatch-18.c |  2 +-
 gcc/testsuite/gcc.target/s390/hotpatch-19.c |  4 ++--
 gcc/testsuite/gcc.target/s390/hotpatch-2.c  |  4 ++--
 gcc/testsuite/gcc.target/s390/hotpatch-20.c |  2 +-
 gcc/testsuite/gcc.target/s390/hotpatch-21.c |  2 +-
 gcc/testsuite/gcc.target/s390/hotpatch-22.c |  2 +-
 gcc/testsuite/gcc.target/s390/hotpatch-23.c |  2 +-
 gcc/testsuite/gcc.target/s390/hotpatch-24.c |  2 +-
 gcc/testsuite/gcc.target/s390/hotpatch-25.c |  9 ++++-----
 gcc/testsuite/gcc.target/s390/hotpatch-26.c | 17 +++++++++++++++++
 gcc/testsuite/gcc.target/s390/hotpatch-27.c | 17 +++++++++++++++++
 gcc/testsuite/gcc.target/s390/hotpatch-28.c | 18 ++++++++++++++++++
 gcc/testsuite/gcc.target/s390/hotpatch-3.c  |  4 ++--
 gcc/testsuite/gcc.target/s390/hotpatch-4.c  |  4 ++--
 gcc/testsuite/gcc.target/s390/hotpatch-5.c  |  4 ++--
 gcc/testsuite/gcc.target/s390/hotpatch-6.c  |  4 ++--
 gcc/testsuite/gcc.target/s390/hotpatch-7.c  |  4 ++--
 gcc/testsuite/gcc.target/s390/hotpatch-8.c  |  4 ++--
 gcc/testsuite/gcc.target/s390/hotpatch-9.c  |  4 ++--
 gcc/testsuite/gcc.target/s390/s390.exp      | 13 +++++++++++--
 30 files changed, 120 insertions(+), 55 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/s390/hotpatch-26.c
 create mode 100644 gcc/testsuite/gcc.target/s390/hotpatch-27.c
 create mode 100644 gcc/testsuite/gcc.target/s390/hotpatch-28.c

diff --git a/gcc/config/s390/s390.c b/gcc/config/s390/s390.c
index 1e6c7fb..26f2b6e 100644
--- a/gcc/config/s390/s390.c
+++ b/gcc/config/s390/s390.c
@@ -11492,31 +11492,37 @@ s390_reorg (void)
 
       /* Insert NOPs for hotpatching. */
       for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
-	{
-	  if (NOTE_P (insn) && NOTE_KIND (insn) == NOTE_INSN_FUNCTION_BEG)
-	    break;
-	}
-      gcc_assert (insn);
-      /* Output a series of NOPs after the NOTE_INSN_FUNCTION_BEG.  */
-      while (hw_after > 0)
+	/* Emit NOPs
+	    1. inside the area covered by debug information to allow setting
+	       breakpoints at the NOPs,
+	    2. before any insn which results in an asm instruction,
+	    3. before in-function labels to avoid jumping to the NOPs, for
+	       example as part of a loop,
+	    4. before any barrier in case the function is completely empty
+	       (__builtin_unreachable ()) and has neither internal labels nor
+	       active insns.
+	*/
+	if (active_insn_p (insn) || BARRIER_P (insn) || LABEL_P (insn))
+	  break;
+      /* Output a series of NOPs before the first active insn.  */
+      while (insn && hw_after > 0)
 	{
 	  if (hw_after >= 3 && TARGET_CPU_ZARCH)
 	    {
-	      insn = emit_insn_after (gen_nop_6_byte (), insn);
+	      emit_insn_before (gen_nop_6_byte (), insn);
 	      hw_after -= 3;
 	    }
 	  else if (hw_after >= 2)
 	    {
-	      insn = emit_insn_after (gen_nop_4_byte (), insn);
+	      emit_insn_before (gen_nop_4_byte (), insn);
 	      hw_after -= 2;
 	    }
 	  else
 	    {
-	      insn = emit_insn_after (gen_nop_2_byte (), insn);
+	      emit_insn_before (gen_nop_2_byte (), insn);
 	      hw_after -= 1;
 	    }
 	}
-      gcc_assert (hw_after == 0);
     }
 }
 
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-1.c b/gcc/testsuite/gcc.target/s390/hotpatch-1.c
index b14fa90..55088b8 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-1.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-1.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch" } */
+/* { dg-options "-mzarch" } */
 
 #include <stdio.h>
 
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-10.c b/gcc/testsuite/gcc.target/s390/hotpatch-10.c
index a990c4c..d2cb9a2 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-10.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-10.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=0,0" } */
+/* { dg-options "-mzarch -mhotpatch=0,0" } */
 
 #include <stdio.h>
 
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-11.c b/gcc/testsuite/gcc.target/s390/hotpatch-11.c
index 6f8a52b..cabb9d26 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-11.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-11.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=1,0" } */
+/* { dg-options "-mzarch -mhotpatch=1,0" } */
 
 #include <stdio.h>
 
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-12.c b/gcc/testsuite/gcc.target/s390/hotpatch-12.c
index b73ca90..fc9adc3 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-12.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-12.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=999,0" } */
+/* { dg-options "-mzarch -mhotpatch=999,0" } */
 
 #include <stdio.h>
 
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-13.c b/gcc/testsuite/gcc.target/s390/hotpatch-13.c
index 150667a..b25fbd3 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-13.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-13.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch" } */
+/* { dg-options "-mzarch" } */
 
 #include <stdio.h>
 
@@ -18,4 +18,3 @@ void hp1(void)
 /* { dg-final { scan-assembler-not "nop\t0" } } */
 /* { dg-final { scan-assembler-not "brcl\t0, 0" } } */
 /* { dg-final { scan-assembler "alignment for hotpatch" } } */
-/* { dg-final { scan-assembler-times "\.align\t8" 2 } } */
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-14.c b/gcc/testsuite/gcc.target/s390/hotpatch-14.c
index c5f118c..c387d6b 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-14.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-14.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch" } */
+/* { dg-options "-mzarch" } */
 
 #include <stdio.h>
 
@@ -13,7 +13,7 @@ void hp1(void)
 
 /* Check number of occurences of certain instructions.  */
 /* { dg-final { scan-assembler-not "pre-label NOPs" } } */
-/* { dg-final { scan-assembler "post-label.*(2 halfwords)" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(2 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*nop\t0" } } */
 /* { dg-final { scan-assembler-not "nopr\t%r7" } } */
 /* { dg-final { scan-assembler-times "nop\t0" 1 } } */
 /* { dg-final { scan-assembler-not "brcl\t0, 0" } } */
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-15.c b/gcc/testsuite/gcc.target/s390/hotpatch-15.c
index ef0fb74..410106b 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-15.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-15.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch" } */
+/* { dg-options "-mzarch" } */
 
 #include <stdio.h>
 
@@ -13,7 +13,7 @@ void hp1(void)
 
 /* Check number of occurences of certain instructions.  */
 /* { dg-final { scan-assembler "pre-label.*(1 halfwords)" } } */
-/* { dg-final { scan-assembler "post-label.*(2 halfwords)" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(2 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*nop\t0" } } */
 /* { dg-final { scan-assembler-times "nopr\t%r7" 1 } } */
 /* { dg-final { scan-assembler-times "nop\t0" 1 } } */
 /* { dg-final { scan-assembler-not "brcl\t0, 0" } } */
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-16.c b/gcc/testsuite/gcc.target/s390/hotpatch-16.c
index a34bf95..fa06fff 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-16.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-16.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=0,0" } */
+/* { dg-options "-mzarch -mhotpatch=0,0" } */
 
 #include <stdio.h>
 
@@ -13,7 +13,7 @@ void hp1(void)
 
 /* Check number of occurences of certain instructions.  */
 /* { dg-final { scan-assembler "pre-label.*(1 halfwords)" } } */
-/* { dg-final { scan-assembler "post-label.*(2 halfwords)" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(2 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*nop\t0" } } */
 /* { dg-final { scan-assembler-times "nopr\t%r7" 1 } } */
 /* { dg-final { scan-assembler-times "nop\t0" 1 } } */
 /* { dg-final { scan-assembler-not "brcl\t0, 0" } } */
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-17.c b/gcc/testsuite/gcc.target/s390/hotpatch-17.c
index 66ac725..3ef7d69 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-17.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-17.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=1,2" } */
+/* { dg-options "-mzarch -mhotpatch=1,2" } */
 
 #include <stdio.h>
 
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-18.c b/gcc/testsuite/gcc.target/s390/hotpatch-18.c
index 8b076a4..c93af7f 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-18.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-18.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=1,2 -mhotpatch=0,0" } */
+/* { dg-options "-mzarch -mhotpatch=1,2 -mhotpatch=0,0" } */
 
 #include <stdio.h>
 
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-19.c b/gcc/testsuite/gcc.target/s390/hotpatch-19.c
index 6993c7e..c69b35e 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-19.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-19.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=1,2" } */
+/* { dg-options "-mzarch -mhotpatch=1,2" } */
 
 #include <stdio.h>
 
@@ -19,7 +19,7 @@ void hp1(void)
 
 /* Check number of occurences of certain instructions.  */
 /* { dg-final { scan-assembler "pre-label.*(1 halfwords)" } } */
-/* { dg-final { scan-assembler "post-label.*(2 halfwords)" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(2 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*nop\t0" } } */
 /* { dg-final { scan-assembler-times "nopr\t%r7" 1 } } */
 /* { dg-final { scan-assembler-times "nop\t0" 1 } } */
 /* { dg-final { scan-assembler-not "brcl\t0, 0" } } */
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-2.c b/gcc/testsuite/gcc.target/s390/hotpatch-2.c
index 67189f8..2a2665e 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-2.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-2.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=0,1" } */
+/* { dg-options "-mzarch -mhotpatch=0,1" } */
 
 #include <stdio.h>
 
@@ -12,7 +12,7 @@ void hp1(void)
 
 /* Check number of occurences of certain instructions.  */
 /* { dg-final { scan-assembler-not "pre-label NOPs" } } */
-/* { dg-final { scan-assembler "post-label.*(1 halfwords)" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(1 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*nopr\t" } } */
 /* { dg-final { scan-assembler-times "nopr\t%r7" 1 } } */
 /* { dg-final { scan-assembler-not "nop\t0" } } */
 /* { dg-final { scan-assembler-not "brcl\t0, 0" } } */
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-20.c b/gcc/testsuite/gcc.target/s390/hotpatch-20.c
index 09ef5ca..0a32a68 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-20.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-20.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch" } */
+/* { dg-options "-mzarch" } */
 
 #include <stdio.h>
 
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-21.c b/gcc/testsuite/gcc.target/s390/hotpatch-21.c
index e909990..f6e9099 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-21.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-21.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=0,1" } */
+/* { dg-options "-mzarch -mhotpatch=0,1" } */
 
 #include <stdio.h>
 
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-22.c b/gcc/testsuite/gcc.target/s390/hotpatch-22.c
index d89d779..21f7d7e 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-22.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-22.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=0,1 -falign-functions=1024" } */
+/* { dg-options "-mzarch -mhotpatch=0,1 -falign-functions=1024" } */
 
 #include <stdio.h>
 
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-23.c b/gcc/testsuite/gcc.target/s390/hotpatch-23.c
index 1e05d12..6e149cc 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-23.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-23.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=0,1 -falign-functions=4096" } */
+/* { dg-options "-mzarch -mhotpatch=0,1 -falign-functions=4096" } */
 
 #include <stdio.h>
 
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-24.c b/gcc/testsuite/gcc.target/s390/hotpatch-24.c
index fc64274..1e47591 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-24.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-24.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=0,1 -falign-functions=2048" } */
+/* { dg-options "-mzarch -mhotpatch=0,1 -falign-functions=2048" } */
 
 #include <stdio.h>
 
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-25.c b/gcc/testsuite/gcc.target/s390/hotpatch-25.c
index e9257e3..e6cdbb6 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-25.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-25.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch" } */
+/* { dg-options "-mzarch" } */
 
 typedef long (*fn_t)(void);
 
@@ -25,9 +25,8 @@ fn_t outer(void)
 /* { dg-final { scan-assembler "pre-label.*(1 halfwords)" } } */
 /* { dg-final { scan-assembler "pre-label.*(4 halfwords)" } } */
 /* { dg-final { scan-assembler "pre-label.*(16 halfwords)" } } */
-/* { dg-final { scan-assembler "post-label.*(2 halfwords)" } } */
-/* { dg-final { scan-assembler "post-label.*(8 halfwords)" } } */
-/* { dg-final { scan-assembler "post-label.*(32 halfwords)" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(2 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*nopr\t" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(8 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*brcl\t0, 0" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(32 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*brcl\t0, 0" } } */
 /* { dg-final { scan-assembler-times "alignment for hotpatch" 3 } } */
-/* { dg-final { scan-assembler-times "\.align\t8" 6 } } */
 /* { dg-final { scan-assembler "nopr.*\n.*nopr.*\n.*nopr.*\n.*nopr.*\n.*nopr.*\n.*nopr.*\n.*nopr.*\n.*nopr.*\n.*nopr.*\n.*nopr.*\n.*nopr.*\n.*nopr.*\n.*nopr.*\n.*nopr.*\n.*nopr.*\n.*nopr" } } */
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-26.c b/gcc/testsuite/gcc.target/s390/hotpatch-26.c
new file mode 100644
index 0000000..eb95c26
--- /dev/null
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-26.c
@@ -0,0 +1,17 @@
+/* Functional tests for the function hotpatching feature.  */
+
+/* { dg-do compile } */
+/* { dg-options "-O3 -mzarch -mhotpatch=1,2" } */
+
+__attribute__ ((noreturn)) void hp1(void)
+{
+  __builtin_unreachable ();
+}
+
+/* Check number of occurences of certain instructions.  */
+/* { dg-final { scan-assembler "pre-label NOPs" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(2 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*nop\t0" } } */
+/* { dg-final { scan-assembler-times "nopr\t%r7" 1 } } */
+/* { dg-final { scan-assembler-times "nop\t0" 1 } } */
+/* { dg-final { scan-assembler-not "brcl\t0, 0" } } */
+/* { dg-final { scan-assembler "alignment for hotpatch" } } */
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-27.c b/gcc/testsuite/gcc.target/s390/hotpatch-27.c
new file mode 100644
index 0000000..cdbd4ca
--- /dev/null
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-27.c
@@ -0,0 +1,17 @@
+/* Functional tests for the function hotpatching feature.  */
+
+/* { dg-do compile } */
+/* { dg-options "-O3 -mzarch -mhotpatch=1,2" } */
+
+__attribute__ ((noreturn)) void hp3(void)
+{
+  __builtin_unreachable ();
+}
+
+/* Check number of occurences of certain instructions.  */
+/* { dg-final { scan-assembler "pre-label NOPs" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(2 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*nop\t0" } } */
+/* { dg-final { scan-assembler-times "nopr\t%r7" 1 } } */
+/* { dg-final { scan-assembler-times "nop\t0" 1 } } */
+/* { dg-final { scan-assembler-not "brcl\t0, 0" } } */
+/* { dg-final { scan-assembler "alignment for hotpatch" } } */
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-28.c b/gcc/testsuite/gcc.target/s390/hotpatch-28.c
new file mode 100644
index 0000000..9922daa
--- /dev/null
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-28.c
@@ -0,0 +1,18 @@
+/* Functional tests for the function hotpatching feature.  */
+
+/* { dg-do compile } */
+/* { dg-options "-O3 -mzarch -mhotpatch=1,2" } */
+
+void hp1 (volatile unsigned int *i)
+{
+  for (;;)
+    (*i)++;
+}
+
+/* Check number of occurences of certain instructions.  */
+/* { dg-final { scan-assembler "pre-label NOPs" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(2 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*nop\t0" } } */
+/* { dg-final { scan-assembler-times "nopr\t%r7" 1 } } */
+/* { dg-final { scan-assembler-times "nop\t0" 1 } } */
+/* { dg-final { scan-assembler-not "brcl\t0, 0" } } */
+/* { dg-final { scan-assembler "alignment for hotpatch" } } */
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-3.c b/gcc/testsuite/gcc.target/s390/hotpatch-3.c
index ec4a978..6718591 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-3.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-3.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=0,2" } */
+/* { dg-options "-mzarch -mhotpatch=0,2" } */
 
 #include <stdio.h>
 
@@ -12,7 +12,7 @@ void hp1(void)
 
 /* Check number of occurences of certain instructions.  */
 /* { dg-final { scan-assembler-not "pre-label NOPs" } } */
-/* { dg-final { scan-assembler "post-label.*(2 halfwords)" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(2 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*nop\t0" } } */
 /* { dg-final { scan-assembler-not "nopr\t%r7" } } */
 /* { dg-final { scan-assembler-times "nop\t0" 1 } } */
 /* { dg-final { scan-assembler-not "brcl\t0, 0" } } */
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-4.c b/gcc/testsuite/gcc.target/s390/hotpatch-4.c
index d55e71d..b770d4b 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-4.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-4.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=0,3" } */
+/* { dg-options "-mzarch -mhotpatch=0,3" } */
 
 #include <stdio.h>
 
@@ -12,7 +12,7 @@ void hp1(void)
 
 /* Check number of occurences of certain instructions.  */
 /* { dg-final { scan-assembler-not "pre-label NOPs" } } */
-/* { dg-final { scan-assembler "post-label.*(3 halfwords)" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(3 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*brcl\t0, 0" } } */
 /* { dg-final { scan-assembler-not "nopr\t%r7" } } */
 /* { dg-final { scan-assembler-not "nop\t0" } } */
 /* { dg-final { scan-assembler-times "brcl\t0, 0" 1 } } */
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-5.c b/gcc/testsuite/gcc.target/s390/hotpatch-5.c
index f77d83a..f1dcd89 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-5.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-5.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=0,4" } */
+/* { dg-options "-mzarch -mhotpatch=0,4" } */
 
 #include <stdio.h>
 
@@ -12,7 +12,7 @@ void hp1(void)
 
 /* Check number of occurences of certain instructions.  */
 /* { dg-final { scan-assembler-not "pre-label NOPs" } } */
-/* { dg-final { scan-assembler "post-label.*(4 halfwords)" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(4 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*brcl\t0, 0" } } */
 /* { dg-final { scan-assembler-times "nopr\t%r7" 1 } } */
 /* { dg-final { scan-assembler-not "nop\t0" } } */
 /* { dg-final { scan-assembler-times "brcl\t0, 0" 1 } } */
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-6.c b/gcc/testsuite/gcc.target/s390/hotpatch-6.c
index 330cf5d..6203a72b 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-6.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-6.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=0,5" } */
+/* { dg-options "-mzarch -mhotpatch=0,5" } */
 
 #include <stdio.h>
 
@@ -12,7 +12,7 @@ void hp1(void)
 
 /* Check number of occurences of certain instructions.  */
 /* { dg-final { scan-assembler-not "pre-label NOPs" } } */
-/* { dg-final { scan-assembler "post-label.*(5 halfwords)" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(5 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*brcl\t0, 0" } } */
 /* { dg-final { scan-assembler-not "nopr\t%r7" } } */
 /* { dg-final { scan-assembler-times "nop\t0" 1 } } */
 /* { dg-final { scan-assembler-times "brcl\t0, 0" 1 } } */
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-7.c b/gcc/testsuite/gcc.target/s390/hotpatch-7.c
index 2f24e3cc..e201ae9 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-7.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-7.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=0,6" } */
+/* { dg-options "-mzarch -mhotpatch=0,6" } */
 
 #include <stdio.h>
 
@@ -12,7 +12,7 @@ void hp1(void)
 
 /* Check number of occurences of certain instructions.  */
 /* { dg-final { scan-assembler-not "pre-label NOPs" } } */
-/* { dg-final { scan-assembler "post-label.*(6 halfwords)" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(6 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*brcl\t0, 0" } } */
 /* { dg-final { scan-assembler-not "nopr\t%r7" } } */
 /* { dg-final { scan-assembler-not "nop\t0" } } */
 /* { dg-final { scan-assembler-times "brcl\t0, 0" 2 } } */
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-8.c b/gcc/testsuite/gcc.target/s390/hotpatch-8.c
index 7b266bd..1ea3160 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-8.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-8.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile { target { ! lp64 } } } */
-/* { dg-options "-O3 -mesa -march=g5 -mhotpatch=0,3" } */
+/* { dg-options "-mesa -march=g5 -mhotpatch=0,3" } */
 
 #include <stdio.h>
 
@@ -12,7 +12,7 @@ void hp1(void)
 
 /* Check number of occurences of certain instructions.  */
 /* { dg-final { scan-assembler-not "pre-label NOPs" } } */
-/* { dg-final { scan-assembler "post-label.*(3 halfwords)" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(3 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*nop\t0" } } */
 /* { dg-final { scan-assembler-times "nopr\t%r7" 1 } } */
 /* { dg-final { scan-assembler-times "nop\t0" 1 } } */
 /* { dg-final { scan-assembler-not "brcl\t0, 0" } } */
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-9.c b/gcc/testsuite/gcc.target/s390/hotpatch-9.c
index c0ad319..e30f276 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-9.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-9.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile { target { ! lp64 } } } */
-/* { dg-options "-O3 -mesa -march=g5 -mhotpatch=0,4" } */
+/* { dg-options "-mesa -march=g5 -mhotpatch=0,4" } */
 
 #include <stdio.h>
 
@@ -12,7 +12,7 @@ void hp1(void)
 
 /* Check number of occurences of certain instructions.  */
 /* { dg-final { scan-assembler-not "pre-label NOPs" } } */
-/* { dg-final { scan-assembler "post-label.*(4 halfwords)" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(4 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*nop\t0" } } */
 /* { dg-final { scan-assembler-not "nopr\t%r7" } } */
 /* { dg-final { scan-assembler-times "nop\t0" 2 } } */
 /* { dg-final { scan-assembler-not "brcl\t0, 0" } } */
diff --git a/gcc/testsuite/gcc.target/s390/s390.exp b/gcc/testsuite/gcc.target/s390/s390.exp
index 431e2c0..4c719f9 100644
--- a/gcc/testsuite/gcc.target/s390/s390.exp
+++ b/gcc/testsuite/gcc.target/s390/s390.exp
@@ -46,9 +46,18 @@ if ![info exists DEFAULT_CFLAGS] then {
 # Initialize `dg'.
 dg-init
 
+set hotpatch_tests $srcdir/$subdir/hotpatch-\[0-9\]*.c
+
 # Main loop.
-dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.\[cS\]]] \
-	"" $DEFAULT_CFLAGS
+dg-runtest [lsort [prune [glob -nocomplain $srcdir/$subdir/*.\[cS\]] \
+			 $hotpatch_tests]] "" $DEFAULT_CFLAGS
+
+# Additional hotpatch torture tests.
+torture-init
+set HOTPATCH_TEST_OPTS [list -Os -O0 -O1 -O2 -O3]
+set-torture-options $HOTPATCH_TEST_OPTS
+gcc-dg-runtest [lsort [glob -nocomplain $hotpatch_tests]] "" $DEFAULT_CFLAGS
+torture-finish
 
 # All done.
 dg-finish
-- 
2.3.0


[-- Attachment #3: hotpatch13-gcc49-0001-PR-66215-S390-Fix-placement-of-post-label-NOPs-with-.patch --]
[-- Type: text/x-diff, Size: 27283 bytes --]

From a4c503c2e6c4c7e3ae3cfdc37a66e24e850b0773 Mon Sep 17 00:00:00 2001
From: Dominik Vogt <vogt@linux.vnet.ibm.com>
Date: Fri, 22 May 2015 09:03:26 +0100
Subject: [PATCH] PR 66215: S390: Fix placement of post-label NOPs with
 -mhotpatch=.

---
 gcc/config/s390/s390.c                      | 28 +++++++++++++++++-----------
 gcc/testsuite/gcc.target/s390/hotpatch-1.c  |  2 +-
 gcc/testsuite/gcc.target/s390/hotpatch-10.c |  2 +-
 gcc/testsuite/gcc.target/s390/hotpatch-11.c |  2 +-
 gcc/testsuite/gcc.target/s390/hotpatch-12.c |  2 +-
 gcc/testsuite/gcc.target/s390/hotpatch-13.c |  3 +--
 gcc/testsuite/gcc.target/s390/hotpatch-14.c |  4 ++--
 gcc/testsuite/gcc.target/s390/hotpatch-15.c |  4 ++--
 gcc/testsuite/gcc.target/s390/hotpatch-16.c |  4 ++--
 gcc/testsuite/gcc.target/s390/hotpatch-17.c |  2 +-
 gcc/testsuite/gcc.target/s390/hotpatch-18.c |  2 +-
 gcc/testsuite/gcc.target/s390/hotpatch-19.c |  4 ++--
 gcc/testsuite/gcc.target/s390/hotpatch-2.c  |  4 ++--
 gcc/testsuite/gcc.target/s390/hotpatch-20.c |  2 +-
 gcc/testsuite/gcc.target/s390/hotpatch-21.c |  2 +-
 gcc/testsuite/gcc.target/s390/hotpatch-22.c |  2 +-
 gcc/testsuite/gcc.target/s390/hotpatch-23.c |  2 +-
 gcc/testsuite/gcc.target/s390/hotpatch-24.c |  2 +-
 gcc/testsuite/gcc.target/s390/hotpatch-25.c |  9 ++++-----
 gcc/testsuite/gcc.target/s390/hotpatch-26.c | 17 +++++++++++++++++
 gcc/testsuite/gcc.target/s390/hotpatch-27.c | 17 +++++++++++++++++
 gcc/testsuite/gcc.target/s390/hotpatch-28.c | 18 ++++++++++++++++++
 gcc/testsuite/gcc.target/s390/hotpatch-3.c  |  4 ++--
 gcc/testsuite/gcc.target/s390/hotpatch-4.c  |  4 ++--
 gcc/testsuite/gcc.target/s390/hotpatch-5.c  |  4 ++--
 gcc/testsuite/gcc.target/s390/hotpatch-6.c  |  4 ++--
 gcc/testsuite/gcc.target/s390/hotpatch-7.c  |  4 ++--
 gcc/testsuite/gcc.target/s390/hotpatch-8.c  |  4 ++--
 gcc/testsuite/gcc.target/s390/hotpatch-9.c  |  4 ++--
 gcc/testsuite/gcc.target/s390/s390.exp      | 13 +++++++++++--
 30 files changed, 120 insertions(+), 55 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/s390/hotpatch-26.c
 create mode 100644 gcc/testsuite/gcc.target/s390/hotpatch-27.c
 create mode 100644 gcc/testsuite/gcc.target/s390/hotpatch-28.c

diff --git a/gcc/config/s390/s390.c b/gcc/config/s390/s390.c
index 120f31c..8cae9ba 100644
--- a/gcc/config/s390/s390.c
+++ b/gcc/config/s390/s390.c
@@ -11454,31 +11454,37 @@ s390_reorg (void)
 
       /* Insert NOPs for hotpatching. */
       for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
-	{
-	  if (NOTE_P (insn) && NOTE_KIND (insn) == NOTE_INSN_FUNCTION_BEG)
-	    break;
-	}
-      gcc_assert (insn);
-      /* Output a series of NOPs after the NOTE_INSN_FUNCTION_BEG.  */
-      while (hw_after > 0)
+	/* Emit NOPs
+	    1. inside the area covered by debug information to allow setting
+	       breakpoints at the NOPs,
+	    2. before any insn which results in an asm instruction,
+	    3. before in-function labels to avoid jumping to the NOPs, for
+	       example as part of a loop,
+	    4. before any barrier in case the function is completely empty
+	       (__builtin_unreachable ()) and has neither internal labels nor
+	       active insns.
+	*/
+	if (active_insn_p (insn) || BARRIER_P (insn) || LABEL_P (insn))
+	  break;
+      /* Output a series of NOPs before the first active insn.  */
+      while (insn && hw_after > 0)
 	{
 	  if (hw_after >= 3 && TARGET_CPU_ZARCH)
 	    {
-	      insn = emit_insn_after (gen_nop_6_byte (), insn);
+	      emit_insn_before (gen_nop_6_byte (), insn);
 	      hw_after -= 3;
 	    }
 	  else if (hw_after >= 2)
 	    {
-	      insn = emit_insn_after (gen_nop_4_byte (), insn);
+	      emit_insn_before (gen_nop_4_byte (), insn);
 	      hw_after -= 2;
 	    }
 	  else
 	    {
-	      insn = emit_insn_after (gen_nop_2_byte (), insn);
+	      emit_insn_before (gen_nop_2_byte (), insn);
 	      hw_after -= 1;
 	    }
 	}
-      gcc_assert (hw_after == 0);
     }
 }
 
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-1.c b/gcc/testsuite/gcc.target/s390/hotpatch-1.c
index b14fa90..55088b8 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-1.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-1.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch" } */
+/* { dg-options "-mzarch" } */
 
 #include <stdio.h>
 
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-10.c b/gcc/testsuite/gcc.target/s390/hotpatch-10.c
index a990c4c..d2cb9a2 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-10.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-10.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=0,0" } */
+/* { dg-options "-mzarch -mhotpatch=0,0" } */
 
 #include <stdio.h>
 
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-11.c b/gcc/testsuite/gcc.target/s390/hotpatch-11.c
index 6f8a52b..cabb9d26 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-11.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-11.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=1,0" } */
+/* { dg-options "-mzarch -mhotpatch=1,0" } */
 
 #include <stdio.h>
 
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-12.c b/gcc/testsuite/gcc.target/s390/hotpatch-12.c
index b73ca90..fc9adc3 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-12.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-12.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=999,0" } */
+/* { dg-options "-mzarch -mhotpatch=999,0" } */
 
 #include <stdio.h>
 
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-13.c b/gcc/testsuite/gcc.target/s390/hotpatch-13.c
index 150667a..b25fbd3 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-13.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-13.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch" } */
+/* { dg-options "-mzarch" } */
 
 #include <stdio.h>
 
@@ -18,4 +18,3 @@ void hp1(void)
 /* { dg-final { scan-assembler-not "nop\t0" } } */
 /* { dg-final { scan-assembler-not "brcl\t0, 0" } } */
 /* { dg-final { scan-assembler "alignment for hotpatch" } } */
-/* { dg-final { scan-assembler-times "\.align\t8" 2 } } */
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-14.c b/gcc/testsuite/gcc.target/s390/hotpatch-14.c
index c5f118c..c387d6b 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-14.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-14.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch" } */
+/* { dg-options "-mzarch" } */
 
 #include <stdio.h>
 
@@ -13,7 +13,7 @@ void hp1(void)
 
 /* Check number of occurences of certain instructions.  */
 /* { dg-final { scan-assembler-not "pre-label NOPs" } } */
-/* { dg-final { scan-assembler "post-label.*(2 halfwords)" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(2 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*nop\t0" } } */
 /* { dg-final { scan-assembler-not "nopr\t%r7" } } */
 /* { dg-final { scan-assembler-times "nop\t0" 1 } } */
 /* { dg-final { scan-assembler-not "brcl\t0, 0" } } */
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-15.c b/gcc/testsuite/gcc.target/s390/hotpatch-15.c
index ef0fb74..410106b 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-15.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-15.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch" } */
+/* { dg-options "-mzarch" } */
 
 #include <stdio.h>
 
@@ -13,7 +13,7 @@ void hp1(void)
 
 /* Check number of occurences of certain instructions.  */
 /* { dg-final { scan-assembler "pre-label.*(1 halfwords)" } } */
-/* { dg-final { scan-assembler "post-label.*(2 halfwords)" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(2 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*nop\t0" } } */
 /* { dg-final { scan-assembler-times "nopr\t%r7" 1 } } */
 /* { dg-final { scan-assembler-times "nop\t0" 1 } } */
 /* { dg-final { scan-assembler-not "brcl\t0, 0" } } */
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-16.c b/gcc/testsuite/gcc.target/s390/hotpatch-16.c
index a34bf95..fa06fff 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-16.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-16.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=0,0" } */
+/* { dg-options "-mzarch -mhotpatch=0,0" } */
 
 #include <stdio.h>
 
@@ -13,7 +13,7 @@ void hp1(void)
 
 /* Check number of occurences of certain instructions.  */
 /* { dg-final { scan-assembler "pre-label.*(1 halfwords)" } } */
-/* { dg-final { scan-assembler "post-label.*(2 halfwords)" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(2 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*nop\t0" } } */
 /* { dg-final { scan-assembler-times "nopr\t%r7" 1 } } */
 /* { dg-final { scan-assembler-times "nop\t0" 1 } } */
 /* { dg-final { scan-assembler-not "brcl\t0, 0" } } */
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-17.c b/gcc/testsuite/gcc.target/s390/hotpatch-17.c
index 66ac725..3ef7d69 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-17.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-17.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=1,2" } */
+/* { dg-options "-mzarch -mhotpatch=1,2" } */
 
 #include <stdio.h>
 
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-18.c b/gcc/testsuite/gcc.target/s390/hotpatch-18.c
index 8b076a4..c93af7f 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-18.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-18.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=1,2 -mhotpatch=0,0" } */
+/* { dg-options "-mzarch -mhotpatch=1,2 -mhotpatch=0,0" } */
 
 #include <stdio.h>
 
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-19.c b/gcc/testsuite/gcc.target/s390/hotpatch-19.c
index 6993c7e..c69b35e 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-19.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-19.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=1,2" } */
+/* { dg-options "-mzarch -mhotpatch=1,2" } */
 
 #include <stdio.h>
 
@@ -19,7 +19,7 @@ void hp1(void)
 
 /* Check number of occurences of certain instructions.  */
 /* { dg-final { scan-assembler "pre-label.*(1 halfwords)" } } */
-/* { dg-final { scan-assembler "post-label.*(2 halfwords)" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(2 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*nop\t0" } } */
 /* { dg-final { scan-assembler-times "nopr\t%r7" 1 } } */
 /* { dg-final { scan-assembler-times "nop\t0" 1 } } */
 /* { dg-final { scan-assembler-not "brcl\t0, 0" } } */
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-2.c b/gcc/testsuite/gcc.target/s390/hotpatch-2.c
index 67189f8..2a2665e 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-2.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-2.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=0,1" } */
+/* { dg-options "-mzarch -mhotpatch=0,1" } */
 
 #include <stdio.h>
 
@@ -12,7 +12,7 @@ void hp1(void)
 
 /* Check number of occurences of certain instructions.  */
 /* { dg-final { scan-assembler-not "pre-label NOPs" } } */
-/* { dg-final { scan-assembler "post-label.*(1 halfwords)" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(1 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*nopr\t" } } */
 /* { dg-final { scan-assembler-times "nopr\t%r7" 1 } } */
 /* { dg-final { scan-assembler-not "nop\t0" } } */
 /* { dg-final { scan-assembler-not "brcl\t0, 0" } } */
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-20.c b/gcc/testsuite/gcc.target/s390/hotpatch-20.c
index 09ef5ca..0a32a68 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-20.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-20.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch" } */
+/* { dg-options "-mzarch" } */
 
 #include <stdio.h>
 
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-21.c b/gcc/testsuite/gcc.target/s390/hotpatch-21.c
index e909990..f6e9099 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-21.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-21.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=0,1" } */
+/* { dg-options "-mzarch -mhotpatch=0,1" } */
 
 #include <stdio.h>
 
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-22.c b/gcc/testsuite/gcc.target/s390/hotpatch-22.c
index d89d779..21f7d7e 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-22.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-22.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=0,1 -falign-functions=1024" } */
+/* { dg-options "-mzarch -mhotpatch=0,1 -falign-functions=1024" } */
 
 #include <stdio.h>
 
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-23.c b/gcc/testsuite/gcc.target/s390/hotpatch-23.c
index 1e05d12..6e149cc 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-23.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-23.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=0,1 -falign-functions=4096" } */
+/* { dg-options "-mzarch -mhotpatch=0,1 -falign-functions=4096" } */
 
 #include <stdio.h>
 
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-24.c b/gcc/testsuite/gcc.target/s390/hotpatch-24.c
index fc64274..1e47591 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-24.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-24.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=0,1 -falign-functions=2048" } */
+/* { dg-options "-mzarch -mhotpatch=0,1 -falign-functions=2048" } */
 
 #include <stdio.h>
 
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-25.c b/gcc/testsuite/gcc.target/s390/hotpatch-25.c
index e9257e3..e6cdbb6 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-25.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-25.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch" } */
+/* { dg-options "-mzarch" } */
 
 typedef long (*fn_t)(void);
 
@@ -25,9 +25,8 @@ fn_t outer(void)
 /* { dg-final { scan-assembler "pre-label.*(1 halfwords)" } } */
 /* { dg-final { scan-assembler "pre-label.*(4 halfwords)" } } */
 /* { dg-final { scan-assembler "pre-label.*(16 halfwords)" } } */
-/* { dg-final { scan-assembler "post-label.*(2 halfwords)" } } */
-/* { dg-final { scan-assembler "post-label.*(8 halfwords)" } } */
-/* { dg-final { scan-assembler "post-label.*(32 halfwords)" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(2 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*nopr\t" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(8 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*brcl\t0, 0" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(32 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*brcl\t0, 0" } } */
 /* { dg-final { scan-assembler-times "alignment for hotpatch" 3 } } */
-/* { dg-final { scan-assembler-times "\.align\t8" 6 } } */
 /* { dg-final { scan-assembler "nopr.*\n.*nopr.*\n.*nopr.*\n.*nopr.*\n.*nopr.*\n.*nopr.*\n.*nopr.*\n.*nopr.*\n.*nopr.*\n.*nopr.*\n.*nopr.*\n.*nopr.*\n.*nopr.*\n.*nopr.*\n.*nopr.*\n.*nopr" } } */
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-26.c b/gcc/testsuite/gcc.target/s390/hotpatch-26.c
new file mode 100644
index 0000000..eb95c26
--- /dev/null
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-26.c
@@ -0,0 +1,17 @@
+/* Functional tests for the function hotpatching feature.  */
+
+/* { dg-do compile } */
+/* { dg-options "-O3 -mzarch -mhotpatch=1,2" } */
+
+__attribute__ ((noreturn)) void hp1(void)
+{
+  __builtin_unreachable ();
+}
+
+/* Check number of occurences of certain instructions.  */
+/* { dg-final { scan-assembler "pre-label NOPs" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(2 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*nop\t0" } } */
+/* { dg-final { scan-assembler-times "nopr\t%r7" 1 } } */
+/* { dg-final { scan-assembler-times "nop\t0" 1 } } */
+/* { dg-final { scan-assembler-not "brcl\t0, 0" } } */
+/* { dg-final { scan-assembler "alignment for hotpatch" } } */
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-27.c b/gcc/testsuite/gcc.target/s390/hotpatch-27.c
new file mode 100644
index 0000000..cdbd4ca
--- /dev/null
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-27.c
@@ -0,0 +1,17 @@
+/* Functional tests for the function hotpatching feature.  */
+
+/* { dg-do compile } */
+/* { dg-options "-O3 -mzarch -mhotpatch=1,2" } */
+
+__attribute__ ((noreturn)) void hp3(void)
+{
+  __builtin_unreachable ();
+}
+
+/* Check number of occurences of certain instructions.  */
+/* { dg-final { scan-assembler "pre-label NOPs" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(2 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*nop\t0" } } */
+/* { dg-final { scan-assembler-times "nopr\t%r7" 1 } } */
+/* { dg-final { scan-assembler-times "nop\t0" 1 } } */
+/* { dg-final { scan-assembler-not "brcl\t0, 0" } } */
+/* { dg-final { scan-assembler "alignment for hotpatch" } } */
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-28.c b/gcc/testsuite/gcc.target/s390/hotpatch-28.c
new file mode 100644
index 0000000..9922daa
--- /dev/null
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-28.c
@@ -0,0 +1,18 @@
+/* Functional tests for the function hotpatching feature.  */
+
+/* { dg-do compile } */
+/* { dg-options "-O3 -mzarch -mhotpatch=1,2" } */
+
+void hp1 (volatile unsigned int *i)
+{
+  for (;;)
+    (*i)++;
+}
+
+/* Check number of occurences of certain instructions.  */
+/* { dg-final { scan-assembler "pre-label NOPs" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(2 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*nop\t0" } } */
+/* { dg-final { scan-assembler-times "nopr\t%r7" 1 } } */
+/* { dg-final { scan-assembler-times "nop\t0" 1 } } */
+/* { dg-final { scan-assembler-not "brcl\t0, 0" } } */
+/* { dg-final { scan-assembler "alignment for hotpatch" } } */
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-3.c b/gcc/testsuite/gcc.target/s390/hotpatch-3.c
index ec4a978..6718591 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-3.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-3.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=0,2" } */
+/* { dg-options "-mzarch -mhotpatch=0,2" } */
 
 #include <stdio.h>
 
@@ -12,7 +12,7 @@ void hp1(void)
 
 /* Check number of occurences of certain instructions.  */
 /* { dg-final { scan-assembler-not "pre-label NOPs" } } */
-/* { dg-final { scan-assembler "post-label.*(2 halfwords)" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(2 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*nop\t0" } } */
 /* { dg-final { scan-assembler-not "nopr\t%r7" } } */
 /* { dg-final { scan-assembler-times "nop\t0" 1 } } */
 /* { dg-final { scan-assembler-not "brcl\t0, 0" } } */
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-4.c b/gcc/testsuite/gcc.target/s390/hotpatch-4.c
index d55e71d..b770d4b 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-4.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-4.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=0,3" } */
+/* { dg-options "-mzarch -mhotpatch=0,3" } */
 
 #include <stdio.h>
 
@@ -12,7 +12,7 @@ void hp1(void)
 
 /* Check number of occurences of certain instructions.  */
 /* { dg-final { scan-assembler-not "pre-label NOPs" } } */
-/* { dg-final { scan-assembler "post-label.*(3 halfwords)" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(3 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*brcl\t0, 0" } } */
 /* { dg-final { scan-assembler-not "nopr\t%r7" } } */
 /* { dg-final { scan-assembler-not "nop\t0" } } */
 /* { dg-final { scan-assembler-times "brcl\t0, 0" 1 } } */
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-5.c b/gcc/testsuite/gcc.target/s390/hotpatch-5.c
index f77d83a..f1dcd89 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-5.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-5.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=0,4" } */
+/* { dg-options "-mzarch -mhotpatch=0,4" } */
 
 #include <stdio.h>
 
@@ -12,7 +12,7 @@ void hp1(void)
 
 /* Check number of occurences of certain instructions.  */
 /* { dg-final { scan-assembler-not "pre-label NOPs" } } */
-/* { dg-final { scan-assembler "post-label.*(4 halfwords)" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(4 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*brcl\t0, 0" } } */
 /* { dg-final { scan-assembler-times "nopr\t%r7" 1 } } */
 /* { dg-final { scan-assembler-not "nop\t0" } } */
 /* { dg-final { scan-assembler-times "brcl\t0, 0" 1 } } */
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-6.c b/gcc/testsuite/gcc.target/s390/hotpatch-6.c
index 330cf5d..6203a72b 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-6.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-6.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=0,5" } */
+/* { dg-options "-mzarch -mhotpatch=0,5" } */
 
 #include <stdio.h>
 
@@ -12,7 +12,7 @@ void hp1(void)
 
 /* Check number of occurences of certain instructions.  */
 /* { dg-final { scan-assembler-not "pre-label NOPs" } } */
-/* { dg-final { scan-assembler "post-label.*(5 halfwords)" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(5 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*brcl\t0, 0" } } */
 /* { dg-final { scan-assembler-not "nopr\t%r7" } } */
 /* { dg-final { scan-assembler-times "nop\t0" 1 } } */
 /* { dg-final { scan-assembler-times "brcl\t0, 0" 1 } } */
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-7.c b/gcc/testsuite/gcc.target/s390/hotpatch-7.c
index 2f24e3cc..e201ae9 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-7.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-7.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=0,6" } */
+/* { dg-options "-mzarch -mhotpatch=0,6" } */
 
 #include <stdio.h>
 
@@ -12,7 +12,7 @@ void hp1(void)
 
 /* Check number of occurences of certain instructions.  */
 /* { dg-final { scan-assembler-not "pre-label NOPs" } } */
-/* { dg-final { scan-assembler "post-label.*(6 halfwords)" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(6 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*brcl\t0, 0" } } */
 /* { dg-final { scan-assembler-not "nopr\t%r7" } } */
 /* { dg-final { scan-assembler-not "nop\t0" } } */
 /* { dg-final { scan-assembler-times "brcl\t0, 0" 2 } } */
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-8.c b/gcc/testsuite/gcc.target/s390/hotpatch-8.c
index 7b266bd..1ea3160 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-8.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-8.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile { target { ! lp64 } } } */
-/* { dg-options "-O3 -mesa -march=g5 -mhotpatch=0,3" } */
+/* { dg-options "-mesa -march=g5 -mhotpatch=0,3" } */
 
 #include <stdio.h>
 
@@ -12,7 +12,7 @@ void hp1(void)
 
 /* Check number of occurences of certain instructions.  */
 /* { dg-final { scan-assembler-not "pre-label NOPs" } } */
-/* { dg-final { scan-assembler "post-label.*(3 halfwords)" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(3 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*nop\t0" } } */
 /* { dg-final { scan-assembler-times "nopr\t%r7" 1 } } */
 /* { dg-final { scan-assembler-times "nop\t0" 1 } } */
 /* { dg-final { scan-assembler-not "brcl\t0, 0" } } */
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-9.c b/gcc/testsuite/gcc.target/s390/hotpatch-9.c
index c0ad319..e30f276 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-9.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-9.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile { target { ! lp64 } } } */
-/* { dg-options "-O3 -mesa -march=g5 -mhotpatch=0,4" } */
+/* { dg-options "-mesa -march=g5 -mhotpatch=0,4" } */
 
 #include <stdio.h>
 
@@ -12,7 +12,7 @@ void hp1(void)
 
 /* Check number of occurences of certain instructions.  */
 /* { dg-final { scan-assembler-not "pre-label NOPs" } } */
-/* { dg-final { scan-assembler "post-label.*(4 halfwords)" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(4 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*nop\t0" } } */
 /* { dg-final { scan-assembler-not "nopr\t%r7" } } */
 /* { dg-final { scan-assembler-times "nop\t0" 2 } } */
 /* { dg-final { scan-assembler-not "brcl\t0, 0" } } */
diff --git a/gcc/testsuite/gcc.target/s390/s390.exp b/gcc/testsuite/gcc.target/s390/s390.exp
index f2ba929..17f7bed 100644
--- a/gcc/testsuite/gcc.target/s390/s390.exp
+++ b/gcc/testsuite/gcc.target/s390/s390.exp
@@ -46,9 +46,18 @@ if ![info exists DEFAULT_CFLAGS] then {
 # Initialize `dg'.
 dg-init
 
+set hotpatch_tests $srcdir/$subdir/hotpatch-\[0-9\]*.c
+
 # Main loop.
-dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.\[cS\]]] \
-	"" $DEFAULT_CFLAGS
+dg-runtest [lsort [prune [glob -nocomplain $srcdir/$subdir/*.\[cS\]] \
+			 $hotpatch_tests]] "" $DEFAULT_CFLAGS
+
+# Additional hotpatch torture tests.
+torture-init
+set HOTPATCH_TEST_OPTS [list -Os -O0 -O1 -O2 -O3]
+set-torture-options $HOTPATCH_TEST_OPTS
+gcc-dg-runtest [lsort [glob -nocomplain $hotpatch_tests]] $DEFAULT_CFLAGS
+torture-finish
 
 # All done.
 dg-finish
-- 
2.3.0


[-- Attachment #4: hotpatch13-gcc48-0001-PR-66215-S390-Fix-placement-of-post-label-NOPs-with-.patch --]
[-- Type: text/x-diff, Size: 27283 bytes --]

From 3f112c572450f70c82e653989ef74c723e44c680 Mon Sep 17 00:00:00 2001
From: Dominik Vogt <vogt@linux.vnet.ibm.com>
Date: Fri, 22 May 2015 09:03:26 +0100
Subject: [PATCH] PR 66215: S390: Fix placement of post-label NOPs with
 -mhotpatch=.

---
 gcc/config/s390/s390.c                      | 28 +++++++++++++++++-----------
 gcc/testsuite/gcc.target/s390/hotpatch-1.c  |  2 +-
 gcc/testsuite/gcc.target/s390/hotpatch-10.c |  2 +-
 gcc/testsuite/gcc.target/s390/hotpatch-11.c |  2 +-
 gcc/testsuite/gcc.target/s390/hotpatch-12.c |  2 +-
 gcc/testsuite/gcc.target/s390/hotpatch-13.c |  3 +--
 gcc/testsuite/gcc.target/s390/hotpatch-14.c |  4 ++--
 gcc/testsuite/gcc.target/s390/hotpatch-15.c |  4 ++--
 gcc/testsuite/gcc.target/s390/hotpatch-16.c |  4 ++--
 gcc/testsuite/gcc.target/s390/hotpatch-17.c |  2 +-
 gcc/testsuite/gcc.target/s390/hotpatch-18.c |  2 +-
 gcc/testsuite/gcc.target/s390/hotpatch-19.c |  4 ++--
 gcc/testsuite/gcc.target/s390/hotpatch-2.c  |  4 ++--
 gcc/testsuite/gcc.target/s390/hotpatch-20.c |  2 +-
 gcc/testsuite/gcc.target/s390/hotpatch-21.c |  2 +-
 gcc/testsuite/gcc.target/s390/hotpatch-22.c |  2 +-
 gcc/testsuite/gcc.target/s390/hotpatch-23.c |  2 +-
 gcc/testsuite/gcc.target/s390/hotpatch-24.c |  2 +-
 gcc/testsuite/gcc.target/s390/hotpatch-25.c |  9 ++++-----
 gcc/testsuite/gcc.target/s390/hotpatch-26.c | 17 +++++++++++++++++
 gcc/testsuite/gcc.target/s390/hotpatch-27.c | 17 +++++++++++++++++
 gcc/testsuite/gcc.target/s390/hotpatch-28.c | 18 ++++++++++++++++++
 gcc/testsuite/gcc.target/s390/hotpatch-3.c  |  4 ++--
 gcc/testsuite/gcc.target/s390/hotpatch-4.c  |  4 ++--
 gcc/testsuite/gcc.target/s390/hotpatch-5.c  |  4 ++--
 gcc/testsuite/gcc.target/s390/hotpatch-6.c  |  4 ++--
 gcc/testsuite/gcc.target/s390/hotpatch-7.c  |  4 ++--
 gcc/testsuite/gcc.target/s390/hotpatch-8.c  |  4 ++--
 gcc/testsuite/gcc.target/s390/hotpatch-9.c  |  4 ++--
 gcc/testsuite/gcc.target/s390/s390.exp      | 13 +++++++++++--
 30 files changed, 120 insertions(+), 55 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/s390/hotpatch-26.c
 create mode 100644 gcc/testsuite/gcc.target/s390/hotpatch-27.c
 create mode 100644 gcc/testsuite/gcc.target/s390/hotpatch-28.c

diff --git a/gcc/config/s390/s390.c b/gcc/config/s390/s390.c
index a6b6a83..7452115 100644
--- a/gcc/config/s390/s390.c
+++ b/gcc/config/s390/s390.c
@@ -11267,31 +11267,37 @@ s390_reorg (void)
 
       /* Insert NOPs for hotpatching. */
       for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
-	{
-	  if (NOTE_P (insn) && NOTE_KIND (insn) == NOTE_INSN_FUNCTION_BEG)
-	    break;
-	}
-      gcc_assert (insn);
-      /* Output a series of NOPs after the NOTE_INSN_FUNCTION_BEG.  */
-      while (hw_after > 0)
+	/* Emit NOPs
+	    1. inside the area covered by debug information to allow setting
+	       breakpoints at the NOPs,
+	    2. before any insn which results in an asm instruction,
+	    3. before in-function labels to avoid jumping to the NOPs, for
+	       example as part of a loop,
+	    4. before any barrier in case the function is completely empty
+	       (__builtin_unreachable ()) and has neither internal labels nor
+	       active insns.
+	*/
+	if (active_insn_p (insn) || BARRIER_P (insn) || LABEL_P (insn))
+	  break;
+      /* Output a series of NOPs before the first active insn.  */
+      while (insn && hw_after > 0)
 	{
 	  if (hw_after >= 3 && TARGET_CPU_ZARCH)
 	    {
-	      insn = emit_insn_after (gen_nop_6_byte (), insn);
+	      emit_insn_before (gen_nop_6_byte (), insn);
 	      hw_after -= 3;
 	    }
 	  else if (hw_after >= 2)
 	    {
-	      insn = emit_insn_after (gen_nop_4_byte (), insn);
+	      emit_insn_before (gen_nop_4_byte (), insn);
 	      hw_after -= 2;
 	    }
 	  else
 	    {
-	      insn = emit_insn_after (gen_nop_2_byte (), insn);
+	      emit_insn_before (gen_nop_2_byte (), insn);
 	      hw_after -= 1;
 	    }
 	}
-      gcc_assert (hw_after == 0);
     }
 }
 
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-1.c b/gcc/testsuite/gcc.target/s390/hotpatch-1.c
index b14fa90..55088b8 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-1.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-1.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch" } */
+/* { dg-options "-mzarch" } */
 
 #include <stdio.h>
 
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-10.c b/gcc/testsuite/gcc.target/s390/hotpatch-10.c
index a990c4c..d2cb9a2 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-10.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-10.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=0,0" } */
+/* { dg-options "-mzarch -mhotpatch=0,0" } */
 
 #include <stdio.h>
 
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-11.c b/gcc/testsuite/gcc.target/s390/hotpatch-11.c
index 6f8a52b..cabb9d26 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-11.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-11.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=1,0" } */
+/* { dg-options "-mzarch -mhotpatch=1,0" } */
 
 #include <stdio.h>
 
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-12.c b/gcc/testsuite/gcc.target/s390/hotpatch-12.c
index b73ca90..fc9adc3 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-12.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-12.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=999,0" } */
+/* { dg-options "-mzarch -mhotpatch=999,0" } */
 
 #include <stdio.h>
 
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-13.c b/gcc/testsuite/gcc.target/s390/hotpatch-13.c
index 150667a..b25fbd3 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-13.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-13.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch" } */
+/* { dg-options "-mzarch" } */
 
 #include <stdio.h>
 
@@ -18,4 +18,3 @@ void hp1(void)
 /* { dg-final { scan-assembler-not "nop\t0" } } */
 /* { dg-final { scan-assembler-not "brcl\t0, 0" } } */
 /* { dg-final { scan-assembler "alignment for hotpatch" } } */
-/* { dg-final { scan-assembler-times "\.align\t8" 2 } } */
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-14.c b/gcc/testsuite/gcc.target/s390/hotpatch-14.c
index c5f118c..c387d6b 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-14.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-14.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch" } */
+/* { dg-options "-mzarch" } */
 
 #include <stdio.h>
 
@@ -13,7 +13,7 @@ void hp1(void)
 
 /* Check number of occurences of certain instructions.  */
 /* { dg-final { scan-assembler-not "pre-label NOPs" } } */
-/* { dg-final { scan-assembler "post-label.*(2 halfwords)" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(2 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*nop\t0" } } */
 /* { dg-final { scan-assembler-not "nopr\t%r7" } } */
 /* { dg-final { scan-assembler-times "nop\t0" 1 } } */
 /* { dg-final { scan-assembler-not "brcl\t0, 0" } } */
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-15.c b/gcc/testsuite/gcc.target/s390/hotpatch-15.c
index ef0fb74..410106b 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-15.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-15.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch" } */
+/* { dg-options "-mzarch" } */
 
 #include <stdio.h>
 
@@ -13,7 +13,7 @@ void hp1(void)
 
 /* Check number of occurences of certain instructions.  */
 /* { dg-final { scan-assembler "pre-label.*(1 halfwords)" } } */
-/* { dg-final { scan-assembler "post-label.*(2 halfwords)" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(2 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*nop\t0" } } */
 /* { dg-final { scan-assembler-times "nopr\t%r7" 1 } } */
 /* { dg-final { scan-assembler-times "nop\t0" 1 } } */
 /* { dg-final { scan-assembler-not "brcl\t0, 0" } } */
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-16.c b/gcc/testsuite/gcc.target/s390/hotpatch-16.c
index a34bf95..fa06fff 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-16.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-16.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=0,0" } */
+/* { dg-options "-mzarch -mhotpatch=0,0" } */
 
 #include <stdio.h>
 
@@ -13,7 +13,7 @@ void hp1(void)
 
 /* Check number of occurences of certain instructions.  */
 /* { dg-final { scan-assembler "pre-label.*(1 halfwords)" } } */
-/* { dg-final { scan-assembler "post-label.*(2 halfwords)" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(2 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*nop\t0" } } */
 /* { dg-final { scan-assembler-times "nopr\t%r7" 1 } } */
 /* { dg-final { scan-assembler-times "nop\t0" 1 } } */
 /* { dg-final { scan-assembler-not "brcl\t0, 0" } } */
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-17.c b/gcc/testsuite/gcc.target/s390/hotpatch-17.c
index 66ac725..3ef7d69 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-17.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-17.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=1,2" } */
+/* { dg-options "-mzarch -mhotpatch=1,2" } */
 
 #include <stdio.h>
 
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-18.c b/gcc/testsuite/gcc.target/s390/hotpatch-18.c
index 8b076a4..c93af7f 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-18.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-18.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=1,2 -mhotpatch=0,0" } */
+/* { dg-options "-mzarch -mhotpatch=1,2 -mhotpatch=0,0" } */
 
 #include <stdio.h>
 
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-19.c b/gcc/testsuite/gcc.target/s390/hotpatch-19.c
index 6993c7e..c69b35e 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-19.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-19.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=1,2" } */
+/* { dg-options "-mzarch -mhotpatch=1,2" } */
 
 #include <stdio.h>
 
@@ -19,7 +19,7 @@ void hp1(void)
 
 /* Check number of occurences of certain instructions.  */
 /* { dg-final { scan-assembler "pre-label.*(1 halfwords)" } } */
-/* { dg-final { scan-assembler "post-label.*(2 halfwords)" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(2 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*nop\t0" } } */
 /* { dg-final { scan-assembler-times "nopr\t%r7" 1 } } */
 /* { dg-final { scan-assembler-times "nop\t0" 1 } } */
 /* { dg-final { scan-assembler-not "brcl\t0, 0" } } */
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-2.c b/gcc/testsuite/gcc.target/s390/hotpatch-2.c
index 67189f8..2a2665e 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-2.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-2.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=0,1" } */
+/* { dg-options "-mzarch -mhotpatch=0,1" } */
 
 #include <stdio.h>
 
@@ -12,7 +12,7 @@ void hp1(void)
 
 /* Check number of occurences of certain instructions.  */
 /* { dg-final { scan-assembler-not "pre-label NOPs" } } */
-/* { dg-final { scan-assembler "post-label.*(1 halfwords)" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(1 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*nopr\t" } } */
 /* { dg-final { scan-assembler-times "nopr\t%r7" 1 } } */
 /* { dg-final { scan-assembler-not "nop\t0" } } */
 /* { dg-final { scan-assembler-not "brcl\t0, 0" } } */
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-20.c b/gcc/testsuite/gcc.target/s390/hotpatch-20.c
index 09ef5ca..0a32a68 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-20.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-20.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch" } */
+/* { dg-options "-mzarch" } */
 
 #include <stdio.h>
 
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-21.c b/gcc/testsuite/gcc.target/s390/hotpatch-21.c
index e909990..f6e9099 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-21.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-21.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=0,1" } */
+/* { dg-options "-mzarch -mhotpatch=0,1" } */
 
 #include <stdio.h>
 
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-22.c b/gcc/testsuite/gcc.target/s390/hotpatch-22.c
index d89d779..21f7d7e 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-22.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-22.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=0,1 -falign-functions=1024" } */
+/* { dg-options "-mzarch -mhotpatch=0,1 -falign-functions=1024" } */
 
 #include <stdio.h>
 
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-23.c b/gcc/testsuite/gcc.target/s390/hotpatch-23.c
index 1e05d12..6e149cc 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-23.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-23.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=0,1 -falign-functions=4096" } */
+/* { dg-options "-mzarch -mhotpatch=0,1 -falign-functions=4096" } */
 
 #include <stdio.h>
 
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-24.c b/gcc/testsuite/gcc.target/s390/hotpatch-24.c
index fc64274..1e47591 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-24.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-24.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=0,1 -falign-functions=2048" } */
+/* { dg-options "-mzarch -mhotpatch=0,1 -falign-functions=2048" } */
 
 #include <stdio.h>
 
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-25.c b/gcc/testsuite/gcc.target/s390/hotpatch-25.c
index e9257e3..e6cdbb6 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-25.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-25.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch" } */
+/* { dg-options "-mzarch" } */
 
 typedef long (*fn_t)(void);
 
@@ -25,9 +25,8 @@ fn_t outer(void)
 /* { dg-final { scan-assembler "pre-label.*(1 halfwords)" } } */
 /* { dg-final { scan-assembler "pre-label.*(4 halfwords)" } } */
 /* { dg-final { scan-assembler "pre-label.*(16 halfwords)" } } */
-/* { dg-final { scan-assembler "post-label.*(2 halfwords)" } } */
-/* { dg-final { scan-assembler "post-label.*(8 halfwords)" } } */
-/* { dg-final { scan-assembler "post-label.*(32 halfwords)" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(2 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*nopr\t" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(8 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*brcl\t0, 0" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(32 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*brcl\t0, 0" } } */
 /* { dg-final { scan-assembler-times "alignment for hotpatch" 3 } } */
-/* { dg-final { scan-assembler-times "\.align\t8" 6 } } */
 /* { dg-final { scan-assembler "nopr.*\n.*nopr.*\n.*nopr.*\n.*nopr.*\n.*nopr.*\n.*nopr.*\n.*nopr.*\n.*nopr.*\n.*nopr.*\n.*nopr.*\n.*nopr.*\n.*nopr.*\n.*nopr.*\n.*nopr.*\n.*nopr.*\n.*nopr" } } */
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-26.c b/gcc/testsuite/gcc.target/s390/hotpatch-26.c
new file mode 100644
index 0000000..eb95c26
--- /dev/null
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-26.c
@@ -0,0 +1,17 @@
+/* Functional tests for the function hotpatching feature.  */
+
+/* { dg-do compile } */
+/* { dg-options "-O3 -mzarch -mhotpatch=1,2" } */
+
+__attribute__ ((noreturn)) void hp1(void)
+{
+  __builtin_unreachable ();
+}
+
+/* Check number of occurences of certain instructions.  */
+/* { dg-final { scan-assembler "pre-label NOPs" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(2 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*nop\t0" } } */
+/* { dg-final { scan-assembler-times "nopr\t%r7" 1 } } */
+/* { dg-final { scan-assembler-times "nop\t0" 1 } } */
+/* { dg-final { scan-assembler-not "brcl\t0, 0" } } */
+/* { dg-final { scan-assembler "alignment for hotpatch" } } */
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-27.c b/gcc/testsuite/gcc.target/s390/hotpatch-27.c
new file mode 100644
index 0000000..cdbd4ca
--- /dev/null
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-27.c
@@ -0,0 +1,17 @@
+/* Functional tests for the function hotpatching feature.  */
+
+/* { dg-do compile } */
+/* { dg-options "-O3 -mzarch -mhotpatch=1,2" } */
+
+__attribute__ ((noreturn)) void hp3(void)
+{
+  __builtin_unreachable ();
+}
+
+/* Check number of occurences of certain instructions.  */
+/* { dg-final { scan-assembler "pre-label NOPs" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(2 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*nop\t0" } } */
+/* { dg-final { scan-assembler-times "nopr\t%r7" 1 } } */
+/* { dg-final { scan-assembler-times "nop\t0" 1 } } */
+/* { dg-final { scan-assembler-not "brcl\t0, 0" } } */
+/* { dg-final { scan-assembler "alignment for hotpatch" } } */
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-28.c b/gcc/testsuite/gcc.target/s390/hotpatch-28.c
new file mode 100644
index 0000000..9922daa
--- /dev/null
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-28.c
@@ -0,0 +1,18 @@
+/* Functional tests for the function hotpatching feature.  */
+
+/* { dg-do compile } */
+/* { dg-options "-O3 -mzarch -mhotpatch=1,2" } */
+
+void hp1 (volatile unsigned int *i)
+{
+  for (;;)
+    (*i)++;
+}
+
+/* Check number of occurences of certain instructions.  */
+/* { dg-final { scan-assembler "pre-label NOPs" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(2 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*nop\t0" } } */
+/* { dg-final { scan-assembler-times "nopr\t%r7" 1 } } */
+/* { dg-final { scan-assembler-times "nop\t0" 1 } } */
+/* { dg-final { scan-assembler-not "brcl\t0, 0" } } */
+/* { dg-final { scan-assembler "alignment for hotpatch" } } */
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-3.c b/gcc/testsuite/gcc.target/s390/hotpatch-3.c
index ec4a978..6718591 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-3.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-3.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=0,2" } */
+/* { dg-options "-mzarch -mhotpatch=0,2" } */
 
 #include <stdio.h>
 
@@ -12,7 +12,7 @@ void hp1(void)
 
 /* Check number of occurences of certain instructions.  */
 /* { dg-final { scan-assembler-not "pre-label NOPs" } } */
-/* { dg-final { scan-assembler "post-label.*(2 halfwords)" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(2 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*nop\t0" } } */
 /* { dg-final { scan-assembler-not "nopr\t%r7" } } */
 /* { dg-final { scan-assembler-times "nop\t0" 1 } } */
 /* { dg-final { scan-assembler-not "brcl\t0, 0" } } */
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-4.c b/gcc/testsuite/gcc.target/s390/hotpatch-4.c
index d55e71d..b770d4b 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-4.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-4.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=0,3" } */
+/* { dg-options "-mzarch -mhotpatch=0,3" } */
 
 #include <stdio.h>
 
@@ -12,7 +12,7 @@ void hp1(void)
 
 /* Check number of occurences of certain instructions.  */
 /* { dg-final { scan-assembler-not "pre-label NOPs" } } */
-/* { dg-final { scan-assembler "post-label.*(3 halfwords)" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(3 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*brcl\t0, 0" } } */
 /* { dg-final { scan-assembler-not "nopr\t%r7" } } */
 /* { dg-final { scan-assembler-not "nop\t0" } } */
 /* { dg-final { scan-assembler-times "brcl\t0, 0" 1 } } */
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-5.c b/gcc/testsuite/gcc.target/s390/hotpatch-5.c
index f77d83a..f1dcd89 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-5.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-5.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=0,4" } */
+/* { dg-options "-mzarch -mhotpatch=0,4" } */
 
 #include <stdio.h>
 
@@ -12,7 +12,7 @@ void hp1(void)
 
 /* Check number of occurences of certain instructions.  */
 /* { dg-final { scan-assembler-not "pre-label NOPs" } } */
-/* { dg-final { scan-assembler "post-label.*(4 halfwords)" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(4 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*brcl\t0, 0" } } */
 /* { dg-final { scan-assembler-times "nopr\t%r7" 1 } } */
 /* { dg-final { scan-assembler-not "nop\t0" } } */
 /* { dg-final { scan-assembler-times "brcl\t0, 0" 1 } } */
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-6.c b/gcc/testsuite/gcc.target/s390/hotpatch-6.c
index 330cf5d..6203a72b 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-6.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-6.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=0,5" } */
+/* { dg-options "-mzarch -mhotpatch=0,5" } */
 
 #include <stdio.h>
 
@@ -12,7 +12,7 @@ void hp1(void)
 
 /* Check number of occurences of certain instructions.  */
 /* { dg-final { scan-assembler-not "pre-label NOPs" } } */
-/* { dg-final { scan-assembler "post-label.*(5 halfwords)" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(5 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*brcl\t0, 0" } } */
 /* { dg-final { scan-assembler-not "nopr\t%r7" } } */
 /* { dg-final { scan-assembler-times "nop\t0" 1 } } */
 /* { dg-final { scan-assembler-times "brcl\t0, 0" 1 } } */
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-7.c b/gcc/testsuite/gcc.target/s390/hotpatch-7.c
index 2f24e3cc..e201ae9 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-7.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-7.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -mhotpatch=0,6" } */
+/* { dg-options "-mzarch -mhotpatch=0,6" } */
 
 #include <stdio.h>
 
@@ -12,7 +12,7 @@ void hp1(void)
 
 /* Check number of occurences of certain instructions.  */
 /* { dg-final { scan-assembler-not "pre-label NOPs" } } */
-/* { dg-final { scan-assembler "post-label.*(6 halfwords)" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(6 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*brcl\t0, 0" } } */
 /* { dg-final { scan-assembler-not "nopr\t%r7" } } */
 /* { dg-final { scan-assembler-not "nop\t0" } } */
 /* { dg-final { scan-assembler-times "brcl\t0, 0" 2 } } */
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-8.c b/gcc/testsuite/gcc.target/s390/hotpatch-8.c
index 7b266bd..1ea3160 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-8.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-8.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile { target { ! lp64 } } } */
-/* { dg-options "-O3 -mesa -march=g5 -mhotpatch=0,3" } */
+/* { dg-options "-mesa -march=g5 -mhotpatch=0,3" } */
 
 #include <stdio.h>
 
@@ -12,7 +12,7 @@ void hp1(void)
 
 /* Check number of occurences of certain instructions.  */
 /* { dg-final { scan-assembler-not "pre-label NOPs" } } */
-/* { dg-final { scan-assembler "post-label.*(3 halfwords)" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(3 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*nop\t0" } } */
 /* { dg-final { scan-assembler-times "nopr\t%r7" 1 } } */
 /* { dg-final { scan-assembler-times "nop\t0" 1 } } */
 /* { dg-final { scan-assembler-not "brcl\t0, 0" } } */
diff --git a/gcc/testsuite/gcc.target/s390/hotpatch-9.c b/gcc/testsuite/gcc.target/s390/hotpatch-9.c
index c0ad319..e30f276 100644
--- a/gcc/testsuite/gcc.target/s390/hotpatch-9.c
+++ b/gcc/testsuite/gcc.target/s390/hotpatch-9.c
@@ -1,7 +1,7 @@
 /* Functional tests for the function hotpatching feature.  */
 
 /* { dg-do compile { target { ! lp64 } } } */
-/* { dg-options "-O3 -mesa -march=g5 -mhotpatch=0,4" } */
+/* { dg-options "-mesa -march=g5 -mhotpatch=0,4" } */
 
 #include <stdio.h>
 
@@ -12,7 +12,7 @@ void hp1(void)
 
 /* Check number of occurences of certain instructions.  */
 /* { dg-final { scan-assembler-not "pre-label NOPs" } } */
-/* { dg-final { scan-assembler "post-label.*(4 halfwords)" } } */
+/* { dg-final { scan-assembler "^\[^.\].*:\n.*post-label.*(4 halfwords).*\n\(\(.L.*:\n\)\|\(\[\[:space:\]\]*.cfi_.*\n\)\)*\[\[:space:\]\]*nop\t0" } } */
 /* { dg-final { scan-assembler-not "nopr\t%r7" } } */
 /* { dg-final { scan-assembler-times "nop\t0" 2 } } */
 /* { dg-final { scan-assembler-not "brcl\t0, 0" } } */
diff --git a/gcc/testsuite/gcc.target/s390/s390.exp b/gcc/testsuite/gcc.target/s390/s390.exp
index 141c0ee..a984064 100644
--- a/gcc/testsuite/gcc.target/s390/s390.exp
+++ b/gcc/testsuite/gcc.target/s390/s390.exp
@@ -46,9 +46,18 @@ if ![info exists DEFAULT_CFLAGS] then {
 # Initialize `dg'.
 dg-init
 
+set hotpatch_tests $srcdir/$subdir/hotpatch-\[0-9\]*.c
+
 # Main loop.
-dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.\[cS\]]] \
-	"" $DEFAULT_CFLAGS
+dg-runtest [lsort [prune [glob -nocomplain $srcdir/$subdir/*.\[cS\]] \
+			 $hotpatch_tests]] "" $DEFAULT_CFLAGS
+
+# Additional hotpatch torture tests.
+torture-init
+set HOTPATCH_TEST_OPTS [list -Os -O0 -O1 -O2 -O3]
+set-torture-options $HOTPATCH_TEST_OPTS
+gcc-dg-runtest [lsort [glob -nocomplain $hotpatch_tests]] $DEFAULT_CFLAGS
+torture-finish
 
 # All done.
 dg-finish
-- 
2.3.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-06-01  8:33 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-29 11:52 [PATCH] PR 66215: S390: Fix placement of post-label NOPs with -mhotpatch Dominik Vogt
2015-05-29 12:35 ` Jakub Jelinek
2015-05-29 15:18   ` Dominik Vogt
2015-05-29 15:28     ` Andreas Krebbel
2015-06-01  8:33     ` Dominik Vogt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).