[Issue 20126] New: bad codegen for return statement in function with asm code
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue Aug 13 05:24:50 UTC 2019
https://issues.dlang.org/show_bug.cgi?id=20126
Issue ID: 20126
Summary: bad codegen for return statement in function with asm
code
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: regression
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: turkeyman at gmail.com
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)
--
More information about the Digitalmars-d-bugs
mailing list