Oleg Ranevskyy | 09df002 | 2017-05-23 19:38:37 +0000 | [diff] [blame] | 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 |
James Molloy | 9abb2fa | 2016-09-26 07:26:24 +0000 | [diff] [blame] | 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 |
James Molloy | 6215fad | 2016-10-06 07:56:00 +0000 | [diff] [blame] | 23 | @.arr4 = private unnamed_addr constant [2 x i16] [i16 3, i16 4], align 16 |
Vadzim Dambrouski | ba789cb | 2017-03-20 22:59:57 +0000 | [diff] [blame] | 24 | @.zerosize = private unnamed_addr constant [0 x i16] zeroinitializer, align 4 |
James Molloy | 9abb2fa | 2016-09-26 07:26:24 +0000 | [diff] [blame] | 25 | |
| 26 | ; CHECK-LABEL: @test1 |
| 27 | ; CHECK: adr r0, [[x:.*]] |
| 28 | ; CHECK: [[x]]: |
| 29 | ; CHECK: .asciz "s\000\000" |
| 30 | define 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 | |
| 35 | declare void @a(i8*) #1 |
| 36 | |
| 37 | ; CHECK-LABEL: @test2 |
| 38 | ; CHECK-NOT: .asci |
| 39 | ; CHECK: .fnend |
| 40 | define 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" |
| 49 | define 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" |
| 59 | define 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 |
| 67 | define 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 | |
| 72 | define 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 |
| 82 | define 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 |
| 92 | define 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 |
| 100 | define 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 |
| 109 | define 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. |
| 119 | define void @fn1() "target-features"="+strict-align" { |
| 120 | entry: |
| 121 | %a = alloca [4 x i16], align 2 |
| 122 | %0 = bitcast [4 x i16]* %a to i8* |
Daniel Neilson | 1e68724 | 2018-01-19 17:13:12 +0000 | [diff] [blame] | 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) |
James Molloy | 9abb2fa | 2016-09-26 07:26:24 +0000 | [diff] [blame] | 124 | ret void |
| 125 | } |
| 126 | |
| 127 | define void @fn2() "target-features"="+strict-align" { |
| 128 | entry: |
| 129 | %a = alloca [8 x i8], align 2 |
| 130 | %0 = bitcast [8 x i8]* %a to i8* |
Daniel Neilson | 1e68724 | 2018-01-19 17:13:12 +0000 | [diff] [blame] | 131 | call void @llvm.memcpy.p0i8.p0i8.i32(i8* %0, i8* bitcast ([8 x i8]* @fn2.a to i8*), i32 16, i1 false) |
James Molloy | 9abb2fa | 2016-09-26 07:26:24 +0000 | [diff] [blame] | 132 | ret void |
| 133 | } |
| 134 | |
James Molloy | 6215fad | 2016-10-06 07:56:00 +0000 | [diff] [blame] | 135 | ; This shouldn't be promoted, as the global requires >4 byte alignment. |
| 136 | ; CHECK-LABEL: @test9 |
| 137 | ; CHECK-NOT: adr |
| 138 | define 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 | |
Vadzim Dambrouski | ba789cb | 2017-03-20 22:59:57 +0000 | [diff] [blame] | 143 | ; Ensure that zero sized values are supported / not promoted. |
| 144 | ; CHECK-LABEL: @pr32130 |
| 145 | ; CHECK-NOT: adr |
| 146 | define 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 | |
Kristof Beyls | 5ac6adb | 2017-02-23 12:24:55 +0000 | [diff] [blame] | 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" |
| 158 | define void @test10(i8* %a) local_unnamed_addr #0 { |
Daniel Neilson | 1e68724 | 2018-01-19 17:13:12 +0000 | [diff] [blame] | 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) |
Kristof Beyls | 5ac6adb | 2017-02-23 12:24:55 +0000 | [diff] [blame] | 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 |
| 176 | define void @test11(i16* %a) local_unnamed_addr #0 { |
Daniel Neilson | 1e68724 | 2018-01-19 17:13:12 +0000 | [diff] [blame] | 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) |
Kristof Beyls | 5ac6adb | 2017-02-23 12:24:55 +0000 | [diff] [blame] | 178 | ret void |
| 179 | } |
| 180 | |
James Molloy | 6215fad | 2016-10-06 07:56:00 +0000 | [diff] [blame] | 181 | |
James Molloy | 9abb2fa | 2016-09-26 07:26:24 +0000 | [diff] [blame] | 182 | declare void @b(i8*) #1 |
| 183 | declare void @c(i16*) #1 |
Daniel Neilson | 1e68724 | 2018-01-19 17:13:12 +0000 | [diff] [blame] | 184 | declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture writeonly, i8* nocapture readonly, i32, i1) |
| 185 | declare void @llvm.memmove.p0i8.p0i8.i32(i8*, i8*, i32, i1) local_unnamed_addr |
| 186 | declare void @llvm.memmove.p0i16.p0i16.i32(i16*, i16*, i32, i1) local_unnamed_addr |
James Molloy | 9abb2fa | 2016-09-26 07:26:24 +0000 | [diff] [blame] | 187 | |
| 188 | attributes #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" } |
| 189 | attributes #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" } |
| 190 | attributes #2 = { nounwind } |
| 191 | |
| 192 | !llvm.module.flags = !{!0, !1} |
James Molloy | 9abb2fa | 2016-09-26 07:26:24 +0000 | [diff] [blame] | 193 | |
| 194 | !0 = !{i32 1, !"wchar_size", i32 4} |
| 195 | !1 = !{i32 1, !"min_enum_size", i32 4} |