Bug 12968 – DMD inline asm outputs wrong XCHG instruction

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
All
Creation time
2014-06-23T10:29:00Z
Last change time
2014-06-27T12:37:01Z
Keywords
iasm, wrong-code
Assigned to
blah38621
Creator
safety0ff.bugz

Comments

Comment #0 by safety0ff.bugz — 2014-06-23T10:29:42Z
DMD outputs xchg RDX, RAX when you ask for xchg RDX, R8 /// CODE: ulong bug(ulong a, ulong b, ulong c) { version (D_InlineAsm_X86_64) { // RDI = c RSI = b RDX = a // RAX = return value // Scratch: RAX, RCX, R8, R9 version (linux) asm { naked; // Let's return c using iasm mov RAX, RDI; // DMD outputs: REX.W+90+rd XCHG r64, RAX // instead of: REX.W+87/r XCHG r/m64,r64 xchg RDX, R8; // Interestingly, DMD outputs: // xchg RDX,RDI // and xchg RDX,R9 correctly ret; } } } ulong nobug(ulong a, ulong b, ulong c) { version (D_InlineAsm_X86_64) { version (linux) asm { naked; mov RAX, RDI; // Let's return c using iasm db 0x4c; db 0x87; db 0xC2; // xchg RDX, R8; ret; } } } void main() { import std.stdio; writeln(bug(1, 2, 3)); // ERROR: outputs 1 writeln(nobug(1, 2, 3)); // outputs 3 as it should assert(bug(1, 2, 3) == 3);// should pass but fails }
Comment #1 by blah38621 — 2014-06-23T20:03:47Z
Provided I understand the code correctly, I believe the offending code is backend/cod3.c line 5128. Now I just have to figure out why it's reaching there.
Comment #2 by blah38621 — 2014-06-23T20:37:43Z
Well, it appears I don't understand the right format to get it to auto-reference the PR here, so I'll do it manually instead. https://github.com/D-Programming-Language/dmd/pull/3690
Comment #3 by github-bugzilla — 2014-06-24T23:09:01Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/6f013e558501c7b736656bec12ee241bd6f65684 Fix issue 12968 - Incorrect codgen for xchg with R8 https://github.com/D-Programming-Language/dmd/commit/9ddfff545a12d9c3b4df4829e3d4f8c90679cc02 Merge pull request #3690 from Orvid/issue12968 Fix issue 12968 - incorrect codegen
Comment #4 by yebblies — 2014-06-27T12:37:01Z
(In reply to Orvid King from comment #2) > Well, it appears I don't understand the right format to get it to > auto-reference the PR here, so I'll do it manually instead. > > https://github.com/D-Programming-Language/dmd/pull/3690 There is no auto reference, only the message when the commit is merged.