@@ -18435,11 +18435,13 @@ (define_expand "xbegin"
operands[1] = force_reg (SImode, constm1_rtx);
- emit_jump_insn (gen_xbegin_1 (operands[0], operands[1], label));
+ emit_jump_insn (gen_xbegin_1 (operands[1], label));
emit_label (label);
LABEL_NUSES (label) = 1;
+ emit_move_insn (operands[0], operands[1]);
+
DONE;
})
@@ -18447,13 +18449,12 @@ (define_insn "xbegin_1"
[(set (pc)
(if_then_else (ne (unspec [(const_int 0)] UNSPEC_XBEGIN_ABORT)
(const_int 0))
- (label_ref (match_operand 2))
+ (label_ref (match_operand 1))
(pc)))
- (set (match_operand:SI 0 "register_operand" "=a")
- (unspec_volatile:SI [(match_operand:SI 1 "register_operand" "0")]
- UNSPECV_XBEGIN))]
+ (set (match_operand:SI 0 "register_operand" "+a")
+ (unspec_volatile:SI [(match_dup 0)] UNSPECV_XBEGIN))]
"TARGET_RTM"
- "xbegin\t%l2"
+ "xbegin\t%l1"
[(set_attr "type" "other")
(set_attr "length" "6")])
@@ -1,4 +1,4 @@
-# Copyright (C) 1997, 2004, 2007, 2008, 2009, 2010
+# Copyright (C) 1997, 2004, 2007, 2008, 2009, 2010, 2011, 2012
# Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
@@ -243,6 +243,17 @@ proc check_effective_target_bmi2 { } {
} "-mbmi2" ]
}
+# Return 1 if rtm instructions can be compiled.
+proc check_effective_target_rtm { } {
+ return [check_no_compiler_messages rtm object {
+ void
+ _rtm_xend (void)
+ {
+ return __builtin_ia32_xend ();
+ }
+ } "-mrtm" ]
+}
+
# If the linker used understands -M <mapfile>, pass it to clear hardware
# capabilities set by the Sun assembler.
set clearcap_ldflags "-Wl,-M,$srcdir/$subdir/clearcap.map"
@@ -0,0 +1,32 @@
+#include <stdlib.h>
+#include "cpuid.h"
+
+static void rtm_test (void);
+
+static void __attribute__ ((noinline)) do_test (void)
+{
+ rtm_test ();
+}
+
+int
+main ()
+{
+ unsigned int eax, ebx, ecx, edx;
+
+ if (__get_cpuid_max (0, NULL) >= 7)
+ {
+ __cpuid_count (7, 0, eax, ebx, ecx, edx);
+ if (ebx & bit_RTM)
+ {
+ do_test ();
+#ifdef DEBUG
+ printf ("PASSED\n");
+#endif
+ return 0;
+ }
+ }
+#ifdef DEBUG
+ printf ("SKIPPED\n");
+#endif
+ return 0;
+}
@@ -0,0 +1,27 @@
+/* PR target/53315 and PR target/53291 */
+/* { dg-do run } */
+/* { dg-options "-O2 -mrtm" } */
+/* { dg-require-effective-target rtm } */
+
+#include <x86intrin.h>
+#include "rtm-check.h"
+
+static void
+rtm_test (void)
+{
+ int flag = -1;
+ unsigned status;
+
+ if ((status = _xbegin ()) == _XBEGIN_STARTED)
+ {
+ flag = _xtest ();
+ _xend ();
+ }
+ else
+ return;
+
+ if (flag != 1)
+ abort ();
+ if (_xtest () != 0)
+ abort ();
+}