blob: c70f08cff17b56975d01dc74f6df51006d16fe0e [file] [log] [blame]
James Molloy9abb2fa2016-09-26 07:26:24 +00001; RUN: llc -relocation-model=static < %s | FileCheck %s
2; RUN: llc -relocation-model=pic < %s | FileCheck %s
3; RUN: llc -relocation-model=ropi < %s | FileCheck %s
4; RUN: llc -relocation-model=rwpi < %s | FileCheck %s
5
6target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-n32-S64"
7target triple = "armv7--linux-gnueabihf"
8
9@.str = private unnamed_addr constant [2 x i8] c"s\00", align 1
10@.str1 = private unnamed_addr constant [69 x i8] c"this string is far too long to fit in a literal pool by far and away\00", align 1
11@.str2 = private unnamed_addr constant [27 x i8] c"this string is just right!\00", align 1
12@.str3 = private unnamed_addr constant [26 x i8] c"this string is used twice\00", align 1
13@.str4 = private unnamed_addr constant [29 x i8] c"same string in two functions\00", align 1
14@.arr1 = private unnamed_addr constant [2 x i16] [i16 3, i16 4], align 2
15@.arr2 = private unnamed_addr constant [2 x i16] [i16 7, i16 8], align 2
16@.arr3 = private unnamed_addr constant [2 x i16*] [i16* null, i16* null], align 4
17@.ptr = private unnamed_addr constant [2 x i16*] [i16* getelementptr inbounds ([2 x i16], [2 x i16]* @.arr2, i32 0, i32 0), i16* null], align 2
18
19; CHECK-LABEL: @test1
20; CHECK: adr r0, [[x:.*]]
21; CHECK: [[x]]:
22; CHECK: .asciz "s\000\000"
23define void @test1() #0 {
24 tail call void @a(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i32 0, i32 0)) #2
25 ret void
26}
27
28declare void @a(i8*) #1
29
30; CHECK-LABEL: @test2
31; CHECK-NOT: .asci
32; CHECK: .fnend
33define void @test2() #0 {
34 tail call void @a(i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str1, i32 0, i32 0)) #2
35 ret void
36}
37
38; CHECK-LABEL: @test3
39; CHECK: adr r0, [[x:.*]]
40; CHECK: [[x]]:
41; CHECK: .asciz "this string is just right!\000"
42define void @test3() #0 {
43 tail call void @a(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str2, i32 0, i32 0)) #2
44 ret void
45}
46
47
48; CHECK-LABEL: @test4
49; CHECK: adr r{{.*}}, [[x:.*]]
50; CHECK: [[x]]:
51; CHECK: .asciz "this string is used twice\000\000"
52define void @test4() #0 {
53 tail call void @a(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str3, i32 0, i32 0)) #2
54 tail call void @a(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str3, i32 0, i32 0)) #2
55 ret void
56}
57
58; CHECK-LABEL: @test5a
59; CHECK-NOT: adr
60define void @test5a() #0 {
61 tail call void @a(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str4, i32 0, i32 0)) #2
62 ret void
63}
64
65define void @test5b() #0 {
66 tail call void @b(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str4, i32 0, i32 0)) #2
67 ret void
68}
69
70; CHECK-LABEL: @test6a
71; CHECK: adr r0, [[x:.*]]
72; CHECK: [[x]]:
73; CHECK: .short 3
74; CHECK: .short 4
75define void @test6a() #0 {
76 tail call void @c(i16* getelementptr inbounds ([2 x i16], [2 x i16]* @.arr1, i32 0, i32 0)) #2
77 ret void
78}
79
80; CHECK-LABEL: @test6b
81; CHECK: adr r0, [[x:.*]]
82; CHECK: [[x]]:
83; CHECK: .short 3
84; CHECK: .short 4
85define void @test6b() #0 {
86 tail call void @c(i16* getelementptr inbounds ([2 x i16], [2 x i16]* @.arr1, i32 0, i32 0)) #2
87 ret void
88}
89
90; This shouldn't be promoted, as the string is used by another global.
91; CHECK-LABEL: @test7
92; CHECK-NOT: adr
93define void @test7() #0 {
94 tail call void @c(i16* getelementptr inbounds ([2 x i16], [2 x i16]* @.arr2, i32 0, i32 0)) #2
95 ret void
96}
97
98; This shouldn't be promoted, because the array contains pointers.
99; CHECK-LABEL: @test8
100; CHECK-NOT: .zero
101; CHECK: .fnend
102define void @test8() #0 {
103 %a = load i16*, i16** getelementptr inbounds ([2 x i16*], [2 x i16*]* @.arr3, i32 0, i32 0)
104 tail call void @c(i16* %a) #2
105 ret void
106}
107
108@fn1.a = private unnamed_addr constant [4 x i16] [i16 4, i16 0, i16 0, i16 0], align 2
109@fn2.a = private unnamed_addr constant [8 x i8] [i8 4, i8 0, i8 0, i8 0, i8 23, i8 0, i8 6, i8 0], align 1
110
111; Just check these don't crash.
112define void @fn1() "target-features"="+strict-align" {
113entry:
114 %a = alloca [4 x i16], align 2
115 %0 = bitcast [4 x i16]* %a to i8*
116 call void @llvm.memcpy.p0i8.p0i8.i32(i8* %0, i8* bitcast ([4 x i16]* @fn1.a to i8*), i32 8, i32 2, i1 false)
117 ret void
118}
119
120define void @fn2() "target-features"="+strict-align" {
121entry:
122 %a = alloca [8 x i8], align 2
123 %0 = bitcast [8 x i8]* %a to i8*
124 call void @llvm.memcpy.p0i8.p0i8.i32(i8* %0, i8* bitcast ([8 x i8]* @fn2.a to i8*), i32 16, i32 1, i1 false)
125 ret void
126}
127
128declare void @b(i8*) #1
129declare void @c(i16*) #1
130declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture writeonly, i8* nocapture readonly, i32, i32, i1)
131
132attributes #0 = { nounwind "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
133attributes #1 = { "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
134attributes #2 = { nounwind }
135
136!llvm.module.flags = !{!0, !1}
137!llvm.ident = !{!2}
138
139!0 = !{i32 1, !"wchar_size", i32 4}
140!1 = !{i32 1, !"min_enum_size", i32 4}
141!2 = !{!"Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM 3.6.0svn)"}