Blame SOURCES/gcc34-pr21412.patch

6693b3
2005-05-07  Richard Henderson  <rth@redhat.com>
6693b3
6693b3
	PR target/21412
6693b3
	* config/rs6000/rs6000.c (rs6000_emit_move): Look for tls addresses
6693b3
	with constant offsets.
6693b3
6693b3
2004-07-11  Ulrich Weigand  <uweigand@de.ibm.com>
6693b3
6693b3
	* config/s390/s390.c (legitimize_tls_address): Handle constant offsets
6693b3
	added to TLS symbol addresses.
6693b3
6693b3
2004-07-06  Richard Henderson  <rth@redhat.com>
6693b3
6693b3
	* config/i386/i386.c (legitimize_address): Handle CONST with TLS
6693b3
	operand.
6693b3
	(ix86_expand_move): Don't call legitimize_pic_address directly.
6693b3
6693b3
2006-05-05  Jakub Jelinek  <jakub@redhat.com>
6693b3
6693b3
	* gcc.dg/tls/opt-12.c: New test.
6693b3
6693b3
--- gcc/config/s390/s390.c	(revision 84404)
6693b3
+++ gcc/config/s390/s390.c	(revision 84535)
6693b3
@@ -2913,6 +2913,18 @@ legitimize_tls_address (rtx addr, rtx re
6693b3
 	}
6693b3
     }
6693b3
 
6693b3
+  else if (GET_CODE (addr) == CONST && GET_CODE (XEXP (addr, 0)) == PLUS
6693b3
+	   && GET_CODE (XEXP (XEXP (addr, 0), 1)) == CONST_INT)
6693b3
+    {
6693b3
+      new = XEXP (XEXP (addr, 0), 0);
6693b3
+      if (GET_CODE (new) != SYMBOL_REF)
6693b3
+	new = gen_rtx_CONST (Pmode, new);
6693b3
+
6693b3
+      new = legitimize_tls_address (new, reg);
6693b3
+      new = plus_constant (new, INTVAL (XEXP (XEXP (addr, 0), 1)));
6693b3
+      new = force_operand (new, 0);
6693b3
+    }
6693b3
+
6693b3
   else
6693b3
     abort ();  /* for now ... */
6693b3
 
6693b3
--- gcc/config/i386/i386.c	2005-11-21 14:56:49.000000000 +0100
6693b3
+++ gcc/config/i386/i386.c	2006-05-05 11:21:54.000000000 +0200
6693b3
@@ -6604,6 +6604,13 @@ legitimize_address (rtx x, rtx oldx ATTR
6693b3
   log = tls_symbolic_operand (x, mode);
6693b3
   if (log)
6693b3
     return legitimize_tls_address (x, log, false);
6693b3
+  if (GET_CODE (x) == CONST
6693b3
+      && GET_CODE (XEXP (x, 0)) == PLUS
6693b3
+      && (log = tls_symbolic_operand (XEXP (XEXP (x, 0), 0), Pmode)))
6693b3
+    {
6693b3
+      rtx t = legitimize_tls_address (XEXP (XEXP (x, 0), 0), log, false);
6693b3
+      return gen_rtx_PLUS (Pmode, t, XEXP (XEXP (x, 0), 1));
6693b3
+    }
6693b3
 
6693b3
   if (flag_pic && SYMBOLIC_CONST (x))
6693b3
     return legitimize_pic_address (x, 0);
6693b3
@@ -8395,6 +8402,10 @@ ix86_expand_move (enum machine_mode mode
6693b3
 #else
6693b3
       if (GET_CODE (op0) == MEM)
6693b3
 	op1 = force_reg (Pmode, op1);
6693b3
+      else if (GET_CODE (op1) == CONST
6693b3
+	       && GET_CODE (XEXP (op1, 0)) == PLUS
6693b3
+	       && tls_symbolic_operand (XEXP (XEXP (op1, 0), 0), Pmode))
6693b3
+	op1 = legitimize_address (op1, op1, Pmode);
6693b3
       else
6693b3
 	{
6693b3
 	  rtx temp = op0;
6693b3
--- gcc/config/rs6000/rs6000.c	(revision 99334)
6693b3
+++ gcc/config/rs6000/rs6000.c	(revision 99367)
6693b3
@@ -4436,11 +4436,31 @@ rs6000_emit_move (rtx dest, rtx source, 
6693b3
 
6693b3
   /* Recognize the case where operand[1] is a reference to thread-local
6693b3
      data and load its address to a register.  */
6693b3
-  if (GET_CODE (operands[1]) == SYMBOL_REF)
6693b3
+  if (rs6000_tls_referenced_p (operands[1]))
6693b3
     {
6693b3
-      enum tls_model model = SYMBOL_REF_TLS_MODEL (operands[1]);
6693b3
-      if (model != 0)
6693b3
-	operands[1] = rs6000_legitimize_tls_address (operands[1], model);
6693b3
+      enum tls_model model;
6693b3
+      rtx tmp = operands[1];
6693b3
+      rtx addend = NULL;
6693b3
+
6693b3
+      if (GET_CODE (tmp) == CONST && GET_CODE (XEXP (tmp, 0)) == PLUS)
6693b3
+	{
6693b3
+          addend = XEXP (XEXP (tmp, 0), 1);
6693b3
+	  tmp = XEXP (XEXP (tmp, 0), 0);
6693b3
+	}
6693b3
+
6693b3
+      if (GET_CODE (tmp) != SYMBOL_REF)
6693b3
+	abort ();
6693b3
+      model = SYMBOL_REF_TLS_MODEL (tmp);
6693b3
+      if (model == 0)
6693b3
+	abort ();
6693b3
+
6693b3
+      tmp = rs6000_legitimize_tls_address (tmp, model);
6693b3
+      if (addend)
6693b3
+	{
6693b3
+	  tmp = gen_rtx_PLUS (mode, tmp, addend);
6693b3
+	  tmp = force_operand (tmp, operands[0]);
6693b3
+	}
6693b3
+      operands[1] = tmp;
6693b3
     }
6693b3
 
6693b3
   /* Handle the case where reload calls us with an invalid address.  */
6693b3
--- gcc/testsuite/gcc.dg/tls/opt-9.c	(revision 0)
6693b3
+++ gcc/testsuite/gcc.dg/tls/opt-9.c	(revision 99367)
6693b3
@@ -0,0 +1,7 @@
6693b3
+/* PR 21412 */
6693b3
+/* { dg-do compile */
6693b3
+/* { dg-options "-O2 -fPIC" } */
6693b3
+
6693b3
+struct S { int x[10]; };
6693b3
+extern __thread struct S s;
6693b3
+int *foo() { return &s.x[2]; }
6693b3
--- gcc/testsuite/gcc.dg/tls/opt-12.c	2006-04-19 19:21:31.748476000 +0200
6693b3
+++ gcc/testsuite/gcc.dg/tls/opt-12.c	2006-05-05 11:01:33.000000000 +0200
6693b3
@@ -0,0 +1,16 @@
6693b3
+/* { dg-do compile } */
6693b3
+/* { dg-options "-O2" } */
6693b3
+/* { XXdgXX-require-effective-target tls } */
6693b3
+
6693b3
+__thread struct
6693b3
+{
6693b3
+  int a;
6693b3
+  char b[32];
6693b3
+} thr;
6693b3
+
6693b3
+int
6693b3
+main ()
6693b3
+{
6693b3
+  __builtin_strcpy (thr.b, "abcd");
6693b3
+  return 0;
6693b3
+}