Skip to content

Commit

Permalink
remove unnecessary REX prefix byte from 32 bit MOV
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright committed Feb 6, 2019
1 parent 8adbfee commit 07ed006
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
5 changes: 4 additions & 1 deletion src/dmd/backend/cod1.d
Original file line number Diff line number Diff line change
Expand Up @@ -1928,7 +1928,10 @@ void fixresult(ref CodeBuilder cdb, elem *e, regm_t retregs, regm_t *pretregs)
assert(!(retregs & XMMREGS));
assert(!(forregs & XMMREGS));
reg = findreg(retregs & (mBP | ALLREGS));
genmovreg(cdb, rreg, reg); // MOV rreg,reg
if (I64 && sz <= 4)
genregs(cdb, 0x89, reg, rreg); // only move 32 bits, and zero the top 32 bits
else
genmovreg(cdb, rreg, reg); // MOV rreg,reg
}
}
cssave(e,retregs | *pretregs,opsflag);
Expand Down
9 changes: 4 additions & 5 deletions test/runnable/test_cdcmp.d
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ alias baselineCases = AliasSeq!(
Code!(int, "<", Zero!int)([
/* push rbp */ 0x55,
/* mov rbp,rsp */ 0x48, 0x8b, 0xec,
/* mov rax,rdi */ 0x48, 0x89, 0xf8,
/* mov eax,edi */ 0x89, 0xf8,
/* shr eax,0x1f */ 0xc1, 0xe8, 0x1f,
/* pop rbp */ 0x5d,
/* ret */ 0xc3,
Expand All @@ -685,7 +685,7 @@ alias baselineCases = AliasSeq!(
Code!(int, "<=", Zero!int)([
/* push rbp */ 0x55,
/* mov rbp,rsp */ 0x48, 0x8b, 0xec,
/* mov rax,rdi */ 0x48, 0x89, 0xf8,
/* mov eax,edi */ 0x89, 0xf8,
/* add eax,0xffffffff */ 0x83, 0xc0, 0xff,
/* adc eax,0x0 */ 0x83, 0xd0, 0x00,
/* shr eax,0x1f */ 0xc1, 0xe8, 0x1f,
Expand Down Expand Up @@ -741,7 +741,7 @@ alias baselineCases = AliasSeq!(
Code!(int, ">=", Zero!int)([
/* push rbp */ 0x55,
/* mov rbp,rsp */ 0x48, 0x8b, 0xec,
/* mov rax,rdi */ 0x48, 0x89, 0xf8,
/* mov eax,edi */ 0x89, 0xf8,
/* add eax,eax */ 0x01, 0xc0,
/* sbb eax,eax */ 0x19, 0xc0,
/* inc eax */ 0xff, 0xc0,
Expand All @@ -759,13 +759,12 @@ alias baselineCases = AliasSeq!(
Code!(int, ">", Zero!int)([
/* push rbp */ 0x55,
/* mov rbp,rsp */ 0x48, 0x8b, 0xec,
/* mov rax,rdi */ 0x48, 0x89, 0xf8,
/* mov eax,edi */ 0x89, 0xf8,
/* neg eax */ 0xf7, 0xd8,
/* sbb eax,0x0 */ 0x83, 0xd8, 0x00,
/* shr eax,0x1f */ 0xc1, 0xe8, 0x1f,
/* pop rbp */ 0x5d,
/* ret */ 0xc3,
/* add BYTE PTR [rax],al */ 0x00, 0x00,
]),
Code!(int, ">", int)([
/* push rbp */ 0x55,
Expand Down
10 changes: 5 additions & 5 deletions test/runnable/test_cdstrpar.d
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ alias baselineCases = AliasSeq!(
/* push rbp */ 0x55,
/* mov rbp,rsp */ 0x48, 0x8b, 0xec,
/* call 9 <testee_ubyte_4+0x9> */ 0xe8, 0x00, 0x00, 0x00, 0x00,
/* mov rdi,rax */ 0x48, 0x89, 0xc7,
/* mov edi,eax */ 0x89, 0xc7,
/* call 11 <testee_ubyte_4+0x11> */ 0xe8, 0x00, 0x00, 0x00, 0x00,
/* pop rbp */ 0x5d,
/* ret */ 0xc3,
Expand All @@ -132,7 +132,7 @@ alias baselineCases = AliasSeq!(
/* push rbp */ 0x55,
/* mov rbp,rsp */ 0x48, 0x8b, 0xec,
/* call 9 <testee_ubyte_8+0x9> */ 0xe8, 0x00, 0x00, 0x00, 0x00,
/* mov rdi,rax */ 0x48, 0x89, 0xc7,
/* mov edi,eax */ 0x89, 0xc7,
/* call 11 <testee_ubyte_8+0x11> */ 0xe8, 0x00, 0x00, 0x00, 0x00,
/* pop rbp */ 0x5d,
/* ret */ 0xc3,
Expand All @@ -141,8 +141,8 @@ alias baselineCases = AliasSeq!(
/* push rbp */ 0x55,
/* mov rbp,rsp */ 0x48, 0x8b, 0xec,
/* call 9 <testee_ubyte_16+0x9> */ 0xe8, 0x00, 0x00, 0x00, 0x00,
/* mov rdi,rax */ 0x48, 0x89, 0xc7,
/* mov rsi,rdx */ 0x48, 0x89, 0xd6,
/* mov edi,eax */ 0x89, 0xc7,
/* mov esi,edx */ 0x89, 0xd6,
/* call 14 <testee_ubyte_16+0x14> */ 0xe8, 0x00, 0x00, 0x00, 0x00,
/* pop rbp */ 0x5d,
/* ret */ 0xc3,
Expand All @@ -153,7 +153,7 @@ alias baselineCases = AliasSeq!(
/* sub rsp,0x20 */ 0x48, 0x83, 0xec, 0x20,
/* lea rdi,[rbp-0x20] */ 0x48, 0x8d, 0x7d, 0xe0,
/* call 11 <testee_ubyte_32+0x11> */ 0xe8, 0x00, 0x00, 0x00, 0x00,
/* mov rsi,rax */ 0x48, 0x89, 0xc6,
/* mov esi,eax */ 0x89, 0xc6,
/* push QWORD PTR [rsi+0x18] */ 0xff, 0x76, 0x18,
/* push QWORD PTR [rsi+0x10] */ 0xff, 0x76, 0x10,
/* push QWORD PTR [rsi+0x8] */ 0xff, 0x76, 0x08,
Expand Down

0 comments on commit 07ed006

Please sign in to comment.