>
> My ia32 change generates much worse code:
>
> [hjl@gnu-6 gcc]$ cat /tmp/c.i
> static __thread char ccc, bbb;
>
> int __cxa_get_globals()
> {
>  return &ccc - &bbb;
> }
> [hjl@gnu-6 gcc]$ ./xgcc -B./ -S -O2 -fPIC /tmp/c.i
> [hjl@gnu-6 gcc]$ cat c.s
> .file "c.i"
> .section .text.unlikely,"ax",@progbits
> .LCOLDB0:
> .text
> .LHOTB0:
> .p2align 4,,15
> .globl __cxa_get_globals
> .type __cxa_get_globals, @function
> __cxa_get_globals:
> .LFB0:
> .cfi_startproc
> subq $8, %rsp
> .cfi_def_cfa_offset 16
> leaq ccc@tlsld(%rip), %rdi
> call __tls_get_addr@PLT
> addq $8, %rsp
> .cfi_def_cfa_offset 8
> leaq ccc@dtpoff(%rax), %rcx
> leaq bbb@dtpoff(%rax), %rdx
> movq %rcx, %rax
> subq %rdx, %rax
> ret
> .cfi_endproc
> .LFE0:
> .size __cxa_get_globals, .-__cxa_get_globals
> .section .text.unlikely
> .LCOLDE0:
> .text
> .LHOTE0:
> .section .tbss,"awT",@nobits
> .type bbb, @object
> .size bbb, 1
> bbb:
> .zero 1
> .type ccc, @object
> .size ccc, 1
> ccc:
> .zero 1
> .ident "GCC: (GNU) 4.9.0 20140312 (experimental)"
> .section .note.GNU-stack,"",@progbits
> [hjl@gnu-6 gcc]$ cat /tmp/c.i
> static __thread char ccc, bbb;
>
> int __cxa_get_globals()
> {
>  return &ccc - &bbb;
> }
> [hjl@gnu-6 gcc]$ ./xgcc -B./ -S -O2 -fPIC /tmp/c.i -m32
> [hjl@gnu-6 gcc]$ cat c.s
> .file "c.i"
> .section .text.unlikely,"ax",@progbits
> .LCOLDB0:
> .text
> .LHOTB0:
> .p2align 4,,15
> .globl __cxa_get_globals
> .type __cxa_get_globals, @function
> __cxa_get_globals:
> .LFB0:
> .cfi_startproc
> pushl %esi
> .cfi_def_cfa_offset 8
> .cfi_offset 6, -8
> pushl %ebx
> .cfi_def_cfa_offset 12
> .cfi_offset 3, -12
> call __x86.get_pc_thunk.bx
> addl $_GLOBAL_OFFSET_TABLE_, %ebx
> subl $4, %esp
> .cfi_def_cfa_offset 16
> leal ccc@tlsldm(%ebx), %eax
> call ___tls_get_addr@PLT
> leal ccc@dtpoff(%eax), %esi
> leal ccc@tlsldm(%ebx), %eax
> call ___tls_get_addr@PLT
> addl $4, %esp
> .cfi_def_cfa_offset 12
> leal bbb@dtpoff(%eax), %eax
> popl %ebx
> .cfi_restore 3
> .cfi_def_cfa_offset 8
> subl %eax, %esi
> movl %esi, %eax
> popl %esi
> .cfi_restore 6
> .cfi_def_cfa_offset 4
> ret
> .cfi_endproc
>
> Maybe we should keep the original patterns and
> split them to add CALL.
>
> --
> H.J.

I tried pr58066-3.patch on the above testcase, the code it generated
seems ok. I think after we change the 32bits pattern in i386.md to be
similar as 64bits pattern, we should change 32bit expand to be similar
as 64bit expand in legitimize_tls_address too?

Thanks,
Wei.

~/workarea/gcc-r208410-2/build/install/bin/gcc -m32 -S -fPIC 1.c

        .file   "1.c"
        .section        .tbss,"awT",@nobits
        .type   ccc, @object
        .size   ccc, 1
ccc:
        .zero   1
        .type   bbb, @object
        .size   bbb, 1
bbb:
        .zero   1
        .text
        .globl  __cxa_get_globals
        .type   __cxa_get_globals, @function
__cxa_get_globals:
.LFB0:
        .cfi_startproc
        pushl   %ebp
        .cfi_def_cfa_offset 8
        .cfi_offset 5, -8
        movl    %esp, %ebp
        .cfi_def_cfa_register 5
        pushl   %esi
        pushl   %ebx
        .cfi_offset 6, -12
        .cfi_offset 3, -16
        call    __x86.get_pc_thunk.bx
        addl    $_GLOBAL_OFFSET_TABLE_, %ebx
        leal    ccc@tlsgd(,%ebx,1), %eax
        call    ___tls_get_addr@PLT
        movl    %eax, %esi
        leal    bbb@tlsgd(,%ebx,1), %eax
        call    ___tls_get_addr@PLT
        subl    %eax, %esi
        movl    %esi, %eax
        popl    %ebx
        .cfi_restore 3
        popl    %esi
        .cfi_restore 6
        popl    %ebp
        .cfi_restore 5
        .cfi_def_cfa 4, 4
        ret
        .cfi_endproc
.LFE0:
        .size   __cxa_get_globals, .-__cxa_get_globals
        .section
.text.__x86.get_pc_thunk.bx,"axG",@progbits,__x86.get_pc_thunk.bx,comdat
        .globl  __x86.get_pc_thunk.bx
        .hidden __x86.get_pc_thunk.bx
        .type   __x86.get_pc_thunk.bx, @function
__x86.get_pc_thunk.bx:
.LFB1:
        .cfi_startproc
        movl    (%esp), %ebx
        ret
        .cfi_endproc
.LFE1:
        .ident  "GCC: (GNU) 4.9.0 20140307 (experimental)"
        .section        .note.GNU-stack,"",@progbits

Reply via email to