https://bugs.llvm.org/show_bug.cgi?id=48268
Bug ID: 48268
Summary: Unnecessary fld+fstp pair in double to float
conversion
Product: clang
Version: trunk
Hardware: PC
OS: All
Status: NEW
Severity: enhancement
Priority: P
Component: C
Assignee: [email protected]
Reporter: [email protected]
CC: [email protected], [email protected],
[email protected], [email protected],
[email protected]
See https://godbolt.org/z/d5ssq1
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.
--
You are receiving this mail because:
You are on the CC list for the bug._______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs