diff --git a/libitm/ChangeLog b/libitm/ChangeLog
index b1629b1a89e32667bd9e38d3761aa97899aca6e1..8aeb589bfed817534413d67bfe01417712361932 100644
--- a/libitm/ChangeLog
+++ b/libitm/ChangeLog
@@ -1,3 +1,10 @@
+2011-11-09  Richard Henderson  <rth@redhat.com>
+
+	* acinclude.m4 (LIBITM_CHECK_AS_AVX): New.
+	* configure.ac: Use it.
+	* config.h.in, configure: Rebuild.
+	* config/x86/x86_avx.cc: Handle !HAVE_AS_AVX.
+
 2011-11-09  Richard Henderson  <rth@redhat.com>
 
 	* barrier.tpl, memcpy.cc, memset.cc, method-wbetl.cc: Remove file.
diff --git a/libitm/acinclude.m4 b/libitm/acinclude.m4
index 8fcde4b57ad24e5b86ae871afbafa4db3c2c8bb9..58fbf424c609a33b456e9e759722dc94fdd91b5f 100644
--- a/libitm/acinclude.m4
+++ b/libitm/acinclude.m4
@@ -95,6 +95,20 @@ AC_DEFUN([LIBITM_CHECK_SIZE_T_MANGLING], [
     [Define to the letter to which size_t is mangled.])
 ])
 
+dnl Check if as supports AVX instructions.
+AC_DEFUN([LIBITM_CHECK_AS_AVX], [
+case "${target_cpu}" in
+i[3456]86 | x86_64)
+  AC_CACHE_CHECK([if the assembler supports AVX], libitm_cv_as_avx, [
+    AC_TRY_COMPILE([], [asm("vzeroupper");],
+		   [libitm_cv_as_avx=yes], [libitm_cv_as_avx=no])
+  ])
+  if test x$libitm_cv_as_avx = xyes; then
+    AC_DEFINE(HAVE_AS_AVX, 1, [Define to 1 if the assembler supports AVX.])
+  fi
+  ;;
+esac])
+
 sinclude(../libtool.m4)
 dnl The lines below arrange for aclocal not to bring an installed
 dnl libtool.m4 into aclocal.m4, while still arranging for automake to
diff --git a/libitm/config.h.in b/libitm/config.h.in
index 369f6c66caf5fbdb7e27a9d993522705267e5822..52db1a6fdc1c122b100dfe0699aee0f69c100ae1 100644
--- a/libitm/config.h.in
+++ b/libitm/config.h.in
@@ -6,6 +6,9 @@
 /* Define to 1 if the target supports 64-bit __sync_*_compare_and_swap */
 #undef HAVE_64BIT_SYNC_BUILTINS
 
+/* Define to 1 if the assembler supports AVX. */
+#undef HAVE_AS_AVX
+
 /* Define if your assembler supports .cfi_* directives. */
 #undef HAVE_AS_CFI_PSEUDO_OP
 
diff --git a/libitm/config/x86/x86_avx.cc b/libitm/config/x86/x86_avx.cc
index 30420aa87f540fb9e35e0f0c326b6bef87fd9db8..cd20fe25cdc9acf409f2d30f0aa3af50f9089590 100644
--- a/libitm/config/x86/x86_avx.cc
+++ b/libitm/config/x86/x86_avx.cc
@@ -22,9 +22,66 @@
    see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
    <http://www.gnu.org/licenses/>.  */
 
+#include "config.h"
+
+// ??? This is pretty gross, but we're going to frob types of the functions.
+// Is this better or worse than just admitting we need to do this in pure
+// assembly?
+
+#ifndef HAVE_AS_AVX
+#undef __AVX__
+#endif
+
 #include "libitm_i.h"
 #include "dispatch.h"
 
+extern "C" {
+
+#ifndef HAVE_AS_AVX
+typedef float _ITM_TYPE_M256 __attribute__((vector_size(32), may_alias));
+#endif
+
+// ??? Re-define the memcpy implementations so that we can frob the
+// interface to deal with possibly missing AVX instruction set support.
+
+#ifdef HAVE_AS_AVX
+#define RETURN(X)	return X
+#define STORE(X,Y)	X = Y
+#define OUTPUT(T)	_ITM_TYPE_##T
+#define INPUT(T,X)	, _ITM_TYPE_##T X
+#else
+/* Emit vmovaps (%rax),%ymm0.  */
+#define RETURN(X) \
+  asm volatile(".byte 0xc5,0xfc,0x28,0x00" : "=m"(X) : "a"(&X));
+/* Emit vmovaps %ymm0,(%rax); vzeroupper.  */
+#define STORE(X,Y) \
+  asm volatile(".byte 0xc5,0xfc,0x29,0x00,0xc5,0xf8,0x77" : "=m"(X) : "a"(&X));
+#define OUTPUT(T)	void
+#define INPUT(T,X)
+#endif
+
+#undef ITM_READ_MEMCPY
+#define ITM_READ_MEMCPY(T, LSMOD, TARGET, M2)				\
+OUTPUT(T) ITM_REGPARM _ITM_##LSMOD##T (const _ITM_TYPE_##T *ptr)	\
+{									\
+  _ITM_TYPE_##T v;							\
+  TARGET memtransfer##M2(&v, ptr, sizeof(_ITM_TYPE_##T), false,		\
+			 GTM::abi_dispatch::NONTXNAL,			\
+			 GTM::abi_dispatch::LSMOD);			\
+  RETURN(v);								\
+}
+
+#undef ITM_WRITE_MEMCPY
+#define ITM_WRITE_MEMCPY(T, LSMOD, TARGET, M2)				\
+void ITM_REGPARM _ITM_##LSMOD##T (_ITM_TYPE_##T *ptr INPUT(T,in))	\
+{									\
+  _ITM_TYPE_##T v;							\
+  STORE(v, in);								\
+  TARGET memtransfer##M2(ptr, &v, sizeof(_ITM_TYPE_##T), false,		\
+			 GTM::abi_dispatch::LSMOD,			\
+			 GTM::abi_dispatch::NONTXNAL);			\
+}
+
 // ??? Use memcpy for now, until we have figured out how to best instantiate
 // these loads/stores.
 CREATE_DISPATCH_FUNCTIONS_T_MEMCPY(M256, GTM::abi_disp()->, )
@@ -34,3 +91,5 @@ _ITM_LM256 (const _ITM_TYPE_M256 *ptr)
 {
   GTM::GTM_LB (ptr, sizeof (*ptr));
 }
+
+}
diff --git a/libitm/configure b/libitm/configure
index 0f0ec1fc77a0cd4e60d1a557f9c4a2ff5a17fe82..b30ced11548504602398b7e0647925356cdd9a50 100644
--- a/libitm/configure
+++ b/libitm/configure
@@ -17115,6 +17115,43 @@ $as_echo "#define HAVE_64BIT_SYNC_BUILTINS 1" >>confdefs.h
 
   fi
 
+case "${target_cpu}" in
+i345686 | x86_64)
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking if the assembler supports AVX" >&5
+$as_echo_n "checking if the assembler supports AVX... " >&6; }
+if test "${libitm_cv_as_avx+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+
+    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+asm("vzeroupper");
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  libitm_cv_as_avx=yes
+else
+  libitm_cv_as_avx=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libitm_cv_as_avx" >&5
+$as_echo "$libitm_cv_as_avx" >&6; }
+  if test x$libitm_cv_as_avx = xyes; then
+
+$as_echo "#define HAVE_AS_AVX 1" >>confdefs.h
+
+  fi
+  ;;
+esac
+
 # Cleanup and exit.
 CFLAGS="$save_CFLAGS"
 cat >confcache <<\_ACEOF
diff --git a/libitm/configure.ac b/libitm/configure.ac
index c40ecb5bf3cab25ece27a024b32afd1dc8f16273..7de5cbeed912283ba399ec040bde099bb74b0289 100644
--- a/libitm/configure.ac
+++ b/libitm/configure.ac
@@ -237,6 +237,7 @@ CFLAGS="$save_CFLAGS $XCFLAGS"
 # had a chance to set XCFLAGS.
 LIBITM_CHECK_SYNC_BUILTINS
 LIBITM_CHECK_64BIT_SYNC_BUILTINS
+LIBITM_CHECK_AS_AVX
 
 # Cleanup and exit.
 CFLAGS="$save_CFLAGS"