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

ConstantMerge ignores alignment, needed because of SSE use #10886

Closed
llvmbot opened this issue Jul 27, 2011 · 3 comments
Closed

ConstantMerge ignores alignment, needed because of SSE use #10886

llvmbot opened this issue Jul 27, 2011 · 3 comments
Labels
bugzilla Issues migrated from bugzilla ipo Interprocedural optimizations

Comments

@llvmbot
Copy link
Collaborator

llvmbot commented Jul 27, 2011

Bugzilla Link 10514
Resolution FIXED
Resolved on Jul 27, 2011 14:47
Version trunk
OS FreeBSD
Reporter LLVM Bugzilla Contributor

Extended Description

on amd64 with SSE enabled, if it doesnt crash for you try to make the "Test1"
string longer (ie. "Test12" etc.):

pes ~$ cat llvm-align.c
#if 0

peter@daintree[10:28AM]-1051> cc -O1 -o bar bar.c
peter@daintree[10:28AM]
-1052> ./bar
Test1 foo1bar2foo3bar

peter@daintree[10:28AM]-1053> cc -O2 -o bar bar.c
peter@daintree[10:28AM]
-1054> ./bar
Test1 foo1bar2foo3bar
zsh: bus error (core dumped) ./bar

If you look at assembler output, with -O1, the constant string appears
twice. One has .align 16 constraint, due to SSE use, the other does not.

With -O2, both strings are merged, and the alignment constraint is lost.
#endif

int foo(int a)
{
char id[] = "foo1bar2foo3bar";
id[0] += a;
for (a = 0; id[a] != 0; a++)
;
return a;
}

int main(void)
{
printf("Test1 %s\n", "foo1bar2foo3bar");
return foo(1);
return 0;
}

@llvmbot
Copy link
Collaborator Author

llvmbot commented Jul 27, 2011

the "cc" here is clang:

pes ~$ clang -v
clang version 3.0 (trunk 136211)
Target: x86_64-unknown-freebsd8.2
Thread model: posix

@llvmbot
Copy link
Collaborator Author

llvmbot commented Jul 27, 2011

With -O1 the assembler output is:
...
foo: # @​foo
movaps foo.id(%rip), %xmm0
...
.section .rodata.str1.16,"aMS",@progbits,1
.align 16
foo.id:
.asciz "foo1bar2foo3bar"
.section .rodata.str1.1,"aMS",@progbits,1
.L.str:
.asciz "Test %s\n"
.L.str1:
.asciz "foo1bar2foo3bar"

With -O2:
...
foo: # @​foo
movaps .L.str1(%rip), %xmm0
...
.section .rodata.str1.1,"aMS",@progbits,1
.L.str:
.asciz "Test %s\n"
.L.str1:
.asciz "foo1bar2foo3bar"

Note missing ".align 16". Luck will determine if it is aligned for the SSE data copy.

@llvmbot
Copy link
Collaborator Author

llvmbot commented Jul 27, 2011

Fixed in r136250.

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 3, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla ipo Interprocedural optimizations
Projects
None yet
Development

No branches or pull requests

1 participant