llvm-project
b941d90c - [clang] Pass fp128 indirectly and return in xmm0 on Windows (#115052)

Commit
324 days ago
[clang] Pass fp128 indirectly and return in xmm0 on Windows (#115052) Clang currently passes and returns `__float128` in vector registers on MinGW targets, which is LLVM's default ABI for `fp128`. However, the Windows x86-64 calling convention [1] states the following: __m128 types, arrays, and strings are never passed by immediate value. Instead, a pointer is passed to memory allocated by the caller. Structs and unions of size 8, 16, 32, or 64 bits, and __m64 types, are passed as if they were integers of the same size. Structs or unions of other sizes are passed as a pointer to memory allocated by the caller. For these aggregate types passed as a pointer, including __m128, the caller-allocated temporary memory must be 16-byte aligned. Based on the above it sounds like `__float128` should be passed indirectly. Thus, change `f128` passing to use the stack and make the return in xmm0 explicit. This is the identical to `i128`, and passing is the same as GCC. Regarding return values, the documentation states: A scalar return value that can fit into 64 bits, including the __m64 type, is returned through RAX. Non-scalar types including floats, doubles, and vector types such as __m128, __m128i, __m128d are returned in XMM0. This makes it sound like it should be acceptable to return `__float128` in xmm0; however, GCC returns `__float128` on the stack. That above ABI statement as well as consistency with `i128` (which is returned in xmm0) mean that it would likely be better for GCC to change its return ABI to match Clang rather than the other way around, so that portion is left as-is. Clang's MSVC targets do not support `__float128` or `_Float128`, but these changes would also apply there if it is eventually enabled. With [2] which should land around the same time, LLVM will also implement this ABI so it is not technically necessary for Clang to make a change here as well. This is sill done in order to be consistent with other types, and to allow calling convention-aware optimizations at all available optimization layers (@rnk mentioned possible reuse of stack arguments). An added benefit is readibility of the LLVM IR since it more accurately reflects what the lowered assembly does. [1]: https://learn.microsoft.com/en-us/cpp/build/x64-calling-convention?view=msvc-170 [2]: https://github.com/llvm/llvm-project/pull/128848
Author
Parents
Loading