https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81490

--- Comment #15 from Uroš Bizjak <ubizjak at gmail dot com> ---
I'm testing the following patch:

--cut here--
Index: i386.c
===================================================================
--- i386.c      (revision 250745)
+++ i386.c      (working copy)
@@ -19421,8 +19421,10 @@ ix86_print_operand_address_as (FILE *file, rtx add
       fputs (string, file);
     }

-  /* Use one byte shorter RIP relative addressing for 64bit mode.  */
-  if (TARGET_64BIT && !base && !index && !no_rip)
+  /* Use one byte shorter RIP relative addressing for
+     symbols in the generic address space.  */
+  if (TARGET_64BIT && !base && !index
+      && ADDR_SPACE_GENERIC_P (as) && !no_rip)
     {
       rtx symbol = disp;

@@ -19442,7 +19444,7 @@ ix86_print_operand_address_as (FILE *file, rtx add
       /* Displacement only requires special attention.  */
       if (CONST_INT_P (disp))
        {
-         if (ASSEMBLER_DIALECT == ASM_INTEL && parts.seg ==
ADDR_SPACE_GENERIC)
+         if (ASSEMBLER_DIALECT == ASM_INTEL && ADDR_SPACE_GENERIC_P (as))
            fputs ("ds:", file);
          fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (disp));
        }
--cut here--

The patched compiler compiles following testcase:

--cut here--
int __seg_gs a;

void test_as (void)
{
  a += 1;
}

__thread int b;

void test_thr (void)
{
  b += 2;
}
--cut here--

to:

test_as:
        addl    $1, %gs:a
        ret

test_thr:
        addl    $2, %fs:b@tpoff
        ret

Reply via email to