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

--- Comment #2 from Sergei Trofimovich <slyfox at gcc dot gnu.org> ---
Looking at the output of `$gcc -S a.c -fPIC -o a.S` I think `testl` comparison
gets clobbered by a hoisted `__tls_get_addr` call:

```
bug:
.LFB2:
        .cfi_startproc
        subq    $24, %rsp
        .cfi_def_cfa_offset 32
        movl    $-1, %edi
        call    val
        testl   %eax, %eax ; %eax contains '-1'
        je      .L14
        leaq    tv_cache@tlsld(%rip), %rdi
        call    __tls_get_addr@PLT ; %rax is clobbered by a TLS table

        jg      .L16 ; <---- I think it want `testl` here, not
__tls_get_addr@PLT
        movl    tv_cache@dtpoff(%rax), %edi
        addq    $24, %rsp
        .cfi_remember_state
        .cfi_def_cfa_offset 8
        jmp     use_cache
        .p2align 4,,10
        .p2align 3
.L16:
        .cfi_restore_state
        movl    $2, %edi
        movq    %rax, 8(%rsp)
        call    val
        testl   %eax, %eax
        je      .L14
        movq    8(%rsp), %rax
        movl    tv_cache@dtpoff(%rax), %edi
        call    use_cache
.L14:
        ud2
        .cfi_endproc
```

Reply via email to