Hi! This is an updated version of the xbegin bugfix. Bootstrapped/regtested on x86_64-linux and i686-linux, tested with the testcase by Andi on RTM capable hw (or was it sim?).
Ok for trunk? 2012-05-14 Andrew Pinski <apin...@cavium.com> H.J. Lu <hongjiu...@intel.com> Jakub Jelinek <ja...@redhat.com> PR target/53315 * config/i386/i386.md (xbegin_1): Use + in constraint and match_dup. (xbegin): Updated. 2012-05-14 Andi Kleen <a...@linux.intel.com> Jakub Jelinek <ja...@redhat.com> PR target/53315 * gcc.target/i386/i386.exp (check_effective_target_rtm): New. * gcc.target/i386/rtm-check.h: New file. * gcc.target/i386/pr53315.c: New test. --- gcc/config/i386/i386.md.jj 2012-05-12 10:21:01.672022706 +0200 +++ gcc/config/i386/i386.md 2012-05-12 10:51:35.783152924 +0200 @@ -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")]) --- gcc/testsuite/gcc.target/i386/i386.exp.jj 2011-09-02 16:29:23.000000000 +0200 +++ gcc/testsuite/gcc.target/i386/i386.exp 2012-05-12 11:04:07.212795468 +0200 @@ -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" --- gcc/testsuite/gcc.target/i386/rtm-check.h.jj 2012-05-12 15:56:56.201185071 +0200 +++ gcc/testsuite/gcc.target/i386/rtm-check.h 2012-05-12 16:00:35.704909163 +0200 @@ -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; +} --- gcc/testsuite/gcc.target/i386/pr53315.c.jj 2012-05-12 10:57:51.886971582 +0200 +++ gcc/testsuite/gcc.target/i386/pr53315.c 2012-05-12 16:02:08.493369397 +0200 @@ -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 (); +} Jakub