[llvm-dev] variadic functions on X86_64 should (conditionally) save XMM regs even if -no-implicit-float

Nasser, Salim via llvm-dev llvm-dev at lists.llvm.org
Mon Nov 27 18:00:44 PST 2017

Specifying -no-implicit-float prevents LLVM from using non-GPR registers for purely integer operations. This is useful for operating systems (such as Wind River's VxWorks) that support tasks that do not save all registers on context switch.

This presents an interesting problem for variadic functions that may optionally take non-integer arguments (e.g. printf style functions). Should non-GPR registers be spilled to the stack when -no-implicit-float is specified?

Ideally we would do so only if non-GPR register arguments are actually passed by the caller. This would require a runtime check, and whether or not such a check is feasible depends on the target and ABI.

However for X86_64, the standard va_start code already has such a check - the number of vector (XMM) register arguments is stored in %al, and the code normally generated for variadic functions (in the absence of -no-implicit-float) includes a guard around the XMM spill code that checks for %al != 0.

Therefore I believe it would be "in the spirit" of -no-implicit-float to remove the NoImplicitFloatOps check from the following:

X86ISelLowering.cpp : get64BitArgumentXMMs()
 if (isSoftFloat || NoImplicitFloatOps || !Subtarget.hasSSE1())
    // Kernel mode asks for SSE to be disabled, so there are no XMM argument                                                                                                                                
    // registers.                                                                                                                                                                                           
    return None;

Does this seem like a reasonable idea?


Salim Nasser
Wind River

More information about the llvm-dev mailing list