See the following example: <https://godbolt.org/z/8sa686756>
double f(struct {long x; double y;} b);
/* expected: b.x -> RDI, b.y -> XMM0
* actual: b.x -> RDI, b.y -> RSI
*/
In the System V x86-64 ABI, when a structure is passed by value, it can be
passed in up to two registers if it is less than 16 bytes.
For those that are >8 bytes, the first and second 'eightbytes' are classified
independently. This can lead to a mixed case where a structure should be passed
in one integer register and one SSE register, but currently TCC classifies the
structure as a whole to be of integer class and passes it in two integer
registers. The relevant code is in x86_64-gen.c (classify_x86_64_inner,
classify_x86_64_arg, classify_x86_64_va_arg, gfunc_sret).
To fix this, the classification functions should keep track of 2
X86_64_Mode(s), and look at the (absolute) field
offsets when recursing into a structure, picking mode[0] or mode[1] based on if
offset < 8. That would allow to
correctly detect the mixed case, but isn't sufficient. The codebase uses
VT_QLONG and VT_QFLOAT value types as
128-bit-values for codegen for the 2 integer / 2 float registers case, so a new
pseudo type would be necessary
for the integer + sse case, or some refactoring to avoid using QLONG/QFLOAT for
this purpose. This also requires specific handling for va_arg. Codegen for
function call args (gfunc_call), etc would also need refactoring.
_______________________________________________
Tinycc-devel mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel