This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: PATCH: PR target/53315: simple xtest program generates ICE


On Fri, May 11, 2012 at 11:16:08AM -0700, H.J. Lu wrote:
> This patch uses + in constraint and match_dup in xbegin_1.  OK for
> trunk?

The patch is buggy, xbegin expander leaves operands[0] uninitialized.
Fixed thusly, untested on rtm hw though:

2012-05-12  Andrew Pinski  <apinski@cavium.com>
	    H.J. Lu  <hongjiu.lu@intel.com>
	    Jakub Jelinek  <jakub@redhat.com>

	PR target/53315
	* config/i386/i386.md (xbegin_1): Use + in constraint and
	match_dup.
	(xbegin): Updated.

2012-05-12  Andi Kleen <ak@linux.intel.com>
	    Jakub Jelinek  <jakub@redhat.com>

	PR target/53315
	* gcc.target/i386/i386.exp (check_effective_target_rtm): New.
	* 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/pr53315.c.jj	2012-05-12 10:57:51.886971582 +0200
+++ gcc/testsuite/gcc.target/i386/pr53315.c	2012-05-12 11:04:43.776579236 +0200
@@ -0,0 +1,45 @@
+/* PR target/53315 and PR target/53291 */
+/* { dg-do run } */
+/* { dg-options "-O2 -mrtm" } */
+/* { dg-require-effective-target rtm } */
+
+#include <x86intrin.h>
+#include "cpuid.h"
+
+extern void abort (void);
+
+static int
+cpu_has_rtm (void)
+{
+  if (__get_cpuid_max (0, NULL) >= 7)
+    {
+      unsigned a, b, c, d;
+      __cpuid_count (7, 0, a, b, c, d);
+      return ! !(b & bit_RTM);
+    }
+  return 0;
+}
+
+int
+main ()
+{
+  int flag = -1;
+  unsigned status;
+
+  if (!cpu_has_rtm ())
+    return 0;
+
+  if ((status = _xbegin ()) == _XBEGIN_STARTED)
+    {
+      flag = _xtest ();
+      _xend ();
+    }
+  else
+    return 0;
+
+  if (flag != 1)
+    abort ();
+  if (_xtest () != 0)
+    abort ();
+  return 0;
+}


	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]