[llvm-bugs] [Bug 27503] New: useless moves generated by memcpy() to union
via llvm-bugs
llvm-bugs at lists.llvm.org
Sun Apr 24 18:50:44 PDT 2016
https://llvm.org/bugs/show_bug.cgi?id=27503
Bug ID: 27503
Summary: useless moves generated by memcpy() to union
Product: new-bugs
Version: 3.8
Hardware: PC
OS: All
Status: NEW
Severity: normal
Priority: P
Component: new bugs
Assignee: unassignedbugs at nondot.org
Reporter: jhaberman at gmail.com
CC: llvm-bugs at lists.llvm.org
Classification: Unclassified
Test case:
--
#include <string.h>
typedef union {
char ch;
float fl;
double dbl;
} u;
u f(const void *p, int type) {
u v;
if (type == 1) {
memcpy(&v, p, 1);
} else if (type <= 5) {
memcpy(&v, p, 4);
} else if (type <= 8) {
memcpy(&v, p, 8);
}
return v;
}
--
On every platform/version I've tested, compiling with -O3 I get bad code like:
--
0000000000000000 <f>:
0: 83 fe 01 cmp esi,0x1
3: 75 0e jne 13 <f+0x13>
5: 0f b6 07 movzx eax,BYTE PTR [rdi]
8: 66 48 0f 6e c0 movq xmm0,rax
d: 66 48 0f 7e c0 movq rax,xmm0
12: c3 ret
13: 83 fe 05 cmp esi,0x5
16: 7f 0d jg 25 <f+0x25>
18: 8b 07 mov eax,DWORD PTR [rdi]
1a: 66 48 0f 6e c0 movq xmm0,rax
1f: 66 48 0f 7e c0 movq rax,xmm0
24: c3 ret
25: 83 fe 08 cmp esi,0x8
28: 7f 04 jg 2e <f+0x2e>
2a: f2 0f 10 07 movsd xmm0,QWORD PTR [rdi]
2e: 66 48 0f 7e c0 movq rax,xmm0
33: c3 ret
--
Note the move to eax, then to xmm0, then back to rax.
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20160425/6e9d5760/attachment.html>
More information about the llvm-bugs
mailing list