[LLVMbugs] [Bug 6551] New: C++ constructors not completely eliminated from function-level static constants
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Mon Mar 8 16:34:04 PST 2010
http://llvm.org/bugs/show_bug.cgi?id=6551
Summary: C++ constructors not completely eliminated from
function-level static constants
Product: libraries
Version: trunk
Platform: All
OS/Version: All
Status: NEW
Severity: normal
Priority: P
Component: Scalar Optimizations
AssignedTo: unassignedbugs at nondot.org
ReportedBy: stoklund at 2pi.dk
CC: llvmbugs at cs.uiuc.edu
llvm-g++ compiles this into a nice constant table:
#include <utility>
typedef std::pair<int,int> P;
static const P table[] = {
P(1,2),
P(3,4),
P(5,6)
};
P f(int n) {
return table[n];
}
Produces the table:
.section __TEXT,__const
.align 4
__ZL5table:
.long 1
.long 2
.long 3
.long 4
.long 5
.long 6
If the static const table is moved into the function
P f(int n) {
static const P table[] = {
P(1,2),
P(3,4),
P(5,6)
};
return table[n];
}
We get horrible dynamic initialization:
Llabel3:
movl %edi, %ebx
cmpb $0, __ZGVZ1fiE5table(%rip)
jne LBB1_3
leaq __ZGVZ1fiE5table(%rip), %rdi
callq ___cxa_guard_acquire
testl %eax, %eax
je LBB1_3
leaq __ZGVZ1fiE5table(%rip), %rdi
movl $1, __ZZ1fiE5table(%rip)
movl $2, __ZZ1fiE5table+4(%rip)
movl $3, __ZZ1fiE5table+8(%rip)
movl $4, __ZZ1fiE5table+12(%rip)
movl $5, __ZZ1fiE5table+16(%rip)
movl $6, __ZZ1fiE5table+20(%rip)
callq ___cxa_guard_release
--
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
More information about the llvm-bugs
mailing list