Blame SOURCES/gcc48-pr67281.patch

25c7f1
2015-10-14  Peter Bergner  <bergner@vnet.ibm.com>
25c7f1
	    Torvald Riegel  <triegel@redhat.com>
25c7f1
25c7f1
	PR target/67281
25c7f1
	* config/rs6000/htm.md (UNSPEC_HTM_FENCE): New.
25c7f1
	(tabort, tabort<wd>c, tabort<wd>ci, tbegin, tcheck, tend,
25c7f1
	trechkpt, treclaim, tsr, ttest): Rename define_insns from this...
25c7f1
	(*tabort, *tabort<wd>c, *tabort<wd>ci, *tbegin, *tcheck, *tend,
25c7f1
	*trechkpt, *treclaim, *tsr, *ttest): ...to this.  Add memory barrier.
25c7f1
	(tabort, tabort<wd>c, tabort<wd>ci, tbegin, tcheck, tend,
25c7f1
	trechkpt, treclaim, tsr, ttest): New define_expands.
25c7f1
	* config/rs6000/rs6000-c.c (rs6000_target_modify_macros): Define
25c7f1
	__TM_FENCE__ for htm.
25c7f1
	* doc/extend.texi: Update documentation for htm builtins.
25c7f1
25c7f1
2015-08-03  Peter Bergner  <bergner@vnet.ibm.com>
25c7f1
25c7f1
	* config/rs6000/htm.md (tabort.): Restrict the source operand to
25c7f1
	using a base register.
25c7f1
25c7f1
	* gcc.target/powerpc/htm-tabort-no-r0.c: New test.
25c7f1
25c7f1
--- gcc/doc/extend.texi	(revision 228826)
25c7f1
+++ gcc/doc/extend.texi	(revision 228827)
25c7f1
@@ -16092,6 +16092,28 @@ unsigned int __builtin_tresume (void)
25c7f1
 unsigned int __builtin_tsuspend (void)
25c7f1
 @end smallexample
25c7f1
 
25c7f1
+Note that the semantics of the above HTM builtins are required to mimic
25c7f1
+the locking semantics used for critical sections.  Builtins that are used
25c7f1
+to create a new transaction or restart a suspended transaction must have
25c7f1
+lock acquisition like semantics while those builtins that end or suspend a
25c7f1
+transaction must have lock release like semantics.  Specifically, this must
25c7f1
+mimic lock semantics as specified by C++11, for example: Lock acquisition is
25c7f1
+as-if an execution of __atomic_exchange_n(&globallock,1,__ATOMIC_ACQUIRE)
25c7f1
+that returns 0, and lock release is as-if an execution of
25c7f1
+__atomic_store(&globallock,0,__ATOMIC_RELEASE), with globallock being an
25c7f1
+implicit implementation-defined lock used for all transactions.  The HTM
25c7f1
+instructions associated with with the builtins inherently provide the
25c7f1
+correct acquisition and release hardware barriers required.  However,
25c7f1
+the compiler must also be prohibited from moving loads and stores across
25c7f1
+the builtins in a way that would violate their semantics.  This has been
25c7f1
+accomplished by adding memory barriers to the associated HTM instructions
25c7f1
+(which is a conservative approach to provide acquire and release semantics).
25c7f1
+Earlier versions of the compiler did not treat the HTM instructions as
25c7f1
+memory barriers.  A @code{__TM_FENCE__} macro has been added, which can
25c7f1
+be used to determine whether the current compiler treats HTM instructions
25c7f1
+as memory barriers or not.  This allows the user to explicitly add memory
25c7f1
+barriers to their code when using an older version of the compiler.
25c7f1
+
25c7f1
 The following set of built-in functions are available to gain access
25c7f1
 to the HTM specific special purpose registers.
25c7f1
 
25c7f1
--- gcc/config/rs6000/htm.md	(revision 226531)
25c7f1
+++ gcc/config/rs6000/htm.md	(revision 228827)
25c7f1
@@ -27,6 +27,14 @@ (define_constants
25c7f1
   ])
25c7f1
 
25c7f1
 ;;
25c7f1
+;; UNSPEC usage
25c7f1
+;;
25c7f1
+
25c7f1
+(define_c_enum "unspec"
25c7f1
+  [UNSPEC_HTM_FENCE
25c7f1
+  ])
25c7f1
+
25c7f1
+;;
25c7f1
 ;; UNSPEC_VOLATILE usage
25c7f1
 ;;
25c7f1
 
25c7f1
@@ -45,96 +53,223 @@ (define_c_enum "unspecv"
25c7f1
    UNSPECV_HTM_MTSPR
25c7f1
   ])
25c7f1
 
25c7f1
+(define_expand "tabort"
25c7f1
+  [(parallel
25c7f1
+     [(set (match_operand:CC 1 "cc_reg_operand" "=x")
25c7f1
+	   (unspec_volatile:CC [(match_operand:SI 0 "base_reg_operand" "b")]
25c7f1
+			       UNSPECV_HTM_TABORT))
25c7f1
+      (set (match_dup 2) (unspec:BLK [(match_dup 2)] UNSPEC_HTM_FENCE))])]
25c7f1
+  "TARGET_HTM"
25c7f1
+{
25c7f1
+  operands[2] = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (Pmode));
25c7f1
+  MEM_VOLATILE_P (operands[2]) = 1;
25c7f1
+})
25c7f1
 
25c7f1
-(define_insn "tabort"
25c7f1
+(define_insn "*tabort"
25c7f1
   [(set (match_operand:CC 1 "cc_reg_operand" "=x")
25c7f1
-	(unspec_volatile:CC [(match_operand:SI 0 "gpc_reg_operand" "r")]
25c7f1
-			    UNSPECV_HTM_TABORT))]
25c7f1
+	(unspec_volatile:CC [(match_operand:SI 0 "base_reg_operand" "b")]
25c7f1
+			    UNSPECV_HTM_TABORT))
25c7f1
+   (set (match_operand:BLK 2) (unspec:BLK [(match_dup 2)] UNSPEC_HTM_FENCE))]
25c7f1
   "TARGET_HTM"
25c7f1
   "tabort. %0"
25c7f1
   [(set_attr "type" "htm")
25c7f1
    (set_attr "length" "4")])
25c7f1
 
25c7f1
-(define_insn "tabort<wd>c"
25c7f1
+(define_expand "tabort<wd>c"
25c7f1
+  [(parallel
25c7f1
+     [(set (match_operand:CC 3 "cc_reg_operand" "=x")
25c7f1
+	   (unspec_volatile:CC [(match_operand 0 "u5bit_cint_operand" "n")
25c7f1
+				(match_operand:GPR 1 "gpc_reg_operand" "r")
25c7f1
+				(match_operand:GPR 2 "gpc_reg_operand" "r")]
25c7f1
+			       UNSPECV_HTM_TABORTXC))
25c7f1
+      (set (match_dup 4) (unspec:BLK [(match_dup 4)] UNSPEC_HTM_FENCE))])]
25c7f1
+  "TARGET_HTM"
25c7f1
+{
25c7f1
+  operands[4] = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (Pmode));
25c7f1
+  MEM_VOLATILE_P (operands[4]) = 1;
25c7f1
+})
25c7f1
+
25c7f1
+(define_insn "*tabort<wd>c"
25c7f1
   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
25c7f1
 	(unspec_volatile:CC [(match_operand 0 "u5bit_cint_operand" "n")
25c7f1
 			     (match_operand:GPR 1 "gpc_reg_operand" "r")
25c7f1
 			     (match_operand:GPR 2 "gpc_reg_operand" "r")]
25c7f1
-			    UNSPECV_HTM_TABORTXC))]
25c7f1
+			    UNSPECV_HTM_TABORTXC))
25c7f1
+   (set (match_operand:BLK 4) (unspec:BLK [(match_dup 4)] UNSPEC_HTM_FENCE))]
25c7f1
   "TARGET_HTM"
25c7f1
   "tabort<wd>c. %0,%1,%2"
25c7f1
   [(set_attr "type" "htm")
25c7f1
    (set_attr "length" "4")])
25c7f1
 
25c7f1
-(define_insn "tabort<wd>ci"
25c7f1
+(define_expand "tabort<wd>ci"
25c7f1
+  [(parallel
25c7f1
+     [(set (match_operand:CC 3 "cc_reg_operand" "=x")
25c7f1
+	   (unspec_volatile:CC [(match_operand 0 "u5bit_cint_operand" "n")
25c7f1
+				(match_operand:GPR 1 "gpc_reg_operand" "r")
25c7f1
+				(match_operand 2 "s5bit_cint_operand" "n")]
25c7f1
+			       UNSPECV_HTM_TABORTXCI))
25c7f1
+      (set (match_dup 4) (unspec:BLK [(match_dup 4)] UNSPEC_HTM_FENCE))])]
25c7f1
+  "TARGET_HTM"
25c7f1
+{
25c7f1
+  operands[4] = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (Pmode));
25c7f1
+  MEM_VOLATILE_P (operands[4]) = 1;
25c7f1
+})
25c7f1
+
25c7f1
+(define_insn "*tabort<wd>ci"
25c7f1
   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
25c7f1
 	(unspec_volatile:CC [(match_operand 0 "u5bit_cint_operand" "n")
25c7f1
 			     (match_operand:GPR 1 "gpc_reg_operand" "r")
25c7f1
 			     (match_operand 2 "s5bit_cint_operand" "n")]
25c7f1
-			    UNSPECV_HTM_TABORTXCI))]
25c7f1
+			    UNSPECV_HTM_TABORTXCI))
25c7f1
+   (set (match_operand:BLK 4) (unspec:BLK [(match_dup 4)] UNSPEC_HTM_FENCE))]
25c7f1
   "TARGET_HTM"
25c7f1
   "tabort<wd>ci. %0,%1,%2"
25c7f1
   [(set_attr "type" "htm")
25c7f1
    (set_attr "length" "4")])
25c7f1
 
25c7f1
-(define_insn "tbegin"
25c7f1
+(define_expand "tbegin"
25c7f1
+  [(parallel
25c7f1
+     [(set (match_operand:CC 1 "cc_reg_operand" "=x")
25c7f1
+	   (unspec_volatile:CC [(match_operand 0 "const_0_to_1_operand" "n")]
25c7f1
+			       UNSPECV_HTM_TBEGIN))
25c7f1
+      (set (match_dup 2) (unspec:BLK [(match_dup 2)] UNSPEC_HTM_FENCE))])]
25c7f1
+  "TARGET_HTM"
25c7f1
+{
25c7f1
+  operands[2] = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (Pmode));
25c7f1
+  MEM_VOLATILE_P (operands[2]) = 1;
25c7f1
+})
25c7f1
+
25c7f1
+(define_insn "*tbegin"
25c7f1
   [(set (match_operand:CC 1 "cc_reg_operand" "=x")
25c7f1
 	(unspec_volatile:CC [(match_operand 0 "const_0_to_1_operand" "n")]
25c7f1
-			    UNSPECV_HTM_TBEGIN))]
25c7f1
+			    UNSPECV_HTM_TBEGIN))
25c7f1
+   (set (match_operand:BLK 2) (unspec:BLK [(match_dup 2)] UNSPEC_HTM_FENCE))]
25c7f1
   "TARGET_HTM"
25c7f1
   "tbegin. %0"
25c7f1
   [(set_attr "type" "htm")
25c7f1
    (set_attr "length" "4")])
25c7f1
 
25c7f1
-(define_insn "tcheck"
25c7f1
+(define_expand "tcheck"
25c7f1
+  [(parallel
25c7f1
+     [(set (match_operand:CC 0 "cc_reg_operand" "=y")
25c7f1
+	   (unspec_volatile:CC [(const_int 0)] UNSPECV_HTM_TCHECK))
25c7f1
+      (set (match_dup 1) (unspec:BLK [(match_dup 1)] UNSPEC_HTM_FENCE))])]
25c7f1
+  "TARGET_HTM"
25c7f1
+{
25c7f1
+  operands[1] = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (Pmode));
25c7f1
+  MEM_VOLATILE_P (operands[1]) = 1;
25c7f1
+})
25c7f1
+
25c7f1
+(define_insn "*tcheck"
25c7f1
   [(set (match_operand:CC 0 "cc_reg_operand" "=y")
25c7f1
-	(unspec_volatile:CC [(const_int 0)]
25c7f1
-			    UNSPECV_HTM_TCHECK))]
25c7f1
+	(unspec_volatile:CC [(const_int 0)] UNSPECV_HTM_TCHECK))
25c7f1
+   (set (match_operand:BLK 1) (unspec:BLK [(match_dup 1)] UNSPEC_HTM_FENCE))]
25c7f1
   "TARGET_HTM"
25c7f1
   "tcheck %0"
25c7f1
   [(set_attr "type" "htm")
25c7f1
    (set_attr "length" "4")])
25c7f1
 
25c7f1
-(define_insn "tend"
25c7f1
+(define_expand "tend"
25c7f1
+  [(parallel
25c7f1
+     [(set (match_operand:CC 1 "cc_reg_operand" "=x")
25c7f1
+	   (unspec_volatile:CC [(match_operand 0 "const_0_to_1_operand" "n")]
25c7f1
+			       UNSPECV_HTM_TEND))
25c7f1
+      (set (match_dup 2) (unspec:BLK [(match_dup 2)] UNSPEC_HTM_FENCE))])]
25c7f1
+  "TARGET_HTM"
25c7f1
+{
25c7f1
+  operands[2] = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (Pmode));
25c7f1
+  MEM_VOLATILE_P (operands[2]) = 1;
25c7f1
+})
25c7f1
+
25c7f1
+(define_insn "*tend"
25c7f1
   [(set (match_operand:CC 1 "cc_reg_operand" "=x")
25c7f1
 	(unspec_volatile:CC [(match_operand 0 "const_0_to_1_operand" "n")]
25c7f1
-			    UNSPECV_HTM_TEND))]
25c7f1
+			    UNSPECV_HTM_TEND))
25c7f1
+   (set (match_operand:BLK 2) (unspec:BLK [(match_dup 2)] UNSPEC_HTM_FENCE))]
25c7f1
   "TARGET_HTM"
25c7f1
   "tend. %0"
25c7f1
   [(set_attr "type" "htm")
25c7f1
    (set_attr "length" "4")])
25c7f1
 
25c7f1
-(define_insn "trechkpt"
25c7f1
+(define_expand "trechkpt"
25c7f1
+  [(parallel
25c7f1
+     [(set (match_operand:CC 0 "cc_reg_operand" "=x")
25c7f1
+	   (unspec_volatile:CC [(const_int 0)] UNSPECV_HTM_TRECHKPT))
25c7f1
+      (set (match_dup 1) (unspec:BLK [(match_dup 1)] UNSPEC_HTM_FENCE))])]
25c7f1
+  "TARGET_HTM"
25c7f1
+{
25c7f1
+  operands[1] = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (Pmode));
25c7f1
+  MEM_VOLATILE_P (operands[1]) = 1;
25c7f1
+})
25c7f1
+
25c7f1
+(define_insn "*trechkpt"
25c7f1
   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
25c7f1
-	(unspec_volatile:CC [(const_int 0)]
25c7f1
-			    UNSPECV_HTM_TRECHKPT))]
25c7f1
+	(unspec_volatile:CC [(const_int 0)] UNSPECV_HTM_TRECHKPT))
25c7f1
+   (set (match_operand:BLK 1) (unspec:BLK [(match_dup 1)] UNSPEC_HTM_FENCE))]
25c7f1
   "TARGET_HTM"
25c7f1
   "trechkpt."
25c7f1
   [(set_attr "type" "htm")
25c7f1
    (set_attr "length" "4")])
25c7f1
 
25c7f1
-(define_insn "treclaim"
25c7f1
+(define_expand "treclaim"
25c7f1
+  [(parallel
25c7f1
+     [(set (match_operand:CC 1 "cc_reg_operand" "=x")
25c7f1
+	   (unspec_volatile:CC [(match_operand:SI 0 "gpc_reg_operand" "r")]
25c7f1
+			       UNSPECV_HTM_TRECLAIM))
25c7f1
+      (set (match_dup 2) (unspec:BLK [(match_dup 2)] UNSPEC_HTM_FENCE))])]
25c7f1
+  "TARGET_HTM"
25c7f1
+{
25c7f1
+  operands[2] = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (Pmode));
25c7f1
+  MEM_VOLATILE_P (operands[2]) = 1;
25c7f1
+})
25c7f1
+
25c7f1
+(define_insn "*treclaim"
25c7f1
   [(set (match_operand:CC 1 "cc_reg_operand" "=x")
25c7f1
 	(unspec_volatile:CC [(match_operand:SI 0 "gpc_reg_operand" "r")]
25c7f1
-			    UNSPECV_HTM_TRECLAIM))]
25c7f1
+			    UNSPECV_HTM_TRECLAIM))
25c7f1
+   (set (match_operand:BLK 2) (unspec:BLK [(match_dup 2)] UNSPEC_HTM_FENCE))]
25c7f1
   "TARGET_HTM"
25c7f1
   "treclaim. %0"
25c7f1
   [(set_attr "type" "htm")
25c7f1
    (set_attr "length" "4")])
25c7f1
 
25c7f1
-(define_insn "tsr"
25c7f1
+(define_expand "tsr"
25c7f1
+  [(parallel
25c7f1
+     [(set (match_operand:CC 1 "cc_reg_operand" "=x")
25c7f1
+	   (unspec_volatile:CC [(match_operand 0 "const_0_to_1_operand" "n")]
25c7f1
+			       UNSPECV_HTM_TSR))
25c7f1
+      (set (match_dup 2) (unspec:BLK [(match_dup 2)] UNSPEC_HTM_FENCE))])]
25c7f1
+  "TARGET_HTM"
25c7f1
+{
25c7f1
+  operands[2] = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (Pmode));
25c7f1
+  MEM_VOLATILE_P (operands[2]) = 1;
25c7f1
+})
25c7f1
+
25c7f1
+(define_insn "*tsr"
25c7f1
   [(set (match_operand:CC 1 "cc_reg_operand" "=x")
25c7f1
 	(unspec_volatile:CC [(match_operand 0 "const_0_to_1_operand" "n")]
25c7f1
-			    UNSPECV_HTM_TSR))]
25c7f1
+			    UNSPECV_HTM_TSR))
25c7f1
+   (set (match_operand:BLK 2) (unspec:BLK [(match_dup 2)] UNSPEC_HTM_FENCE))]
25c7f1
   "TARGET_HTM"
25c7f1
   "tsr. %0"
25c7f1
   [(set_attr "type" "htm")
25c7f1
    (set_attr "length" "4")])
25c7f1
 
25c7f1
-(define_insn "ttest"
25c7f1
+(define_expand "ttest"
25c7f1
+  [(parallel
25c7f1
+     [(set (match_operand:CC 0 "cc_reg_operand" "=x")
25c7f1
+	   (unspec_volatile:CC [(const_int 0)] UNSPECV_HTM_TTEST))
25c7f1
+      (set (match_dup 1) (unspec:BLK [(match_dup 1)] UNSPEC_HTM_FENCE))])]
25c7f1
+  "TARGET_HTM"
25c7f1
+{
25c7f1
+  operands[1] = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (Pmode));
25c7f1
+  MEM_VOLATILE_P (operands[1]) = 1;
25c7f1
+})
25c7f1
+
25c7f1
+(define_insn "*ttest"
25c7f1
   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
25c7f1
-	(unspec_volatile:CC [(const_int 0)]
25c7f1
-			    UNSPECV_HTM_TTEST))]
25c7f1
+	(unspec_volatile:CC [(const_int 0)] UNSPECV_HTM_TTEST))
25c7f1
+   (set (match_operand:BLK 1) (unspec:BLK [(match_dup 1)] UNSPEC_HTM_FENCE))]
25c7f1
   "TARGET_HTM"
25c7f1
   "tabortwci. 0,1,0"
25c7f1
   [(set_attr "type" "htm")
25c7f1
--- gcc/config/rs6000/rs6000-c.c	(revision 228826)
25c7f1
+++ gcc/config/rs6000/rs6000-c.c	(revision 228827)
25c7f1
@@ -372,7 +372,11 @@ rs6000_target_modify_macros (bool define
25c7f1
   if ((flags & OPTION_MASK_VSX) != 0)
25c7f1
     rs6000_define_or_undefine_macro (define_p, "__VSX__");
25c7f1
   if ((flags & OPTION_MASK_HTM) != 0)
25c7f1
-    rs6000_define_or_undefine_macro (define_p, "__HTM__");
25c7f1
+    {
25c7f1
+      rs6000_define_or_undefine_macro (define_p, "__HTM__");
25c7f1
+      /* Tell the user that our HTM insn patterns act as memory barriers.  */
25c7f1
+      rs6000_define_or_undefine_macro (define_p, "__TM_FENCE__");
25c7f1
+    }
25c7f1
   if ((flags & OPTION_MASK_P8_VECTOR) != 0)
25c7f1
     rs6000_define_or_undefine_macro (define_p, "__POWER8_VECTOR__");
25c7f1
   if ((flags & OPTION_MASK_QUAD_MEMORY) != 0)
25c7f1
--- gcc/testsuite/gcc.target/powerpc/htm-tabort-no-r0.c	(revision 0)
25c7f1
+++ gcc/testsuite/gcc.target/powerpc/htm-tabort-no-r0.c	(revision 226532)
25c7f1
@@ -0,0 +1,12 @@
25c7f1
+/* { dg-do compile { target { powerpc*-*-* } } } */
25c7f1
+/* { dg-skip-if "" { powerpc*-*-darwin* } { "*" } { "" } } */
25c7f1
+/* { dg-require-effective-target powerpc_htm_ok } */
25c7f1
+/* { dg-options "-O2 -mhtm -ffixed-r3 -ffixed-r4 -ffixed-r5 -ffixed-r6 -ffixed-r7 -ffixed-r8 -ffixed-r9 -ffixed-r10 -ffixed-r11 -ffixed-r12" } */
25c7f1
+
25c7f1
+/* { dg-final { scan-assembler-not "tabort\\.\[ \t\]0" } } */
25c7f1
+
25c7f1
+int
25c7f1
+foo (void)
25c7f1
+{
25c7f1
+  return __builtin_tabort (10);
25c7f1
+}