<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 - Unnecessary fld+fstp pair in double to float conversion"
   href="https://bugs.llvm.org/show_bug.cgi?id=48268">48268</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Unnecessary fld+fstp pair in double to float conversion
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

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

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

        <tr>
          <th>OS</th>
          <td>All
          </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>C
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>i-bugs-llvm-org-uQW3n8LD3W@rf.risimo.net
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>blitzrakete@gmail.com, dgregor@apple.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>See <a href="https://godbolt.org/z/d5ssq1">https://godbolt.org/z/d5ssq1</a>

Compiling

-----------------
#include <stdio.h>

union floatu {
    float fv;
    unsigned char bytes[4];
};

void print_as_hex(double fv) {
    union floatu u;
    u.fv=fv;
    printf("got a float with       0x%02x 0x%02x 0x%02x 0x%02x\n",
u.bytes[3],u.bytes[2],u.bytes[1],u.bytes[0]);
}
-----------------

with "-mno-sse -m32 -O9"

results in

-----------------
print_as_hex:                           # @print_as_hex
        push    esi
        sub     esp, 8
        fld     qword ptr [esp + 16]    <=== (1) ok
        fstp    dword ptr [esp]         <=== (2) ok
        fld     dword ptr [esp]         <=== (3) Unnecessary
        fstp    dword ptr [esp + 4]     <=== (4) Unnecessary
        mov     eax, dword ptr [esp + 4]
        mov     ecx, eax
        movzx   edx, ah
        movzx   esi, al
        shr     eax, 24
        shr     ecx, 16
        movzx   ecx, cl
        sub     esp, 12
        push    esi
        push    edx
        push    ecx
        push    eax
        push    offset .L.str
        call    printf
        add     esp, 40
        pop     esi
        ret
-----------------

(1) and (2) are required to convert the double to float. But (3) and (4)
perform no conversion and just copy data around.

(2) should write to [esp + 4] and (3) and (4) can be removed.</pre>
        </div>
      </p>


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

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