Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clang initialization code generation can be improved #651

Closed
lattner opened this issue Mar 10, 2004 · 6 comments
Closed

Clang initialization code generation can be improved #651

lattner opened this issue Mar 10, 2004 · 6 comments

Comments

@lattner
Copy link
Collaborator

lattner commented Mar 10, 2004

Bugzilla Link 279
Resolution FIXED
Resolved on Dec 02, 2010 01:07
Version unspecified
OS All
CC @lattner

Extended Description

Though we are generating better code for GCC CONSTRUCTOR nodes (See Bug 275), we
still aren't doing as well as we should do. In particular, we handle cases like
this poorly:

int foo(int X) {
int Arr[100] = { X }; // Should use memset
int Arr[10000] = { 1 }; // Should use memset

// Should memcpy the whole thing
struct { int A, B } Pairs[10] = { {1, 2 }, { 0, 0 } };
}

... While the first ones could be addressed right now, the last one requires a
rewrite of how we handle constructors, which is needed to fix several code
correctness bugs anyway. This bug is just a tracker for when this happens.

-Chris

@lattner
Copy link
Collaborator Author

lattner commented Mar 16, 2004

Here's a testcase in the regression suite:
test/Regression/CFrontend/2004-02-13-StringInit.c.tr

@lattner
Copy link
Collaborator Author

lattner commented Oct 11, 2004

Here's another testcase:

struct T { int A, B; };
struct S { struct T X, Y; };

int test1(int x) {
struct S A = { {x, x+1}, {0, 12 } };
}

int test2() {
struct S A[] = {
{ { 0, 1}, {2, 3} },
{ { 2, 1}, {2, 3} },
{ { 3, 1}, {2, 3} },
{ { 4, 1}, {2, 3} },
{ { 5, 1}, {2, 3} },
};
}

int test3(int x) {
const int array[] = {
17, x, 123, 123, 49, 17, 23,
};
return array[x];
}

@lattner
Copy link
Collaborator Author

lattner commented May 5, 2007

Here is the example from comment #​1:

// RUN: %llvmgcc -xc %s -c -o - | llvm-dis | grep llvm.memset
char test(int X) {
char str[10000] = "abc"; // tail should be memset.
return str[X];
}

@llvmbot
Copy link
Collaborator

llvmbot commented Jun 23, 2009

From comment #​1, we memset the first two arrays. However, we use a bunch of SSE instructions to initialize the "Pairs" variable:

xorps	%xmm0, %xmm0
movaps	%xmm0, -24(%ebp)
movaps	%xmm0, -40(%ebp)
movaps	%xmm0, -56(%ebp)
movaps	%xmm0, -72(%ebp)
movaps	%xmm0, -88(%ebp)
movl	$1, -88(%ebp)
movl	$2, -84(%ebp)

@lattner
Copy link
Collaborator Author

lattner commented Dec 2, 2010

We don't care about llvm-gcc anymore, so stealing this for Clang. After r120645, clang now generates the right code for the second Arr testcase in Comment 0, and also handles hte Pairs example nicely from Comment #​0. It handles the examples in comment #​2, and the "str" case from comment 3. The example in comment 1 doesn't exist anymore.

The one remaining issue is that it does not handle this well from comment #​0:

int foo(int X) {
int Arr[100] = { X }; // Should use memset
}

@lattner
Copy link
Collaborator Author

lattner commented Dec 2, 2010

Finished off in r120692. We now generate a memset + 1 store.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants