diff mbox

PATCH: Check AVX runtime support

Message ID AANLkTimUBZs8vHE-awqf6MUcQc1U_KUhmnQ_q=qFHu8R@mail.gmail.com
State New
Headers show

Commit Message

Uros Bizjak July 23, 2010, 8:57 a.m. UTC
On Fri, Jul 23, 2010 at 8:18 AM, Uros Bizjak <ubizjak@gmail.com> wrote:

>>>> -# Return 1 if avx instructions can be compiled.
>>>> +# Return 1 if avx instructions can be compiled and run.
>>>
>>> The corresponding sse/sse2 effective-target tests used separate sse and
>>> sse_runtime.  AVX should be the same for symmetry.
>>
>> check_effective_target_avx is used on runtime tests.
>>
>> /* { dg-do run } */
>> /* { dg-require-effective-target avx } */
>>
>> --
>> /* { dg-do run } */
>> /* { dg-require-effective-target avx } */
>> /* { dg-require-effective-target avx-runt-time } */
>> --
>>
>> is redundant.
>
> No, it isn't.
>
> "dg-require-effective-target avx" means that the toolchain can compile
> avx assembly, so executable can be produced.
> "dg-require-effective-target avx-runtime" means that the OS can run
> produced executable.

OTOH, we _can_ add check_effective_target_* to
check_effective_target_*_runtime, since we obviously need toolchain
support for runtime tests. However, putting everything together the
way you did was a bad approach. We still need separate check for
toolchain support. Think about LTO tests.

Please note that compile tests don't need effective-target check.

Attached patch implements all this and changes all tests outside
gcc.target/i386 directory to new syntax.

2010-06-22  Uros Bizjak  <ubizjak@gmail.com>

	* lib/target-supports.exp (check_avx_hw_available): New procedure.
	(check_effective_target_avx_runtime): New procedure.
	(check_effective_target_sse2_runtime): Add check_effective_target_sse2.
	(check_effective_target_sse_runtime): Add check_effective_target_sse.

	* gcc.dg/compat/pr38736_main.c: Use avx_runtime effective target.
	* gcc.dg/compat/vector-1b_main.c: Ditto.  Remove cpuid.h include
	and __get_cpuid test.
	* gcc.dg/compat/vector-2b_main.c: Ditto.

	* gcc.target/i386/avx-check.h (main): Also check bit_OSXSAVE.

	* gcc.dg/20020418-1.c: Do not require sse2 effective target
	for compile-time only test.
	* gcc.dg/pr32716.c: Ditto.
	* gcc.dg/pr34856.c: Ditto.
	* gcc.dg/pr36997.c: Ditto.
	* gcc.dg/prefetch-loop-arrays-1.c: Ditto.
	* gfortran.dg/pr28158.f90: Ditto.
	* gfortran.dg/pr30667.f: Ditto.

	* gcc.dg/vect/vect.exp: Use check_effective_target_sse2_runtime for
	i?86-*-* and x86_64-*-* targets to disable execution on targets
	without sse2 runtime support.
	* g++.dg/vect/vect.exp: Ditto.
	* gfortran.dg/vect/vect.exp: Ditto.

	* gcc.dg/pr36584.c: Remove now redundant sse2 effective target check.
	* gcc.dg/pr37544.c: Ditto.
	* gcc.dg/pr40550.c: Ditto.
	* gcc.dg/compat/union-m128-1_main.c: Ditto.
	* gcc.dg/compat/vector-1a_main.c: Ditto.
	* gcc.dg/compat/vector-2a_main.c: Ditto.
	* gcc.dg/torture/pr16104-1.c: Ditto.
	* gcc.dg/torture/pr35771-1.c: Ditto.
	* gcc.dg/torture/pr35771-2.c: Ditto.
	* gcc.dg/torture/pr35771-3.c: Ditto.
	* gcc.dg/torture/stackalign/alloca-2.c: Ditto.
	* gcc.dg/torture/stackalign/alloca-3.c: Ditto.
	* gcc.dg/torture/stackalign/push-1.c: Ditto.
	* gcc.dg/torture/stackalign/vararg-3.c: Ditto.
	* g++.dg/other/pr40446.C: Ditto.
	* g++.dg/other/i386-1.C: Ditto.

Patch is currently in testing, will be committed as soon as tests finish.

Uros.

Comments

Rainer Orth July 23, 2010, 9:07 a.m. UTC | #1
Uros Bizjak <ubizjak@gmail.com> writes:

> Please note that compile tests don't need effective-target check.

Of course they do, to make sure that the assembler is capable of
assembling the compiler output (think Solaris 8/9 as).  We just don't
need both, say, sse2 and sse2_runtime with your patch, which is nice.

> Index: gcc.dg/pr34856.c
> ===================================================================
> --- gcc.dg/pr34856.c	(revision 162422)
> +++ gcc.dg/pr34856.c	(working copy)
> @@ -1,7 +1,6 @@
>  /* { dg-do compile } */
>  /* { dg-options "-O2" } */
>  /* { dg-options "-O2 -msse2" { target { i?86-*-* x86_64-*-* } } } */
> -/* { dg-require-effective-target sse2 { target { i?86-*-* x86_64-*-* } } } */
>  /* { dg-options "-O2 -maltivec" { target { powerpc*-*-linux* && powerpc_altivec_ok } } } */

Need to keep dg-require-effective-target sse2 here.

> Index: gcc.dg/20020418-1.c
> ===================================================================
> --- gcc.dg/20020418-1.c	(revision 162422)
> +++ gcc.dg/20020418-1.c	(working copy)
> @@ -2,7 +2,6 @@
>  /* { dg-do compile } */
>  /* { dg-options "-O2" } */
>  /* { dg-options "-O2 -msse -ffast-math" { target i?86-*-* x86_64-*-* } } */
> -/* { dg-require-effective-target sse { target i?86-*-* x86_64-*-* } } */
>  
>  void bar (float *a, float *b);

Same here.

> Index: gcc.dg/pr32176.c
> ===================================================================
> --- gcc.dg/pr32176.c	(revision 162422)
> +++ gcc.dg/pr32176.c	(working copy)
> @@ -3,7 +3,6 @@
>  /* { dg-do compile } */
>  /* { dg-options "-O2 -fprefetch-loop-arrays -w" } */
>  /* { dg-options "-O2 -fprefetch-loop-arrays -march=i686 -msse" { target { { i?86-*-* x86_64-*-* } && ilp32 } } } */
> -/* { dg-require-effective-target sse { target { { i?86-*-* x86_64-*-* } && ilp32 } } } */

... and here.

> Index: gcc.dg/prefetch-loop-arrays-1.c
> ===================================================================
> --- gcc.dg/prefetch-loop-arrays-1.c	(revision 162422)
> +++ gcc.dg/prefetch-loop-arrays-1.c	(working copy)
> @@ -2,7 +2,6 @@
>  /* { dg-do compile } */
>  /* { dg-options "-O2 -fprefetch-loop-arrays -w" } */
>  /* { dg-options "-O2 -fprefetch-loop-arrays -march=i686 -msse -w" { target { { i?86-*-* x86_64-*-* } && ilp32 } } } */
> -/* { dg-require-effective-target sse { target { { i?86-*-* x86_64-*-* } && ilp32 } } } */

Again.

> Index: gcc.dg/pr36997.c
> ===================================================================
> --- gcc.dg/pr36997.c	(revision 162422)
> +++ gcc.dg/pr36997.c	(working copy)
> @@ -1,6 +1,5 @@
>  /* { dg-do compile { target x86_64-*-* i?86-*-* } } */
>  /* { dg-options "-std=c99 -msse2" } */
> -/* { dg-require-effective-target sse2 } */

And again.

> Index: gfortran.dg/pr28158.f90
> ===================================================================
> --- gfortran.dg/pr28158.f90	(revision 162422)
> +++ gfortran.dg/pr28158.f90	(working copy)
> @@ -1,7 +1,6 @@
>  ! { dg-do compile { target i?86-*-* x86_64-*-* } }
>  ! { dg-require-effective-target ilp32 }
>  ! { dg-options "-O -msse -mfpmath=sse" }
> -! { dg-require-effective-target sse }

Again.

> Index: gfortran.dg/pr30667.f
> ===================================================================
> --- gfortran.dg/pr30667.f	(revision 162422)
> +++ gfortran.dg/pr30667.f	(working copy)
> @@ -1,7 +1,6 @@
>  ! { dg-do compile { target i?86-*-* x86_64-*-* } }
>  ! { dg-require-effective-target ilp32 }
>  ! { dg-options "-O2 -msse -ftree-vectorize" }
> -! { dg-require-effective-target sse } 

Again.

Thanks.
	Rainer
Jakub Jelinek July 23, 2010, 10:19 a.m. UTC | #2
On Fri, Jul 23, 2010 at 11:07:41AM +0200, Rainer Orth wrote:
> Uros Bizjak <ubizjak@gmail.com> writes:
> 
> > Please note that compile tests don't need effective-target check.
> 
> Of course they do, to make sure that the assembler is capable of
> assembling the compiler output (think Solaris 8/9 as).  We just don't
> need both, say, sse2 and sse2_runtime with your patch, which is nice.

{ dg-do compile } tests aren't assembled, it is just -S mode, so I don't see
why would you need that.  For { dg-do assemble } tests (or link or run)
you would need that.

> > Index: gcc.dg/pr34856.c
> > ===================================================================
> > --- gcc.dg/pr34856.c	(revision 162422)
> > +++ gcc.dg/pr34856.c	(working copy)
> > @@ -1,7 +1,6 @@
> >  /* { dg-do compile } */
> >  /* { dg-options "-O2" } */
> >  /* { dg-options "-O2 -msse2" { target { i?86-*-* x86_64-*-* } } } */
> > -/* { dg-require-effective-target sse2 { target { i?86-*-* x86_64-*-* } } } */
> >  /* { dg-options "-O2 -maltivec" { target { powerpc*-*-linux* && powerpc_altivec_ok } } } */
> 
> Need to keep dg-require-effective-target sse2 here.

I don't think so.

	Jakub
Rainer Orth July 23, 2010, 10:19 a.m. UTC | #3
Jakub Jelinek <jakub@redhat.com> writes:

> On Fri, Jul 23, 2010 at 11:07:41AM +0200, Rainer Orth wrote:
>> Uros Bizjak <ubizjak@gmail.com> writes:
>> 
>> > Please note that compile tests don't need effective-target check.
>> 
>> Of course they do, to make sure that the assembler is capable of
>> assembling the compiler output (think Solaris 8/9 as).  We just don't
>> need both, say, sse2 and sse2_runtime with your patch, which is nice.
>
> { dg-do compile } tests aren't assembled, it is just -S mode, so I don't see
> why would you need that.  For { dg-do assemble } tests (or link or run)
> you would need that.

Oh, you're right.  Sorry, must have been dreaming ;-(

	Rainer
H.J. Lu July 23, 2010, 3:20 p.m. UTC | #4
On Fri, Jul 23, 2010 at 1:57 AM, Uros Bizjak <ubizjak@gmail.com> wrote:
> On Fri, Jul 23, 2010 at 8:18 AM, Uros Bizjak <ubizjak@gmail.com> wrote:
>
>>>>> -# Return 1 if avx instructions can be compiled.
>>>>> +# Return 1 if avx instructions can be compiled and run.
>>>>
>>>> The corresponding sse/sse2 effective-target tests used separate sse and
>>>> sse_runtime.  AVX should be the same for symmetry.
>>>
>>> check_effective_target_avx is used on runtime tests.
>>>
>>> /* { dg-do run } */
>>> /* { dg-require-effective-target avx } */
>>>
>>> --
>>> /* { dg-do run } */
>>> /* { dg-require-effective-target avx } */
>>> /* { dg-require-effective-target avx-runt-time } */
>>> --
>>>
>>> is redundant.
>>
>> No, it isn't.
>>
>> "dg-require-effective-target avx" means that the toolchain can compile
>> avx assembly, so executable can be produced.
>> "dg-require-effective-target avx-runtime" means that the OS can run
>> produced executable.
>
> OTOH, we _can_ add check_effective_target_* to
> check_effective_target_*_runtime, since we obviously need toolchain
> support for runtime tests. However, putting everything together the
> way you did was a bad approach. We still need separate check for
> toolchain support. Think about LTO tests.
>
> Please note that compile tests don't need effective-target check.
>
> Attached patch implements all this and changes all tests outside
> gcc.target/i386 directory to new syntax.
>
> 2010-06-22  Uros Bizjak  <ubizjak@gmail.com>
>
>        * lib/target-supports.exp (check_avx_hw_available): New procedure.
>        (check_effective_target_avx_runtime): New procedure.
>        (check_effective_target_sse2_runtime): Add check_effective_target_sse2.
>        (check_effective_target_sse_runtime): Add check_effective_target_sse.
>
>        * gcc.dg/compat/pr38736_main.c: Use avx_runtime effective target.
>        * gcc.dg/compat/vector-1b_main.c: Ditto.  Remove cpuid.h include
>        and __get_cpuid test.
>        * gcc.dg/compat/vector-2b_main.c: Ditto.
>
>        * gcc.target/i386/avx-check.h (main): Also check bit_OSXSAVE.
>
>        * gcc.dg/20020418-1.c: Do not require sse2 effective target
>        for compile-time only test.
>        * gcc.dg/pr32716.c: Ditto.
>        * gcc.dg/pr34856.c: Ditto.
>        * gcc.dg/pr36997.c: Ditto.
>        * gcc.dg/prefetch-loop-arrays-1.c: Ditto.
>        * gfortran.dg/pr28158.f90: Ditto.
>        * gfortran.dg/pr30667.f: Ditto.
>
>        * gcc.dg/vect/vect.exp: Use check_effective_target_sse2_runtime for
>        i?86-*-* and x86_64-*-* targets to disable execution on targets
>        without sse2 runtime support.
>        * g++.dg/vect/vect.exp: Ditto.
>        * gfortran.dg/vect/vect.exp: Ditto.
>
>        * gcc.dg/pr36584.c: Remove now redundant sse2 effective target check.
>        * gcc.dg/pr37544.c: Ditto.
>        * gcc.dg/pr40550.c: Ditto.
>        * gcc.dg/compat/union-m128-1_main.c: Ditto.
>        * gcc.dg/compat/vector-1a_main.c: Ditto.
>        * gcc.dg/compat/vector-2a_main.c: Ditto.
>        * gcc.dg/torture/pr16104-1.c: Ditto.
>        * gcc.dg/torture/pr35771-1.c: Ditto.
>        * gcc.dg/torture/pr35771-2.c: Ditto.
>        * gcc.dg/torture/pr35771-3.c: Ditto.
>        * gcc.dg/torture/stackalign/alloca-2.c: Ditto.
>        * gcc.dg/torture/stackalign/alloca-3.c: Ditto.
>        * gcc.dg/torture/stackalign/push-1.c: Ditto.
>        * gcc.dg/torture/stackalign/vararg-3.c: Ditto.
>        * g++.dg/other/pr40446.C: Ditto.
>        * g++.dg/other/i386-1.C: Ditto.
>
> Patch is currently in testing, will be committed as soon as tests finish.
>

This patch caused:

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45046
diff mbox

Patch

Index: gcc.target/i386/avx-check.h
===================================================================
--- gcc.target/i386/avx-check.h	(revision 162422)
+++ gcc.target/i386/avx-check.h	(working copy)
@@ -20,7 +20,7 @@ 
     return 0;
 
   /* Run AVX test only if host has AVX support.  */
-  if (ecx & bit_AVX)
+  if ((ecx & (bit_AVX | bit_OSXSAVE)) == (bit_AVX | bit_OSXSAVE))
     {
       do_test ();
 #ifdef DEBUG
Index: gcc.dg/pr34856.c
===================================================================
--- gcc.dg/pr34856.c	(revision 162422)
+++ gcc.dg/pr34856.c	(working copy)
@@ -1,7 +1,6 @@ 
 /* { dg-do compile } */
 /* { dg-options "-O2" } */
 /* { dg-options "-O2 -msse2" { target { i?86-*-* x86_64-*-* } } } */
-/* { dg-require-effective-target sse2 { target { i?86-*-* x86_64-*-* } } } */
 /* { dg-options "-O2 -maltivec" { target { powerpc*-*-linux* && powerpc_altivec_ok } } } */
 
 typedef unsigned __attribute__ ((__mode__ (__pointer__))) uintptr_t;
Index: gcc.dg/pr36584.c
===================================================================
--- gcc.dg/pr36584.c	(revision 162422)
+++ gcc.dg/pr36584.c	(working copy)
@@ -1,7 +1,6 @@ 
 /* { dg-do run } */
 /* { dg-options "-O2 -lm" } */
 /* { dg-options "-O2 -msse2 -mfpmath=sse" { target { { i?86-*-* x86_64-*-* } && ilp32 } } } */
-/* { dg-require-effective-target sse2 { target { { i?86-*-* x86_64-*-* } && ilp32 } } } */
 /* { dg-require-effective-target sse2_runtime { target { { i?86-*-* x86_64-*-* } && ilp32 } } } */
 
 extern double fabs (double);
Index: gcc.dg/compat/pr38736_main.c
===================================================================
--- gcc.dg/compat/pr38736_main.c	(revision 162422)
+++ gcc.dg/compat/pr38736_main.c	(working copy)
@@ -1,6 +1,6 @@ 
 /* PR target/38736 */
 /* { dg-skip-if "attribute ((aligned))" { ! { i?86-*-* x86_64-*-* } } } */
-/* { dg-require-effective-target avx } */
+/* { dg-require-effective-target avx_runtime } */
 
 /* Test compatibility of attribute ((aligned)) with and without -mavx.  */
 
Index: gcc.dg/compat/vector-1b_main.c
===================================================================
--- gcc.dg/compat/vector-1b_main.c	(revision 162422)
+++ gcc.dg/compat/vector-1b_main.c	(working copy)
@@ -1,12 +1,10 @@ 
 /* { dg-skip-if "test AVX vector" { ! { i?86-*-* x86_64-*-* } } } */
-/* { dg-require-effective-target avx } */
+/* { dg-require-effective-target avx_runtime } */
 
 /* Test compatibility of vector types: layout between separately-compiled
    modules, parameter passing, and function return.  This test uses
    vectors of integer values.  */
 
-#include "cpuid.h"
-
 extern void vector_1_x (void);
 extern void exit (int);
 int fails;
@@ -14,14 +12,6 @@ 
 int
 main ()
 {
-  unsigned int eax, ebx, ecx, edx;
-
-  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
-    return 0;
-
-  /* Run AVX vector test only if host has AVX support.  */
-  if (ecx & bit_AVX)
-    vector_1_x ();
-
+  vector_1_x ();
   exit (0);
 }
Index: gcc.dg/compat/vector-2b_main.c
===================================================================
--- gcc.dg/compat/vector-2b_main.c	(revision 162422)
+++ gcc.dg/compat/vector-2b_main.c	(working copy)
@@ -1,12 +1,10 @@ 
 /* { dg-skip-if "test AVX support" { ! { i?86-*-* x86_64-*-* } } } */
-/* { dg-require-effective-target avx } */
+/* { dg-require-effective-target avx_runtime } */
 
 /* Test compatibility of vector types: layout between separately-compiled
    modules, parameter passing, and function return.  This test uses
    vectors of floating points values.  */
 
-#include "cpuid.h"
-
 extern void vector_2_x (void);
 extern void exit (int);
 int fails;
@@ -14,14 +12,6 @@ 
 int
 main ()
 {
-  unsigned int eax, ebx, ecx, edx;
-
-  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
-    return 0;
-
-  /* Run AVX vector test only if host has AVX support.  */
-  if (ecx & bit_AVX)
-    vector_2_x ();
-
+  vector_2_x ();
   exit (0);
 }
Index: gcc.dg/compat/union-m128-1_main.c
===================================================================
--- gcc.dg/compat/union-m128-1_main.c	(revision 162422)
+++ gcc.dg/compat/union-m128-1_main.c	(working copy)
@@ -1,6 +1,5 @@ 
 /* { dg-skip-if "test SSE2 support" { ! { i?86-*-* x86_64-*-* } } } */
 /* { dg-options "-O" } */
-/* { dg-require-effective-target sse2 } */
 /* { dg-require-effective-target sse2_runtime } */
 
 /* Test function argument passing.  PR target/15301.  */
Index: gcc.dg/compat/vector-1a_main.c
===================================================================
--- gcc.dg/compat/vector-1a_main.c	(revision 162422)
+++ gcc.dg/compat/vector-1a_main.c	(working copy)
@@ -1,5 +1,4 @@ 
 /* { dg-skip-if "test SSE2 vector" { ! { i?86-*-* x86_64-*-* } } } */
-/* { dg-require-effective-target sse2 } */
 /* { dg-require-effective-target sse2_runtime } */
 
 /* Test compatibility of vector types: layout between separately-compiled
Index: gcc.dg/compat/vector-2a_main.c
===================================================================
--- gcc.dg/compat/vector-2a_main.c	(revision 162422)
+++ gcc.dg/compat/vector-2a_main.c	(working copy)
@@ -1,5 +1,4 @@ 
 /* { dg-skip-if "test SSE2 support" { ! { i?86-*-* x86_64-*-* } } } */
-/* { dg-require-effective-target sse2 } */
 /* { dg-require-effective-target sse2_runtime } */
 
 /* Test compatibility of vector types: layout between separately-compiled
Index: gcc.dg/pr40550.c
===================================================================
--- gcc.dg/pr40550.c	(revision 162422)
+++ gcc.dg/pr40550.c	(working copy)
@@ -1,6 +1,5 @@ 
 /* { dg-do run } */
 /* { dg-options "-msse" { target { { i?86-*-* x86_64-*-* } && ilp32 } } } */
-/* { dg-require-effective-target sse { target { { i?86-*-* x86_64-*-* } && ilp32 } } } */
 /* { dg-require-effective-target sse_runtime { target { { i?86-*-* x86_64-*-* } && ilp32 } } } */
 
 typedef float v2sf __attribute__ ((vector_size (2 * sizeof(float))));
Index: gcc.dg/20020418-1.c
===================================================================
--- gcc.dg/20020418-1.c	(revision 162422)
+++ gcc.dg/20020418-1.c	(working copy)
@@ -2,7 +2,6 @@ 
 /* { dg-do compile } */
 /* { dg-options "-O2" } */
 /* { dg-options "-O2 -msse -ffast-math" { target i?86-*-* x86_64-*-* } } */
-/* { dg-require-effective-target sse { target i?86-*-* x86_64-*-* } } */
 
 void bar (float *a, float *b);
 
Index: gcc.dg/torture/pr35771-1.c
===================================================================
--- gcc.dg/torture/pr35771-1.c	(revision 162422)
+++ gcc.dg/torture/pr35771-1.c	(working copy)
@@ -1,6 +1,5 @@ 
 /* { dg-do run { target i?86-*-* x86_64-*-* } } */
 /* { dg-options "-msse2" } */
-/* { dg-require-effective-target sse2 } */
 /* { dg-require-effective-target sse2_runtime } */
 
 typedef float __m128 __attribute__ ((__vector_size__ (16), __may_alias__));
Index: gcc.dg/torture/stackalign/vararg-3.c
===================================================================
--- gcc.dg/torture/stackalign/vararg-3.c	(revision 162422)
+++ gcc.dg/torture/stackalign/vararg-3.c	(working copy)
@@ -1,7 +1,6 @@ 
 /* PR middle-end/37009 */
 /* { dg-do run { target { { i?86-*-* x86_64-*-* } && ilp32 } } } */
 /* { dg-options "-msse2" } */
-/* { dg-require-effective-target sse2 } */
 /* { dg-require-effective-target sse2_runtime } */
 
 #include <stdarg.h>
Index: gcc.dg/torture/stackalign/push-1.c
===================================================================
--- gcc.dg/torture/stackalign/push-1.c	(revision 162422)
+++ gcc.dg/torture/stackalign/push-1.c	(working copy)
@@ -1,7 +1,6 @@ 
 /* PR middle-end/37010 */
 /* { dg-do run { target { { i?86-*-* x86_64-*-* } && ilp32 } } } */
 /* { dg-options "-msse2 -mpreferred-stack-boundary=2" } */
-/* { dg-require-effective-target sse2 } */
 /* { dg-require-effective-target sse2_runtime } */
 
 #include <emmintrin.h>
Index: gcc.dg/torture/stackalign/alloca-2.c
===================================================================
--- gcc.dg/torture/stackalign/alloca-2.c	(revision 162422)
+++ gcc.dg/torture/stackalign/alloca-2.c	(working copy)
@@ -1,7 +1,6 @@ 
 /* PR middle-end/37009 */
 /* { dg-do run { target { { i?86-*-* x86_64-*-* } && ilp32 } } } */
 /* { dg-options "-msse2" } */
-/* { dg-require-effective-target sse2 } */
 /* { dg-require-effective-target sse2_runtime } */
 
 #include <emmintrin.h>
Index: gcc.dg/torture/stackalign/alloca-3.c
===================================================================
--- gcc.dg/torture/stackalign/alloca-3.c	(revision 162422)
+++ gcc.dg/torture/stackalign/alloca-3.c	(working copy)
@@ -1,7 +1,6 @@ 
 /* PR middle-end/37009 */
 /* { dg-do run { target { { i?86-*-* x86_64-*-* } && ilp32 } } } */
 /* { dg-options "-msse2" } */
-/* { dg-require-effective-target sse2 } */
 /* { dg-require-effective-target sse2_runtime } */
 
 #include <emmintrin.h>
Index: gcc.dg/torture/pr35771-2.c
===================================================================
--- gcc.dg/torture/pr35771-2.c	(revision 162422)
+++ gcc.dg/torture/pr35771-2.c	(working copy)
@@ -1,6 +1,5 @@ 
 /* { dg-do run { target i?86-*-* x86_64-*-* } } */
 /* { dg-options "-msse2" } */
-/* { dg-require-effective-target sse2 } */
 /* { dg-require-effective-target sse2_runtime } */
 
 typedef double __m128d __attribute__ ((__vector_size__ (16), __may_alias__));
Index: gcc.dg/torture/pr16104-1.c
===================================================================
--- gcc.dg/torture/pr16104-1.c	(revision 162422)
+++ gcc.dg/torture/pr16104-1.c	(working copy)
@@ -1,7 +1,6 @@ 
 /* PR rtl-optimization/16104 */
 /* { dg-do run { target i?86-*-* x86_64-*-* } } */
 /* { dg-options "-msse2" } */
-/* { dg-require-effective-target sse2 } */
 /* { dg-require-effective-target sse2_runtime } */
 
 extern void abort (void);
Index: gcc.dg/torture/pr35771-3.c
===================================================================
--- gcc.dg/torture/pr35771-3.c	(revision 162422)
+++ gcc.dg/torture/pr35771-3.c	(working copy)
@@ -1,6 +1,5 @@ 
 /* { dg-do run { target i?86-*-* x86_64-*-* } } */
 /* { dg-options "-msse2" } */
-/* { dg-require-effective-target sse2 } */
 /* { dg-require-effective-target sse2_runtime } */
 
 typedef long long __m128i __attribute__ ((__vector_size__ (16), __may_alias__));
Index: gcc.dg/pr37544.c
===================================================================
--- gcc.dg/pr37544.c	(revision 162422)
+++ gcc.dg/pr37544.c	(working copy)
@@ -1,7 +1,6 @@ 
 /* { dg-do run } */
 /* { dg-options "-O2" } */
 /* { dg-options "-O2 -msse2 -mtune=core2 -mfpmath=387" { target { i?86-*-* x86_64-*-* } } } */
-/* { dg-require-effective-target sse2 { target { i?86-*-* x86_64-*-* } } } */
 /* { dg-require-effective-target sse2_runtime { target { i?86-*-* x86_64-*-* } } } */
 
 extern void abort (void);
Index: gcc.dg/pr32176.c
===================================================================
--- gcc.dg/pr32176.c	(revision 162422)
+++ gcc.dg/pr32176.c	(working copy)
@@ -3,7 +3,6 @@ 
 /* { dg-do compile } */
 /* { dg-options "-O2 -fprefetch-loop-arrays -w" } */
 /* { dg-options "-O2 -fprefetch-loop-arrays -march=i686 -msse" { target { { i?86-*-* x86_64-*-* } && ilp32 } } } */
-/* { dg-require-effective-target sse { target { { i?86-*-* x86_64-*-* } && ilp32 } } } */
 
 void foo (void)
 {
Index: gcc.dg/prefetch-loop-arrays-1.c
===================================================================
--- gcc.dg/prefetch-loop-arrays-1.c	(revision 162422)
+++ gcc.dg/prefetch-loop-arrays-1.c	(working copy)
@@ -2,7 +2,6 @@ 
 /* { dg-do compile } */
 /* { dg-options "-O2 -fprefetch-loop-arrays -w" } */
 /* { dg-options "-O2 -fprefetch-loop-arrays -march=i686 -msse -w" { target { { i?86-*-* x86_64-*-* } && ilp32 } } } */
-/* { dg-require-effective-target sse { target { { i?86-*-* x86_64-*-* } && ilp32 } } } */
 
 __extension__ typedef __SIZE_TYPE__ size_t;
 
Index: gcc.dg/vect/vect.exp
===================================================================
--- gcc.dg/vect/vect.exp	(revision 162422)
+++ gcc.dg/vect/vect.exp	(working copy)
@@ -67,11 +67,8 @@ 
 } elseif { [istarget  "spu-*-*"] } {
    set dg-do-what-default run
 } elseif { [istarget "i?86-*-*"] || [istarget "x86_64-*-*"] } {
-    if { ![check_effective_target_sse2] } then {
-	return
-    }
     lappend DEFAULT_VECTCFLAGS "-msse2"
-    if { [check_sse2_hw_available] && [check_sse_os_support_available] } {
+    if { [check_effective_target_sse2_runtime] } {
 	set dg-do-what-default run
     } else {
 	set dg-do-what-default compile
Index: gcc.dg/pr36997.c
===================================================================
--- gcc.dg/pr36997.c	(revision 162422)
+++ gcc.dg/pr36997.c	(working copy)
@@ -1,6 +1,5 @@ 
 /* { dg-do compile { target x86_64-*-* i?86-*-* } } */
 /* { dg-options "-std=c99 -msse2" } */
-/* { dg-require-effective-target sse2 } */
 
 typedef int __m64 __attribute__ ((__vector_size__ (8), __may_alias__));
 __m64 _mm_add_si64 (__m64 __m1, __m64 __m2)
Index: g++.dg/other/pr40446.C
===================================================================
--- g++.dg/other/pr40446.C	(revision 162422)
+++ g++.dg/other/pr40446.C	(working copy)
@@ -1,7 +1,6 @@ 
 // PR middle-end/40446
 // { dg-do run { target i?86-*-* x86_64-*-* } }
 // { dg-options "-O1 -msse2" }
-// { dg-require-effective-target sse2 }
 // { dg-require-effective-target sse2_runtime }
 
 #include <emmintrin.h>
Index: g++.dg/other/i386-1.C
===================================================================
--- g++.dg/other/i386-1.C	(revision 162422)
+++ g++.dg/other/i386-1.C	(working copy)
@@ -1,6 +1,5 @@ 
 /* { dg-do run { target i?86-*-* x86_64-*-* } } */
 /* { dg-options "-msse2" } */
-/* { dg-require-effective-target sse2 } */
 /* { dg-require-effective-target sse2_runtime } */
 
 #include <xmmintrin.h>
Index: g++.dg/vect/vect.exp
===================================================================
--- g++.dg/vect/vect.exp	(revision 162422)
+++ g++.dg/vect/vect.exp	(working copy)
@@ -75,11 +75,8 @@ 
 } elseif { [istarget  "spu-*-*"] } {
    set dg-do-what-default run
 } elseif { [istarget "i?86-*-*"] || [istarget "x86_64-*-*"] } {
-    if { ![check_effective_target_sse2] } then {
-	return
-    }
     lappend DEFAULT_VECTCFLAGS "-msse2"
-    if { [check_sse2_hw_available] && [check_sse_os_support_available] } {
+    if { [check_effective_target_sse2_runtime] } {
 	set dg-do-what-default run
     } else {
 	set dg-do-what-default compile
Index: lib/target-supports.exp
===================================================================
--- lib/target-supports.exp	(revision 162422)
+++ lib/target-supports.exp	(working copy)
@@ -953,7 +953,7 @@ 
 		#include "cpuid.h"
 		int main ()
 		{
-		  unsigned int eax, ebx, ecx, edx = 0;
+		  unsigned int eax, ebx, ecx, edx;
 		  if (__get_cpuid (1, &eax, &ebx, &ecx, &edx))
 		    return !(edx & bit_SSE);
 		  return 1;
@@ -976,7 +976,7 @@ 
 		#include "cpuid.h"
 		int main ()
 		{
-		  unsigned int eax, ebx, ecx, edx = 0;
+		  unsigned int eax, ebx, ecx, edx;
 		  if (__get_cpuid (1, &eax, &ebx, &ecx, &edx))
 		    return !(edx & bit_SSE2);
 		  return 1;
@@ -986,26 +986,62 @@ 
     }]
 }
 
+# Return 1 if the target supports executing AVX instructions, 0
+# otherwise.  Cache the result.
+
+proc check_avx_hw_available { } {
+    return [check_cached_effective_target avx_hw_available {
+	# If this is not the right target then we can skip the test.
+	if { !([istarget x86_64-*-*] || [istarget i?86-*-*]) } {
+	    expr 0
+	} else {
+	    check_runtime_nocache avx_hw_available {
+		#include "cpuid.h"
+		int main ()
+		{
+		  unsigned int eax, ebx, ecx, edx;
+		  if (__get_cpuid (1, &eax, &ebx, &ecx, &edx))
+		    return ((ecx & (bit_AVX | bit_OSXSAVE))
+			    != (bit_AVX | bit_OSXSAVE));
+		  return 1;
+		}
+	    } ""
+	}
+    }]
+}
+
 # Return 1 if the target supports running SSE executables, 0 otherwise.
 
 proc check_effective_target_sse_runtime { } {
-    if { [check_sse_hw_available] && [check_sse_os_support_available] } {
+    if { [check_effective_target_sse]
+	 && [check_sse_hw_available]
+	 && [check_sse_os_support_available] } {
 	return 1
-    } else {
-	return 0
     }
+    return 0
 }
 
 # Return 1 if the target supports running SSE2 executables, 0 otherwise.
 
 proc check_effective_target_sse2_runtime { } {
-    if { [check_sse2_hw_available] && [check_sse_os_support_available] } {
+    if { [check_effective_target_sse2]
+	 && [check_sse2_hw_available]
+	 && [check_sse_os_support_available] } {
 	return 1
-    } else {
-	return 0
     }
+    return 0
 }
 
+# Return 1 if the target supports running AVX executables, 0 otherwise.
+
+proc check_effective_target_avx_runtime { } {
+    if { [check_effective_target_avx]
+	 && [check_avx_hw_available] } {
+	return 1
+    }
+    return 0
+}
+
 # Return 1 if the target supports executing VSX instructions, 0
 # otherwise.  Cache the result.
 
Index: gfortran.dg/pr28158.f90
===================================================================
--- gfortran.dg/pr28158.f90	(revision 162422)
+++ gfortran.dg/pr28158.f90	(working copy)
@@ -1,7 +1,6 @@ 
 ! { dg-do compile { target i?86-*-* x86_64-*-* } }
 ! { dg-require-effective-target ilp32 }
 ! { dg-options "-O -msse -mfpmath=sse" }
-! { dg-require-effective-target sse }
     subroutine yhalf(z)
     complex cdexpj,z
     z=cdexpj((0.d0,1.d0)*z)
Index: gfortran.dg/pr30667.f
===================================================================
--- gfortran.dg/pr30667.f	(revision 162422)
+++ gfortran.dg/pr30667.f	(working copy)
@@ -1,7 +1,6 @@ 
 ! { dg-do compile { target i?86-*-* x86_64-*-* } }
 ! { dg-require-effective-target ilp32 }
 ! { dg-options "-O2 -msse -ftree-vectorize" }
-! { dg-require-effective-target sse } 
       subroutine cblank_cvb(a,ndim)
       character*(*) a
       character*1 blank
Index: gfortran.dg/vect/vect.exp
===================================================================
--- gfortran.dg/vect/vect.exp	(revision 162422)
+++ gfortran.dg/vect/vect.exp	(working copy)
@@ -68,11 +68,8 @@ 
 } elseif { [istarget  "spu-*-*"] } {
    set dg-do-what-default run
 } elseif { [istarget "i?86-*-*"] || [istarget "x86_64-*-*"] } {
-    if { ![check_effective_target_sse2] } then {
-	return
-    }
     lappend DEFAULT_VECTCFLAGS "-msse2"
-    if { [check_sse2_hw_available] && [check_sse_os_support_available] } {
+    if { [check_effective_target_sse2_runtime] } {
 	set dg-do-what-default run
     } else {
 	set dg-do-what-default compile