public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/54445] New: TLS array lookup with negative constant is not combined into a single instruction
@ 2012-09-01  0:40 adam at consulting dot net.nz
  2012-09-01  3:00 ` [Bug target/54445] " adam at consulting dot net.nz
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: adam at consulting dot net.nz @ 2012-09-01  0:40 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54445

             Bug #: 54445
           Summary: TLS array lookup with negative constant is not
                    combined into a single instruction
    Classification: Unclassified
           Product: gcc
           Version: 4.7.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: adam@consulting.net.nz


I have encountered a weird Thread Local Storage issue where negative constants
in an array lookup statement are not combined into a single memory load
instruction. Non-negative constant are handled OK.

$ cat
tls_array_lookup_with_negative_constant_not_combined_into_a_single_instruction.c 
#include <stdint.h>

uint8_t array[64];
__thread uint8_t tls_array[64];

uint8_t array_lookup_with_positive_constant(int64_t position) {
  return array[position + 1];
}

uint8_t array_lookup_with_negative_constant(int64_t position) {
  return array[position - 1];
}

uint8_t tls_array_lookup_with_positive_constant(int64_t position) {
  return tls_array[position + 1];
}

uint8_t tls_array_lookup_with_negative_constant(int64_t position) {
  return tls_array[position - 1];
}

int main(void) {
  return 0;
}

$ gcc -O3 -std=gnu11 -pthread
tls_array_lookup_with_negative_constant_not_combined_into_a_single_instruction.c
&& objdump -d -m i386:x86-64:intel a.out |less

0000000000400540 <array_lookup_with_positive_constant>:
  400540:       0f b6 87 e1 09 60 00    movzx  eax,BYTE PTR [rdi+0x6009e1]
  400547:       c3                      ret    
  400548:       0f 1f 84 00 00 00 00    nop    DWORD PTR [rax+rax*1+0x0]
  40054f:       00 

0000000000400550 <array_lookup_with_negative_constant>:
  400550:       0f b6 87 df 09 60 00    movzx  eax,BYTE PTR [rdi+0x6009df]
  400557:       c3                      ret    
  400558:       0f 1f 84 00 00 00 00    nop    DWORD PTR [rax+rax*1+0x0]
  40055f:       00 

0000000000400560 <tls_array_lookup_with_positive_constant>:
  400560:       64 0f b6 87 c1 ff ff    movzx  eax,BYTE PTR fs:[rdi-0x3f]
  400567:       ff 
  400568:       c3                      ret    
  400569:       0f 1f 80 00 00 00 00    nop    DWORD PTR [rax+0x0]

0000000000400570 <tls_array_lookup_with_negative_constant>:
  400570:       48 c7 c0 c0 ff ff ff    mov    rax,0xffffffffffffffc0
  400577:       64 0f b6 44 07 ff       movzx  eax,BYTE PTR fs:[rdi+rax*1-0x1]
  40057d:       c3                      ret    
  40057e:       90                      nop
  40057f:       90                      nop

I believe tls_array_lookup_with_negative_constant should generate the
instruction movzx eax,BYTE PTR fs:[rdi-0x41]

Note: I initially observed the issue with the cmp instruction (e.g. mov
rax,0xfffffffffffffdc0; cmp BYTE PTR fs:[rax+rcx*1-0x80],r8b) so the issue is
likely to apply to all x86-64 instructions that perform a TLS memory load with
a negative constant.


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2012-09-13  9:02 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-09-01  0:40 [Bug target/54445] New: TLS array lookup with negative constant is not combined into a single instruction adam at consulting dot net.nz
2012-09-01  3:00 ` [Bug target/54445] " adam at consulting dot net.nz
2012-09-01 14:54 ` ubizjak at gmail dot com
2012-09-01 16:59 ` hjl.tools at gmail dot com
2012-09-02 14:06 ` hjl.tools at gmail dot com
2012-09-02 14:21 ` hjl.tools at gmail dot com
2012-09-12 18:09 ` hjl at gcc dot gnu.org
2012-09-12 18:10 ` hjl.tools at gmail dot com
2012-09-12 18:11 ` hjl at gcc dot gnu.org
2012-09-13  9:02 ` adam at consulting dot net.nz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).