[llvm-bugs] [Bug 24700] New: memset optimization for initialization is sometimes a pessimization
via llvm-bugs
llvm-bugs at lists.llvm.org
Thu Sep 3 14:54:13 PDT 2015
https://llvm.org/bugs/show_bug.cgi?id=24700
Bug ID: 24700
Summary: memset optimization for initialization is sometimes a
pessimization
Product: clang
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: LLVM Codegen
Assignee: unassignedclangbugs at nondot.org
Reporter: richard-llvm at metafoo.co.uk
CC: llvm-bugs at lists.llvm.org
Classification: Unclassified
Extracted from PR24698, consider:
union U {
int a[2];
int b[256];
};
void foo(int a)
{
union U u = {.a = {1}};
union U v = {.a = {a}};
}
Clang emits both of these as a memset of 1024 bytes followed by a store due to
our memset optimizations for initialization (see
shouldUseMemSetPlusStoresToInitialize and CheckAggExprForMemSetUse for the
constant and non-constant cases respectively). That's a pessimization: only the
first 8 bytes of u and v have specified values, so we should emit each of these
initializations as just one or two stores.
Another, more difficult to fix, version of the same problem:
struct S {
union U a, b;
int n;
};
void bar() {
struct S s = { {{1}}, {{2}}, 3 };
}
This can be emitted as three or five stores, but we'll instead memset all 2K of
stack space.
--
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/20150903/d06d02d7/attachment.html>
More information about the llvm-bugs
mailing list