[LLVMbugs] [Bug 2969] New: clang turns const arrays inside functions into allocas/ stores instead of "internal constant" arrays
bugzilla-daemon at cs.uiuc.edu
bugzilla-daemon at cs.uiuc.edu
Tue Oct 28 14:33:42 PDT 2008
http://llvm.org/bugs/show_bug.cgi?id=2969
Summary: clang turns const arrays inside functions into
allocas/stores instead of "internal constant" arrays
Product: clang
Version: unspecified
Platform: All
OS/Version: All
Status: NEW
Severity: normal
Priority: P2
Component: LLVM Codegen
AssignedTo: unassignedbugs at nondot.org
ReportedBy: richard at godbee.net
CC: llvmbugs at cs.uiuc.edu
Created an attachment (id=2144)
--> (http://llvm.org/bugs/attachment.cgi?id=2144)
C source code + complete LLVM assembly output from llvm-gcc and clang
int f1(int n) {
const int array_one[] = { 1, 2, 3 };
return array_one[n];
}
int f2(int n) {
static const int array_two[] = { 7, 8, 9 };
return array_two[n];
}
/* Note that f1() and f2() are identical, except f1()'s int[] is "const" and
f2()'s int[] is "static const". */
**********
llvm-gcc (as shipped with Xcode 3.1.1) will emit "internal constant" arrays for
both array_one and array_two...
@array_one.1538 = internal constant [3 x i32] [ i32 1, i32 2, i32 3 ]
; <[3 x i32]*> [#uses=1]
@array_two.1545 = internal constant [3 x i32] [ i32 7, i32 8, i32 9 ]
; <[3 x i32]*> [#uses=1]
Like llvm-gcc, clang (trunk r58037) will emit an "internal constant" array for
array_two...
@f2.array_two = internal global [3 x i32] [ i32 7, i32 8, i32 9 ]
; <[3 x i32]*> [#uses=1]
However, for array_one, clang will alloca space for the array and store each
element one-by-one inside of f1()...
define i32 @f1(i32 %n) nounwind {
entry:
%array_one = alloca [3 x i32], align 4 ; <[3 x i32]*>
[#uses=4]
%.array = getelementptr [3 x i32]* %array_one, i32 0, i32 0
; <i32*> [#uses=1]
store i32 1, i32* %.array
%.array1 = getelementptr [3 x i32]* %array_one, i32 0, i32 1
; <i32*> [#uses=1]
store i32 2, i32* %.array1
%.array2 = getelementptr [3 x i32]* %array_one, i32 0, i32 2
; <i32*> [#uses=1]
store i32 3, i32* %.array2
%arrayidx = getelementptr [3 x i32]* %array_one, i32 0, i32 %n
; <i32*> [#uses=1]
%tmp3 = load i32* %arrayidx ; <i32> [#uses=1]
ret i32 %tmp3
}
opt -std-compile-args doesn't transform the alloca + stores into an "internal
constant" array, either.
--
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