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: [email protected]
          Reporter: [email protected]
                CC: [email protected]
    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.
_______________________________________________
llvm-bugs mailing list
[email protected]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to