public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/53623] New: [4.7 Regression] sign extension is effectively split into two x86-64 instructions
@ 2012-06-10  2:50 adam at consulting dot net.nz
  2012-06-10 14:39 ` [Bug middle-end/53623] " hjl.tools at gmail dot com
                   ` (17 more replies)
  0 siblings, 18 replies; 19+ messages in thread
From: adam at consulting dot net.nz @ 2012-06-10  2:50 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 53623
           Summary: [4.7 Regression] sign extension is effectively split
                    into two x86-64 instructions
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: adam@consulting.net.nz


Note: 

#include <stdint.h>

typedef (*inst_t)(int64_t rdi, int64_t rsi, int64_t rdx);

int16_t code[256];
inst_t dispatch[256];

void an_inst(int64_t rdi, int64_t rsi, int64_t rdx) {
  rdx = code[rdx];
  uint8_t inst = (uint8_t) rdx;
  rdx >>= 8;
  dispatch[inst](rdi, rsi, rdx);
}

int main(void) {
  return 0;
}

$ gcc-4.6 -O3 sign_extension_regression.c && objdump -d -m i386:x86-64 a.out
|less

00000000004004a0 <an_inst>:
  4004a0:       48 0f bf 94 12 20 1a    movswq 0x601a20(%rdx,%rdx,1),%rdx
  4004a7:       60 00 
  4004a9:       0f b6 c2                movzbl %dl,%eax
  4004ac:       48 c1 fa 08             sar    $0x8,%rdx
  4004b0:       48 8b 04 c5 20 12 60    mov    0x601220(,%rax,8),%rax
  4004b7:       00 
  4004b8:       ff e0                   jmpq   *%rax

int16_t is sign extended into RDX. RDX is arithmetic shifted down by 8 (after
first extracting DL). Result: RDX contains a sign extended 8-bit value.

$ gcc-4.7 -O3 sign_extension_regression.c && objdump -d -m i386:x86-64 a.out
|less

00000000004004b0 <an_inst>:
  4004b0:       0f b7 84 12 60 1a 60    movzwl 0x601a60(%rdx,%rdx,1),%eax
  4004b7:       00 
  4004b8:       48 0f bf d0             movswq %ax,%rdx
  4004bc:       0f b6 c0                movzbl %al,%eax
  4004bf:       48 c1 fa 08             sar    $0x8,%rdx
  4004c3:       48 8b 04 c5 60 12 60    mov    0x601260(,%rax,8),%rax
  4004ca:       00 
  4004cb:       ff e0                   jmpq   *%rax

int16_t is loaded into EAX without sign extension. The low 16 bits of EAX are
loaded into RDX with sign extension. RDX is arithmetic shifted down by 8.
Result: RDX contains a sign extended 8-bit value.

This is a regression. gcc-4.6 achieved the same result with one less
instruction.

Note: The quality of the generated code is affect by Bug 45434 and Bug 46219.
Suggested optimal approach with four instructions:

1. movzwl mem16 -> edx
2. movzbl dl -> eax
3. movsbq dh -> rdx
4. complex indrect jmp (combining mov mem64 -> rax; jmp rax)


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

end of thread, other threads:[~2015-06-23  8:40 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-06-10  2:50 [Bug target/53623] New: [4.7 Regression] sign extension is effectively split into two x86-64 instructions adam at consulting dot net.nz
2012-06-10 14:39 ` [Bug middle-end/53623] " hjl.tools at gmail dot com
2012-06-10 14:43 ` [Bug middle-end/53623] [4.7/4.8 " hjl.tools at gmail dot com
2012-06-10 23:32 ` adam at consulting dot net.nz
2012-06-11  9:47 ` rguenth at gcc dot gnu.org
2012-06-11 12:21 ` jakub at gcc dot gnu.org
2012-09-20 10:28 ` jakub at gcc dot gnu.org
2012-12-03 15:32 ` rguenth at gcc dot gnu.org
2013-04-11  8:00 ` [Bug middle-end/53623] [4.7/4.8/4.9 " rguenth at gcc dot gnu.org
2013-12-13  5:24 ` law at redhat dot com
2014-01-08  6:03 ` law at redhat dot com
2014-01-08  6:03 ` law at gcc dot gnu.org
2015-02-15 14:06 ` hjl.tools at gmail dot com
2015-02-15 14:08 ` hjl.tools at gmail dot com
2015-02-15 16:03 ` [Bug middle-end/53623] [4.7/4.8 " hjl.tools at gmail dot com
2015-02-15 17:51 ` hjl.tools at gmail dot com
2015-02-16  9:00 ` [Bug middle-end/53623] [4.8 " rguenth at gcc dot gnu.org
2015-06-22 14:22 ` rguenth at gcc dot gnu.org
2015-06-23  8:46 ` rguenth at gcc dot gnu.org

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).