blob: fb1bdfd62fb7c18c75d11c04e64da6033b76ef33 [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
James Molloy6215fad2016-10-06 07:56:00 +000018@.arr4 = private unnamed_addr constant [2 x i16] [i16 3, i16 4], align 16
James Molloy9abb2fa2016-09-26 07:26:24 +000019
20; CHECK-LABEL: @test1
21; CHECK: adr r0, [[x:.*]]
22; CHECK: [[x]]:
23; CHECK: .asciz "s\000\000"
24define void @test1() #0 {
25 tail call void @a(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i32 0, i32 0)) #2
26 ret void
27}
28
29declare void @a(i8*) #1
30
31; CHECK-LABEL: @test2
32; CHECK-NOT: .asci
33; CHECK: .fnend
34define void @test2() #0 {
35 tail call void @a(i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str1, i32 0, i32 0)) #2
36 ret void
37}
38
39; CHECK-LABEL: @test3
40; CHECK: adr r0, [[x:.*]]
41; CHECK: [[x]]:
42; CHECK: .asciz "this string is just right!\000"
43define void @test3() #0 {
44 tail call void @a(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str2, i32 0, i32 0)) #2
45 ret void
46}
47
48
49; CHECK-LABEL: @test4
50; CHECK: adr r{{.*}}, [[x:.*]]
51; CHECK: [[x]]:
52; CHECK: .asciz "this string is used twice\000\000"
53define void @test4() #0 {
54 tail call void @a(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str3, i32 0, i32 0)) #2
55 tail call void @a(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str3, i32 0, i32 0)) #2
56 ret void
57}
58
59; CHECK-LABEL: @test5a
60; CHECK-NOT: adr
61define void @test5a() #0 {
62 tail call void @a(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str4, i32 0, i32 0)) #2
63 ret void
64}
65
66define void @test5b() #0 {
67 tail call void @b(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str4, i32 0, i32 0)) #2
68 ret void
69}
70
71; CHECK-LABEL: @test6a
72; CHECK: adr r0, [[x:.*]]
73; CHECK: [[x]]:
74; CHECK: .short 3
75; CHECK: .short 4
76define void @test6a() #0 {
77 tail call void @c(i16* getelementptr inbounds ([2 x i16], [2 x i16]* @.arr1, i32 0, i32 0)) #2
78 ret void
79}
80
81; CHECK-LABEL: @test6b
82; CHECK: adr r0, [[x:.*]]
83; CHECK: [[x]]:
84; CHECK: .short 3
85; CHECK: .short 4
86define void @test6b() #0 {
87 tail call void @c(i16* getelementptr inbounds ([2 x i16], [2 x i16]* @.arr1, i32 0, i32 0)) #2
88 ret void
89}
90
91; This shouldn't be promoted, as the string is used by another global.
92; CHECK-LABEL: @test7
93; CHECK-NOT: adr
94define void @test7() #0 {
95 tail call void @c(i16* getelementptr inbounds ([2 x i16], [2 x i16]* @.arr2, i32 0, i32 0)) #2
96 ret void
97}
98
99; This shouldn't be promoted, because the array contains pointers.
100; CHECK-LABEL: @test8
101; CHECK-NOT: .zero
102; CHECK: .fnend
103define void @test8() #0 {
104 %a = load i16*, i16** getelementptr inbounds ([2 x i16*], [2 x i16*]* @.arr3, i32 0, i32 0)
105 tail call void @c(i16* %a) #2
106 ret void
107}
108
109@fn1.a = private unnamed_addr constant [4 x i16] [i16 4, i16 0, i16 0, i16 0], align 2
110@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
111
112; Just check these don't crash.
113define void @fn1() "target-features"="+strict-align" {
114entry:
115 %a = alloca [4 x i16], align 2
116 %0 = bitcast [4 x i16]* %a to i8*
117 call void @llvm.memcpy.p0i8.p0i8.i32(i8* %0, i8* bitcast ([4 x i16]* @fn1.a to i8*), i32 8, i32 2, i1 false)
118 ret void
119}
120
121define void @fn2() "target-features"="+strict-align" {
122entry:
123 %a = alloca [8 x i8], align 2
124 %0 = bitcast [8 x i8]* %a to i8*
125 call void @llvm.memcpy.p0i8.p0i8.i32(i8* %0, i8* bitcast ([8 x i8]* @fn2.a to i8*), i32 16, i32 1, i1 false)
126 ret void
127}
128
James Molloy6215fad2016-10-06 07:56:00 +0000129; This shouldn't be promoted, as the global requires >4 byte alignment.
130; CHECK-LABEL: @test9
131; CHECK-NOT: adr
132define void @test9() #0 {
133 tail call void @c(i16* getelementptr inbounds ([2 x i16], [2 x i16]* @.arr4, i32 0, i32 0)) #2
134 ret void
135}
136
137
James Molloy9abb2fa2016-09-26 07:26:24 +0000138declare void @b(i8*) #1
139declare void @c(i16*) #1
140declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture writeonly, i8* nocapture readonly, i32, i32, i1)
141
142attributes #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" }
143attributes #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" }
144attributes #2 = { nounwind }
145
146!llvm.module.flags = !{!0, !1}
147!llvm.ident = !{!2}
148
149!0 = !{i32 1, !"wchar_size", i32 4}
150!1 = !{i32 1, !"min_enum_size", i32 4}
151!2 = !{!"Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM 3.6.0svn)"}