1; RUN: llc -mtriple armv7--linux-gnueabihf -relocation-model=static -arm-promote-constant < %s | FileCheck %s --check-prefixes=CHECK,CHECK-V7,CHECK-V7ARM 2; RUN: llc -mtriple armv7--linux-gnueabihf -relocation-model=pic -arm-promote-constant < %s | FileCheck %s --check-prefixes=CHECK,CHECK-V7,CHECK-V7ARM 3; RUN: llc -mtriple armv7--linux-gnueabihf -relocation-model=ropi -arm-promote-constant < %s | FileCheck %s --check-prefixes=CHECK,CHECK-V7,CHECK-V7ARM 4; RUN: llc -mtriple armv7--linux-gnueabihf -relocation-model=rwpi -arm-promote-constant < %s | FileCheck %s --check-prefixes=CHECK,CHECK-V7,CHECK-V7ARM 5; RUN: llc -mtriple thumbv7--linux-gnueabihf -relocation-model=static -arm-promote-constant < %s | FileCheck %s --check-prefixes=CHECK,CHECK-V7,CHECK-V7THUMB 6; RUN: llc -mtriple thumbv7--linux-gnueabihf -relocation-model=pic -arm-promote-constant < %s | FileCheck %s --check-prefixes=CHECK,CHECK-V7,CHECK-V7THUMB 7; RUN: llc -mtriple thumbv7--linux-gnueabihf -relocation-model=ropi -arm-promote-constant < %s | FileCheck %s --check-prefixes=CHECK,CHECK-V7,CHECK-V7THUMB 8; RUN: llc -mtriple thumbv7--linux-gnueabihf -relocation-model=rwpi -arm-promote-constant < %s | FileCheck %s --check-prefixes=CHECK,CHECK-V7,CHECK-V7THUMB 9; RUN: llc -mtriple thumbv6m--linux-gnueabihf -relocation-model=static -arm-promote-constant < %s | FileCheck %s --check-prefixes=CHECK,CHECK-V6M 10; RUN: llc -mtriple thumbv6m--linux-gnueabihf -relocation-model=pic -arm-promote-constant < %s | FileCheck %s --check-prefixes=CHECK,CHECK-V6M 11; RUN: llc -mtriple thumbv6m--linux-gnueabihf -relocation-model=ropi -arm-promote-constant < %s | FileCheck %s --check-prefixes=CHECK,CHECK-V6M 12; RUN: llc -mtriple thumbv6m--linux-gnueabihf -relocation-model=rwpi -arm-promote-constant < %s | FileCheck %s --check-prefixes=CHECK,CHECK-V6M 13 14@.str = private unnamed_addr constant [2 x i8] c"s\00", align 1 15@.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 16@.str2 = private unnamed_addr constant [27 x i8] c"this string is just right!\00", align 1 17@.str3 = private unnamed_addr constant [26 x i8] c"this string is used twice\00", align 1 18@.str4 = private unnamed_addr constant [29 x i8] c"same string in two functions\00", align 1 19@.arr1 = private unnamed_addr constant [2 x i16] [i16 3, i16 4], align 2 20@.arr2 = private unnamed_addr constant [2 x i16] [i16 7, i16 8], align 2 21@.arr3 = private unnamed_addr constant [2 x i16*] [i16* null, i16* null], align 4 22@.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 23@.arr4 = private unnamed_addr constant [2 x i16] [i16 3, i16 4], align 16 24@.zerosize = private unnamed_addr constant [0 x i16] zeroinitializer, align 4 25 26; CHECK-LABEL: @test1 27; CHECK: adr r0, [[x:.*]] 28; CHECK: [[x]]: 29; CHECK: .asciz "s\000\000" 30define void @test1() #0 { 31 tail call void @a(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i32 0, i32 0)) #2 32 ret void 33} 34 35declare void @a(i8*) #1 36 37; CHECK-LABEL: @test2 38; CHECK-NOT: .asci 39; CHECK: .fnend 40define void @test2() #0 { 41 tail call void @a(i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str1, i32 0, i32 0)) #2 42 ret void 43} 44 45; CHECK-LABEL: @test3 46; CHECK: adr r0, [[x:.*]] 47; CHECK: [[x]]: 48; CHECK: .asciz "this string is just right!\000" 49define void @test3() #0 { 50 tail call void @a(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str2, i32 0, i32 0)) #2 51 ret void 52} 53 54 55; CHECK-LABEL: @test4 56; CHECK: adr r{{.*}}, [[x:.*]] 57; CHECK: [[x]]: 58; CHECK: .asciz "this string is used twice\000\000" 59define void @test4() #0 { 60 tail call void @a(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str3, i32 0, i32 0)) #2 61 tail call void @a(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str3, i32 0, i32 0)) #2 62 ret void 63} 64 65; CHECK-LABEL: @test5a 66; CHECK-NOT: adr 67define void @test5a() #0 { 68 tail call void @a(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str4, i32 0, i32 0)) #2 69 ret void 70} 71 72define void @test5b() #0 { 73 tail call void @b(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str4, i32 0, i32 0)) #2 74 ret void 75} 76 77; CHECK-LABEL: @test6a 78; CHECK: adr r0, [[x:.*]] 79; CHECK: [[x]]: 80; CHECK: .short 3 81; CHECK: .short 4 82define void @test6a() #0 { 83 tail call void @c(i16* getelementptr inbounds ([2 x i16], [2 x i16]* @.arr1, i32 0, i32 0)) #2 84 ret void 85} 86 87; CHECK-LABEL: @test6b 88; CHECK: adr r0, [[x:.*]] 89; CHECK: [[x]]: 90; CHECK: .short 3 91; CHECK: .short 4 92define void @test6b() #0 { 93 tail call void @c(i16* getelementptr inbounds ([2 x i16], [2 x i16]* @.arr1, i32 0, i32 0)) #2 94 ret void 95} 96 97; This shouldn't be promoted, as the string is used by another global. 98; CHECK-LABEL: @test7 99; CHECK-NOT: adr 100define void @test7() #0 { 101 tail call void @c(i16* getelementptr inbounds ([2 x i16], [2 x i16]* @.arr2, i32 0, i32 0)) #2 102 ret void 103} 104 105; This shouldn't be promoted, because the array contains pointers. 106; CHECK-LABEL: @test8 107; CHECK-NOT: .zero 108; CHECK: .fnend 109define void @test8() #0 { 110 %a = load i16*, i16** getelementptr inbounds ([2 x i16*], [2 x i16*]* @.arr3, i32 0, i32 0) 111 tail call void @c(i16* %a) #2 112 ret void 113} 114 115@fn1.a = private unnamed_addr constant [4 x i16] [i16 4, i16 0, i16 0, i16 0], align 2 116@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 117 118; Just check these don't crash. 119define void @fn1() "target-features"="+strict-align" { 120entry: 121 %a = alloca [4 x i16], align 2 122 %0 = bitcast [4 x i16]* %a to i8* 123 call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 2 %0, i8* align 2 bitcast ([4 x i16]* @fn1.a to i8*), i32 8, i1 false) 124 ret void 125} 126 127define void @fn2() "target-features"="+strict-align" { 128entry: 129 %a = alloca [8 x i8], align 2 130 %0 = bitcast [8 x i8]* %a to i8* 131 call void @llvm.memcpy.p0i8.p0i8.i32(i8* %0, i8* bitcast ([8 x i8]* @fn2.a to i8*), i32 16, i1 false) 132 ret void 133} 134 135; This shouldn't be promoted, as the global requires >4 byte alignment. 136; CHECK-LABEL: @test9 137; CHECK-NOT: adr 138define void @test9() #0 { 139 tail call void @c(i16* getelementptr inbounds ([2 x i16], [2 x i16]* @.arr4, i32 0, i32 0)) #2 140 ret void 141} 142 143; Ensure that zero sized values are supported / not promoted. 144; CHECK-LABEL: @pr32130 145; CHECK-NOT: adr 146define void @pr32130() #0 { 147 tail call void @c(i16* getelementptr inbounds ([0 x i16], [0 x i16]* @.zerosize, i32 0, i32 0)) #2 148 ret void 149} 150 151; CHECK-LABEL: @test10 152; CHECK-V6M: adr r{{[0-9]*}}, [[x:.*]] 153; CHECK-V6M: [[x]]: 154; CHECK-V6M: .asciz "s\000\000" 155; CHECK-V7: ldrb{{(.w)?}} r{{[0-9]*}}, [[x:.*]] 156; CHECK-V7: [[x]]: 157; CHECK-V7: .asciz "s\000\000" 158define void @test10(i8* %a) local_unnamed_addr #0 { 159 call void @llvm.memmove.p0i8.p0i8.i32(i8* align 1 %a, i8* align 1 getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i32 0, i32 0), i32 1, i1 false) 160 ret void 161} 162 163; CHECK-LABEL: @test11 164; CHECK-V6M: adr r{{[0-9]*}}, [[x:.*]] 165; CHECK-V6M: [[x]]: 166; CHECK-V6M: .short 3 167; CHECK-V6M: .short 4 168; CHECK-V7THUMB: ldrh{{(.w)?}} r{{[0-9]*}}, [[x:.*]] 169; CHECK-V7THUMB: [[x]]: 170; CHECK-V7THUMB: .short 3 171; CHECK-V7THUMB: .short 4 172; CHECK-V7ARM: adr r{{[0-9]*}}, [[x:.*]] 173; CHECK-V7ARM: [[x]]: 174; CHECK-V7ARM: .short 3 175; CHECK-V7ARM: .short 4 176define void @test11(i16* %a) local_unnamed_addr #0 { 177 call void @llvm.memmove.p0i16.p0i16.i32(i16* align 2 %a, i16* align 2 getelementptr inbounds ([2 x i16], [2 x i16]* @.arr1, i32 0, i32 0), i32 2, i1 false) 178 ret void 179} 180 181 182declare void @b(i8*) #1 183declare void @c(i16*) #1 184declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture writeonly, i8* nocapture readonly, i32, i1) 185declare void @llvm.memmove.p0i8.p0i8.i32(i8*, i8*, i32, i1) local_unnamed_addr 186declare void @llvm.memmove.p0i16.p0i16.i32(i16*, i16*, i32, i1) local_unnamed_addr 187 188attributes #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" } 189attributes #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" } 190attributes #2 = { nounwind } 191 192!llvm.module.flags = !{!0, !1} 193 194!0 = !{i32 1, !"wchar_size", i32 4} 195!1 = !{i32 1, !"min_enum_size", i32 4} 196