| Issue |
185390
|
| Summary |
[arm64ec] Incorrect thunk generation for functions returning structures larger than 64 bits
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
ndingle-arm
|
When generating entry thunks for functions returning structures by value that are larger than 64 bits, LLVM does not use the correct registers. I attach a reproducer than demonstrates the behaviour.
The reproducer uses the system complex.h header so _Dcomplex is defined as:
struct _Dcomplex {
double _Val[2];
}
MSVC cl produces the correct output from the reproducer:
2.000E+00+0.000E+00i
but clang gives the wrong output:
2.314E-306+4.792E-322i
Looking at the disassembly, the thunk produced by cl puts the address of the stored result in x8 (rax), which is the correct behaviour for x64 functions returning structures larger than 64 bits (see https://learn.microsoft.com/en-us/cpp/build/x64-calling-convention?view=msvc-170#return-values) :
mov x19,x0
ldp d2,d3,[x2]
ldp d0,d1,[x1]
blr x9
mov x8,x19
dup v7.2d,v0.d[0]
ins v7.d[1],v1.d[0]
str q7,[x19]
clang, however, puts the result in d0 and d1:
str x0,[sp,#8]
ldr d1,[x1,#8]
ldr d0,[x1]
ldr d3,[x2,#8]
ldr d2,[x2]
blr x9
ldr x0,[sp,#8]
str d1,[x0,#8]
str d0,[x0]
I also attach the LLVM IR of the reproducer as suggested by @dpaoliello
[funcs.c](https://github.com/user-attachments/files/25839575/funcs.c)
[main.c](https://github.com/user-attachments/files/25839576/main.c)
[funcs.ll.txt](https://github.com/user-attachments/files/25839657/funcs.ll.txt)
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs