Blame SOURCES/gcc48-pr67281.patch

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