Blame SOURCES/gcc48-pr67281.patch

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