<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - unexpected failure for -mno-sse2"
   href="https://bugs.llvm.org/show_bug.cgi?id=43334">43334</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>unexpected failure for -mno-sse2
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Backend: X86
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>ndesaulniers@google.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>craig.topper@gmail.com, llvm-bugs@lists.llvm.org, llvm-dev@redking.me.uk, spatel+llvm@rotateright.com, srhines@google.com
          </td>
        </tr>

        <tr>
          <th>Blocks</th>
          <td>4068
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Consider:

$ cat foo.c
// double __floatunsidf (unsigned int i)
double foo(unsigned int i) {
    return (double) i;
}

$ clang -O2 -mno-sse2 foo.c
error: SSE2 register return with SSE2 disabled
    return (double) i;

    ^
$ gcc -O2 -mno-sse2 foo.c && llvm-objdump -d foo.o
foo:
  movl %edi, %edi
  movq %rdi, -8(%rsp)
  fildq -8(%rsp)
  fstpl -8(%rsp)
  movlps -8(%rsp), %xmm0
  ret

Adding -mno-80387 to clang seems to then complicate things further: clang
generates:

foo: # @foo
  pushq %rax
  callq __floatunsidf
  popq %rcx
  retq

This is important because:
1. the kernel builds with -mno-see2 -mno-80387 (and a few other related but
less relevant flags:
<a href="https://github.com/ClangBuiltLinux/linux/blob/52a5525214d0d612160154d902956eca0558b7c0/arch/x86/Makefile#L61-L62">https://github.com/ClangBuiltLinux/linux/blob/52a5525214d0d612160154d902956eca0558b7c0/arch/x86/Makefile#L61-L62</a>)
since saving/restoring fp register state gets complicated/expensive for all
registers added via ISA extensions).
2. the kernel does not define soft float routines like __floatunsidf. 
-mhard-float and -ffreestanding don't prevent clang from generating references
to these soft float routines.</pre>
        </div>
      </p>

        <div id="referenced">
          <hr style="border: 1px dashed #969696">
          <b>Referenced Bugs:</b>
          <ul>
              <li>
                [<a class="bz_bug_link 
          bz_status_CONFIRMED "
   title="CONFIRMED - [Meta] Compiling the Linux kernel with clang"
   href="https://bugs.llvm.org/show_bug.cgi?id=4068">Bug 4068</a>] [Meta] Compiling the Linux kernel with clang
              </li>
          </ul>
        </div>
        <br>

      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>