diff mbox

Run tests only if the machine supports the instruction set.

Message ID 20161219142806.GA23636@linux.vnet.ibm.com
State New
Headers show

Commit Message

Dominik Vogt Dec. 19, 2016, 2:28 p.m. UTC
The attached patch is specific to S/390 but contains a small
common code change in gcc-dg.exp.  It fixes the notorious problem
of md tests running on an S/390 machine that does not support the
z13 instruction set.

Bootstrapped and tested on s390x biarch.

Ciao

Dominik ^_^  ^_^
diff mbox

Patch

diff --git a/gcc/config/s390/s390-c.c b/gcc/config/s390/s390-c.c
index fcf7477..8a9ea79 100644
--- a/gcc/config/s390/s390-c.c
+++ b/gcc/config/s390/s390-c.c
@@ -328,6 +328,21 @@  s390_cpu_cpp_builtins_internal (cpp_reader *pfile,
   s390_def_or_undef_macro (pfile, MASK_ZVECTOR, old_opts, opts,
 			   "__bool=__attribute__((s390_vector_bool)) unsigned",
 			   "__bool");
+  {
+    char macro_def[64];
+    int arch_level;
+    gcc_assert (s390_arch != PROCESSOR_NATIVE);
+    arch_level = (int)s390_arch + 3;
+    if (s390_arch >= PROCESSOR_2094_Z9_EC)
+      /* Z9_EC has the same level as Z9_109.  */
+      arch_level--;
+    /* Review when a new arch is added and increase the value.  */
+    char dummy[23 - 2 * PROCESSOR_max] __attribute__((unused));
+    sprintf (macro_def, "__s390_arch_level__=%d", arch_level);
+    cpp_undef (pfile, "__s390_arch_level__");
+    cpp_define (pfile, macro_def);
+  }
+
   if (!flag_iso)
     {
       s390_def_or_undef_macro (pfile, MASK_ZVECTOR, old_opts, opts,
diff --git a/gcc/testsuite/gcc.target/s390/md/andc-splitter-1.c b/gcc/testsuite/gcc.target/s390/md/andc-splitter-1.c
index ed78921..9c41ac4 100644
--- a/gcc/testsuite/gcc.target/s390/md/andc-splitter-1.c
+++ b/gcc/testsuite/gcc.target/s390/md/andc-splitter-1.c
@@ -1,7 +1,8 @@ 
 /* Machine description pattern tests.  */
 
-/* { dg-do run { target { lp64 } } } */
+/* { dg-do compile { target { lp64 } } } */
 /* { dg-options "-mzarch -save-temps -dP" } */
+/* { dg-do run { target { lp64 && runnable } } } */
 /* Skip test if -O0 is present on the command line:
 
     { dg-skip-if "" { *-*-* } { "-O0" } { "" } }
@@ -13,26 +14,26 @@ 
 __attribute__ ((noinline))
 unsigned long andc_vv(unsigned long a, unsigned long b)
 { return ~b & a; }
-/* { dg-final { scan-assembler ":15 .\* \{\\*anddi3\}" } } */
-/* { dg-final { scan-assembler ":15 .\* \{\\*xordi3\}" } } */
+/* { dg-final { scan-assembler ":16 .\* \{\\*anddi3\}" } } */
+/* { dg-final { scan-assembler ":16 .\* \{\\*xordi3\}" } } */
 
 __attribute__ ((noinline))
 unsigned long andc_pv(unsigned long *a, unsigned long b)
 { return ~b & *a; }
-/* { dg-final { scan-assembler ":21 .\* \{\\*anddi3\}" } } */
-/* { dg-final { scan-assembler ":21 .\* \{\\*xordi3\}" } } */
+/* { dg-final { scan-assembler ":22 .\* \{\\*anddi3\}" } } */
+/* { dg-final { scan-assembler ":22 .\* \{\\*xordi3\}" } } */
 
 __attribute__ ((noinline))
 unsigned long andc_vp(unsigned long a, unsigned long *b)
 { return ~*b & a; }
-/* { dg-final { scan-assembler ":27 .\* \{\\*anddi3\}" } } */
-/* { dg-final { scan-assembler ":27 .\* \{\\*xordi3\}" } } */
+/* { dg-final { scan-assembler ":28 .\* \{\\*anddi3\}" } } */
+/* { dg-final { scan-assembler ":28 .\* \{\\*xordi3\}" } } */
 
 __attribute__ ((noinline))
 unsigned long andc_pp(unsigned long *a, unsigned long *b)
 { return ~*b & *a; }
-/* { dg-final { scan-assembler ":33 .\* \{\\*anddi3\}" } } */
-/* { dg-final { scan-assembler ":33 .\* \{\\*xordi3\}" } } */
+/* { dg-final { scan-assembler ":34 .\* \{\\*anddi3\}" } } */
+/* { dg-final { scan-assembler ":34 .\* \{\\*xordi3\}" } } */
 
 /* { dg-final { scan-assembler-times "\tngr\?k\?\t" 4 } } */
 /* { dg-final { scan-assembler-times "\txgr\?\t" 4 } } */
diff --git a/gcc/testsuite/gcc.target/s390/md/andc-splitter-2.c b/gcc/testsuite/gcc.target/s390/md/andc-splitter-2.c
index d88da4d..3d4170a 100644
--- a/gcc/testsuite/gcc.target/s390/md/andc-splitter-2.c
+++ b/gcc/testsuite/gcc.target/s390/md/andc-splitter-2.c
@@ -1,7 +1,8 @@ 
 /* Machine description pattern tests.  */
 
-/* { dg-do run } */
+/* { dg-do compile } */
 /* { dg-options "-save-temps -dP" } */
+/* { dg-do run { target { runnable } } } */
 /* Skip test if -O0 is present on the command line:
 
     { dg-skip-if "" { *-*-* } { "-O0" } { "" } }
@@ -13,26 +14,26 @@ 
 __attribute__ ((noinline))
 unsigned int andc_vv(unsigned int a, unsigned int b)
 { return ~b & a; }
-/* { dg-final { scan-assembler ":15 .\* \{\\*andsi3_\(esa\|zarch\)\}" } } */
-/* { dg-final { scan-assembler ":15 .\* \{\\*xorsi3\}" } } */
+/* { dg-final { scan-assembler ":16 .\* \{\\*andsi3_\(esa\|zarch\)\}" } } */
+/* { dg-final { scan-assembler ":16 .\* \{\\*xorsi3\}" } } */
 
 __attribute__ ((noinline))
 unsigned int andc_pv(unsigned int *a, unsigned int b)
 { return ~b & *a; }
-/* { dg-final { scan-assembler ":21 .\* \{\\*andsi3_\(esa\|zarch\)\}" } } */
-/* { dg-final { scan-assembler ":21 .\* \{\\*xorsi3\}" } } */
+/* { dg-final { scan-assembler ":22 .\* \{\\*andsi3_\(esa\|zarch\)\}" } } */
+/* { dg-final { scan-assembler ":22 .\* \{\\*xorsi3\}" } } */
 
 __attribute__ ((noinline))
 unsigned int andc_vp(unsigned int a, unsigned int *b)
 { return ~*b & a; }
-/* { dg-final { scan-assembler ":27 .\* \{\\*andsi3_\(esa\|zarch\)\}" } } */
-/* { dg-final { scan-assembler ":27 .\* \{\\*xorsi3\}" } } */
+/* { dg-final { scan-assembler ":28 .\* \{\\*andsi3_\(esa\|zarch\)\}" } } */
+/* { dg-final { scan-assembler ":28 .\* \{\\*xorsi3\}" } } */
 
 __attribute__ ((noinline))
 unsigned int andc_pp(unsigned int *a, unsigned int *b)
 { return ~*b & *a; }
-/* { dg-final { scan-assembler ":33 .\* \{\\*andsi3_\(esa\|zarch\)\}" } } */
-/* { dg-final { scan-assembler ":33 .\* \{\\*xorsi3\}" } } */
+/* { dg-final { scan-assembler ":34 .\* \{\\*andsi3_\(esa\|zarch\)\}" } } */
+/* { dg-final { scan-assembler ":34 .\* \{\\*xorsi3\}" } } */
 
 /* { dg-final { scan-assembler-times "\tnr\?k\?\t" 4 } } */
 /* { dg-final { scan-assembler-times "\txr\?k\?\t" 4 } } */
diff --git a/gcc/testsuite/gcc.target/s390/md/rXsbg_mode_sXl.c b/gcc/testsuite/gcc.target/s390/md/rXsbg_mode_sXl.c
index ad442da..3a61e60 100644
--- a/gcc/testsuite/gcc.target/s390/md/rXsbg_mode_sXl.c
+++ b/gcc/testsuite/gcc.target/s390/md/rXsbg_mode_sXl.c
@@ -7,8 +7,8 @@ 
    always wins, even if the condition is false.  If this test is run on hardware
    older than z10 with a buggy dejagnu release, the execution part will fail.
 
-    { dg-do assemble { target { ! z10_instructions } } }
-    { dg-do run { target { z10_instructions } } }
+    { dg-do assemble }
+    { dg-do run { target { runnable } } }
 
    Skip test if -O0, -march=z900, -march=z9-109 or -march=z9-ec is present on
    the command line:
diff --git a/gcc/testsuite/gcc.target/s390/md/setmem_long-1.c b/gcc/testsuite/gcc.target/s390/md/setmem_long-1.c
index bd0c594..ceb9244 100644
--- a/gcc/testsuite/gcc.target/s390/md/setmem_long-1.c
+++ b/gcc/testsuite/gcc.target/s390/md/setmem_long-1.c
@@ -1,7 +1,8 @@ 
 /* Machine description pattern tests.  */
 
-/* { dg-do run } */
+/* { dg-do compile } */
 /* { dg-options "-mmvcle -dP -save-temps" } */
+/* { dg-do run { target { runnable } } } */
 
 __attribute__ ((noinline))
 void test(char *p, char c, int len)
@@ -16,8 +17,8 @@  void test2(char *p, int c, int len)
 }
 
 /* Check that the right patterns are used.  */
-/* { dg-final { scan-assembler-times {c"?:9 .*{[*]setmem_long_?3?1?z?}} 1 } } */
-/* { dg-final { scan-assembler-times {c"?:15 .*{[*]setmem_long_and_?3?1?z?}} 1 { xfail *-*-* } } } */
+/* { dg-final { scan-assembler-times {c"?:10 .*{[*]setmem_long_?3?1?z?}} 1 } } */
+/* { dg-final { scan-assembler-times {c"?:16 .*{[*]setmem_long_and_?3?1?z?}} 1 { xfail *-*-* } } } */
 
 #define LEN 500
 char buf[LEN + 2];
diff --git a/gcc/testsuite/gcc.target/s390/s390.exp b/gcc/testsuite/gcc.target/s390/s390.exp
index 450dcaf..719dad6 100644
--- a/gcc/testsuite/gcc.target/s390/s390.exp
+++ b/gcc/testsuite/gcc.target/s390/s390.exp
@@ -16,6 +16,9 @@ 
 
 # GCC testsuite that uses the `dg.exp' driver.
 
+global torture_current_flags
+set torture_current_flags ""
+
 # Exit immediately if this isn't a s390 target.
 if ![istarget s390*-*-*] then {
   return
@@ -24,17 +27,6 @@  if ![istarget s390*-*-*] then {
 # Load support procs.
 load_lib gcc-dg.exp
 
-# Return 1 if z10 instructions work.
-proc check_effective_target_z10_instructions { } {
-    if { ![check_runtime s390_check_z10_instructions [subst {
-	int main (void)
-	{
-	    asm ("rosbg %%r2,%%r2,0,0,0" : : );
-	    return 0;
-	}
-    }] "-march=z10 -mzarch" ] } { return 0 } else { return 1 }
-}
-
 # Return 1 if the the assembler understands .machine and .machinemode.  The
 # target attribute needs that feature to work.
 proc check_effective_target_target_attribute { } {
@@ -78,6 +70,42 @@  proc check_effective_target_vector { } {
     }] "-march=z13 -mzarch" ] } { return 0 } else { return 1 }
 }
 
+# Return 1 if a program using the full instruction set allowed by
+# the compiler option can be executed.
+proc check_effective_target_runnable { } {
+    global torture_current_flags
+    if { ![check_runtime_nocache s390_check_runnable [subst {
+	int main (void)
+	{
+	#if __s390_arch_level__ >= 11
+	    asm ("lcbb %%r2,0(%%r15),0" : : );
+	#elif __s390_arch_level__ >= 10
+	    asm ("risbgn %%r2,%%r2,0,0,0" : : );
+	#elif __s390_arch_level__ >= 9
+	    asm ("sgrk %%r2,%%r2,%%r2" : : );
+	#elif __s390_arch_level__ >= 8
+	    asm ("rosbg %%r2,%%r2,0,0,0" : : );
+	#elif __s390_arch_level__ >= 7
+	    asm ("nilf %%r2,0" : : );
+	#elif __s390_arch_level__ >= 6
+	    asm ("lay %%r2,0(%%r15)" : : );
+	#elif __s390_arch_level__ >= 5
+	    asm ("tam" : : );
+	#endif
+	#ifdef __HTM__
+	  {
+	    unsigned int nd;
+	    asm ("etnd %0" : "=d" (nd));
+	  }
+	#endif
+	#ifdef __VEC__
+	    asm ("vzero %%v0" : : );
+	#endif
+	  return 0;
+	}
+    }] "$torture_current_flags -m64 -mzarch" ] } { return 0 } else { return 1 }
+}
+
 # If a testcase doesn't have special options, use these.
 global DEFAULT_CFLAGS
 if ![info exists DEFAULT_CFLAGS] then {
@@ -112,11 +140,11 @@  torture-finish
 # Additional md torture tests.
 torture-init
 set MD_TEST_OPTS [list \
-	{-Os -march=z900} {-Os -march=z13} \
-	{-O0 -march=z900} {-O0 -march=z13} \
-	{-O1 -march=z900} {-O1 -march=z13} \
-	{-O2 -march=z900} {-O2 -march=z13} \
-	{-O3 -march=z900} {-O3 -march=z13}]
+	{-Os -march=z900} {-Os -march=z13} {-Os} \
+	{-O0 -march=z900} {-O0 -march=z13} {-O0} \
+	{-O1 -march=z900} {-O1 -march=z13} {-O1} \
+	{-O2 -march=z900} {-O2 -march=z13} {-O2} \
+	{-O3 -march=z900} {-O3 -march=z13} {-O3}]
 set-torture-options $MD_TEST_OPTS
 gcc-dg-runtest [lsort [glob -nocomplain $md_tests]] "" $DEFAULT_CFLAGS
 torture-finish
diff --git a/gcc/testsuite/lib/gcc-dg.exp b/gcc/testsuite/lib/gcc-dg.exp
index 6217272..d9681b1 100644
--- a/gcc/testsuite/lib/gcc-dg.exp
+++ b/gcc/testsuite/lib/gcc-dg.exp
@@ -533,6 +533,8 @@  proc gcc-dg-runtest { testcases flags default-extra-flags } {
 	set nshort [file tail [file dirname $test]]/[file tail $test]
 
 	foreach flags_t $option_list {
+	    global torture_current_flags
+	    set torture_current_flags "$flags_t"
 	    verbose "Testing $nshort, $flags $flags_t" 1
 	    dg-test $test "$flags $flags_t" ${default-extra-flags}
 	}