windows ABI problem with i128?

I’m trying to use LLVM to create compiler-rt.o on Windows. I use this command from the compiler-rt project:

[nix-shell:~/downloads/llvm-project/compiler-rt]$ clang -nostdlib -S -emit-llvm lib/builtins/udivti3.c -g -target x86_64-windows -DCRT_HAS_128BIT

The resulting LLVM IR is:

Most probably you need to properly specify the calling convention the
backend is using for calling the runtime functions. Or implement the
stub for udivti3 that performs the necessary argument lifting.

I guess there is no standard ABI document describing the intended
calling convention here, so I'd just do what mingw64 does here and
make everything here compatible.

Most probably you need to properly specify the calling convention the
backend is using for calling the runtime functions.

Thanks for the tip. Can you be more specific? Are you suggesting there is
some config parameter I can set before running TargetMachineEmitToFile?

Do you know what calling convention it is trying to use at the callsite?
Perhaps I can simply select a different convention from this list for the
implementation of udivti3?
http://llvm.org/docs/LangRef.html#calling-conventions

Or implement the

I figured out the problem:

The definition of __udivti3 is putting the return value on the stack, like this:
106: 48 8b 01 mov (%rcx),%rax
109: 48 8b 51 08 mov 0x8(%rcx),%rdx

However the callsite expects the result to be in %xmm0, which matches microsoft’s ABI:
a8: e8 43 00 00 00 callq f0 <__udivti3>
ad: 66 0f 70 c8 4e pshufd $0x4e,%xmm0,%xmm1
b2: 66 0f d6 45 00 movq %xmm0,0x0(%rbp)
b7: 66 0f d6 4d 08 movq %xmm1,0x8(%rbp)

So I tried using inline assembly to set xmm0: