[llvm-bugs] [Bug 32070] New: Special-case memcpy() after conditional block
via llvm-bugs
llvm-bugs at lists.llvm.org
Sat Feb 25 11:46:09 PST 2017
http://bugs.llvm.org/show_bug.cgi?id=32070
Bug ID: 32070
Summary: Special-case memcpy() after conditional block
Product: new-bugs
Version: trunk
Hardware: PC
OS: All
Status: NEW
Severity: enhancement
Priority: P
Component: new bugs
Assignee: unassignedbugs at nondot.org
Reporter: simonhosie77+llvm at gmail.com
CC: llvm-bugs at lists.llvm.org
Given:
void f(void *d, void const* s, size_t l, int c) {
if (__builtin_expect(c != 0, 1)) {
l = 0;
}
__builtin_memcpy(d, s, l);
}
Compiling this I get a conditional set-register-to-zero and unconditional call
to memcpy().
Ideally we'd just skip over the call when c != 0. Changing the code to this
makes everything better, but it's not automatic, and in realistic code it's not
something I'd want to do manually:
void f(void *d, void const* s, size_t l, int c) {
if (__builtin_expect(c != 0, 1)) {
l = 0;
__builtin_memcpy(d, s, l);
} else {
__builtin_memcpy(d, s, l);
}
}
Generally, finishing a conditional block with additional optimisation
information might produce a candidate for special-case implementation of the
common code that follows it. For __builtin_memcpy() this would include l being
set to any small constant.
--
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/20170225/06f57620/attachment.html>
More information about the llvm-bugs
mailing list