]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR target/66470 (TLS ICE due to ix86_split_long_move)
authorJakub Jelinek <jakub@redhat.com>
Wed, 10 Jun 2015 09:34:21 +0000 (11:34 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Wed, 10 Jun 2015 09:34:21 +0000 (11:34 +0200)
PR target/66470
* config/i386/i386.c (ix86_split_long_move): For collisions
involving direct tls segment refs, move the UNSPEC_TP possibly
wrapped in ZERO_EXTEND out of the address for lea, to each of
the memory loads.

* gcc.dg/tls/pr66470.c: New test.
* gcc.target/i386/pr66470.c: New test.

From-SVN: r224322

gcc/ChangeLog
gcc/config/i386/i386.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/tls/pr66470.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/pr66470.c [new file with mode: 0644]

index 1f6492fee294e9e7e6fe10771cf8862e6cd5da02..80c4ee859c0dc1430a5bf979ce3b52160acba412 100644 (file)
@@ -1,3 +1,11 @@
+2015-06-10  Jakub Jelinek  <jakub@redhat.com>
+
+       PR target/66470
+       * config/i386/i386.c (ix86_split_long_move): For collisions
+       involving direct tls segment refs, move the UNSPEC_TP possibly
+       wrapped in ZERO_EXTEND out of the address for lea, to each of
+       the memory loads.
+
 2015-06-08  Uros Bizjak  <ubizjak@gmail.com>
 
        Backport from mainline:
index c2d0c5fae79551d34be6bf71e8fea3e0aa1022ab..40dec967ce80e4bc312f58e7600b4de1cd2f8365 100644 (file)
@@ -21214,7 +21214,7 @@ ix86_split_long_move (rtx operands[])
         Do an lea to the last part and use only one colliding move.  */
       else if (collisions > 1)
        {
-         rtx base;
+         rtx base, addr, tls_base = NULL_RTX;
 
          collisions = 1;
 
@@ -21225,10 +21225,50 @@ ix86_split_long_move (rtx operands[])
          if (GET_MODE (base) != Pmode)
            base = gen_rtx_REG (Pmode, REGNO (base));
 
-         emit_insn (gen_rtx_SET (VOIDmode, base, XEXP (part[1][0], 0)));
+         addr = XEXP (part[1][0], 0);
+         if (TARGET_TLS_DIRECT_SEG_REFS)
+           {
+             struct ix86_address parts;
+             int ok = ix86_decompose_address (addr, &parts);
+             gcc_assert (ok);
+             if (parts.seg != SEG_DEFAULT)
+               {
+                 /* It is not valid to use %gs: or %fs: in
+                    lea though, so we need to remove it from the
+                    address used for lea and add it to each individual
+                    memory loads instead.  */
+                 addr = copy_rtx (addr);
+                 rtx *x = &addr;
+                 while (GET_CODE (*x) == PLUS)
+                   {
+                     for (i = 0; i < 2; i++)
+                       {
+                         rtx u = XEXP (*x, i);
+                         if (GET_CODE (u) == ZERO_EXTEND)
+                           u = XEXP (u, 0);
+                         if (GET_CODE (u) == UNSPEC
+                             && XINT (u, 1) == UNSPEC_TP)
+                           {
+                             tls_base = XEXP (*x, i);
+                             *x = XEXP (*x, 1 - i);
+                             break;
+                           }
+                       }
+                     if (tls_base)
+                       break;
+                     x = &XEXP (*x, 0);
+                   }
+                 gcc_assert (tls_base);
+               }
+           }
+         emit_insn (gen_rtx_SET (VOIDmode, base, addr));
+         if (tls_base)
+           base = gen_rtx_PLUS (GET_MODE (base), base, tls_base);
          part[1][0] = replace_equiv_address (part[1][0], base);
          for (i = 1; i < nparts; i++)
            {
+             if (tls_base)
+               base = copy_rtx (base);
              tmp = plus_constant (Pmode, base, UNITS_PER_WORD * i);
              part[1][i] = replace_equiv_address (part[1][i], tmp);
            }
index 576bcb30cbc75ce8204d9485717fbe18b591f153..9bda3339c2e2ff85edede91c609266086aaeb5da 100644 (file)
@@ -1,3 +1,9 @@
+2015-06-10  Jakub Jelinek  <jakub@redhat.com>
+
+       PR target/66470
+       * gcc.dg/tls/pr66470.c: New test.
+       * gcc.target/i386/pr66470.c: New test.
+
 2015-06-08  Uros Bizjak  <ubizjak@gmail.com>
 
        Backport from mainline:
diff --git a/gcc/testsuite/gcc.dg/tls/pr66470.c b/gcc/testsuite/gcc.dg/tls/pr66470.c
new file mode 100644 (file)
index 0000000..6d78327
--- /dev/null
@@ -0,0 +1,29 @@
+/* PR target/66470 */
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+/* { dg-require-effective-target tls } */
+
+extern __thread unsigned long long a[10];
+extern __thread struct S { int a, b; } b[10];
+
+unsigned long long
+foo (long x)
+{
+  return a[x];
+}
+
+struct S
+bar (long x)
+{
+  return b[x];
+}
+
+#ifdef __SIZEOF_INT128__
+extern __thread unsigned __int128 c[10];
+
+unsigned __int128
+baz (long x)
+{
+  return c[x];
+}
+#endif
diff --git a/gcc/testsuite/gcc.target/i386/pr66470.c b/gcc/testsuite/gcc.target/i386/pr66470.c
new file mode 100644 (file)
index 0000000..73158d1
--- /dev/null
@@ -0,0 +1,13 @@
+/* PR target/66470 */
+/* { dg-do compile { target { ! { ia32 } } } } */
+/* { dg-options "-O2 -mx32 -maddress-mode=long" } */
+/* { dg-require-effective-target tls } */
+
+extern __thread unsigned __int128 c[10];
+int d;
+
+unsigned __int128
+foo (void)
+{
+  return c[d];
+}