Bug 20126 – codegen reloads parameter from register when iasm changed the backing memory

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2019-08-13T05:24:50Z
Last change time
2019-08-19T08:47:03Z
Keywords
iasm, pull
Assigned to
No Owner
Creator
Manu

Comments

Comment #0 by turkeyman — 2019-08-13T05:24:50Z
On my local 2.087, this code works, but in master, it generates bad code: asmtest.d --------- extern(C) float floop(float* r, float x) { asm { mov EAX, x; mov RCX, r; xchg [RCX], EAX; mov x, EAX; } return x; } > dmd asmtest.d -c -m64 Dumping this emits: 0000000000000000 <floop>: 0: 55 push %rbp 1: 48 8b ec mov %rsp,%rbp 4: 48 83 ec 10 sub $0x10,%rsp 8: 48 89 7d f0 mov %rdi,-0x10(%rbp) c: f3 0f 11 45 f8 movss %xmm0,-0x8(%rbp) 11: 8b 45 f8 mov -0x8(%rbp),%eax 14: 48 8b 4d f0 mov -0x10(%rbp),%rcx 18: 87 01 xchg %eax,(%rcx) 1a: 89 45 f8 mov %eax,-0x8(%rbp) 1d: c9 leaveq 1e: c3 retq It's missing this before the return: movss 0x8(%rbp),%xmm0 You can see where it loads from the argument in xmm0 to -0x8(%rbp) to transfer to RAX in the asm code, then the asm code as written. It writes the modified value back to the stack, but the `return x;` statement should load `x` back into xmm0 to return the value, but it just skips that. I presume that it assumes xmm0 was not clobbered by the asm block and elides the return code, but the variable was written... This fails on x64 in master on both windows and linux, but it works correctly for -m32 (does emit an fld before return). It also used to work on x64 in 2.087.0 (which i'm running locally)
Comment #1 by dlang-bot — 2019-08-17T21:48:50Z
@WalterBright created dlang/dmd pull request #10316 "fix Issue 20126 - codegen reloads parameter from register when iasm c…" fixing this issue: - fix Issue 20126 - codegen reloads parameter from register when iasm changed the backing memory https://github.com/dlang/dmd/pull/10316
Comment #2 by turkeyman — 2019-08-19T00:34:04Z
**Bug report.
Comment #3 by dlang-bot — 2019-08-19T08:47:03Z
dlang/dmd pull request #10316 "fix Issue 20126 - codegen reloads parameter from register when iasm c…" was merged into master: - d51b3ec1a9cb3f1d9d1a5701b2237be7a31f61f4 by Walter Bright: fix Issue 20126 - codegen reloads parameter from register when iasm changed the backing memory https://github.com/dlang/dmd/pull/10316