1 ; RUN: llc -mtriple=thumbv8m.base-eabi -mattr=+execute-only %s -o - | FileCheck --check-prefix=CHECK --check-prefix=CHECK-T2BASE %s
2 ; RUN: llc -mtriple=thumbv8m.base-eabi -mcpu=cortex-m23 -mattr=+execute-only %s -o - | FileCheck --check-prefix=CHECK --check-prefix=CHECK-T2BASE %s
3 ; RUN: llc -mtriple=thumbv7m-eabi -mattr=+execute-only %s -o - | FileCheck --check-prefix=CHECK --check-prefix=CHECK-T2 %s
4 ; RUN: llc -mtriple=thumbv8m.main-eabi -mattr=+execute-only %s -o - | FileCheck --check-prefix=CHECK --check-prefix=CHECK-T2 %s
5 ; RUN: llc -mtriple=thumbv6m-eabi -mattr=+execute-only %s -o - | FileCheck --check-prefix=CHECK-T1 %s
7 ; CHECK-NOT: {{^ *}}.text{{$}}
8 ; CHECK: .section .text,"axy",%progbits,unique,0
12 define i32 @global() minsize {
13 ; CHECK-LABEL: global:
14 ; CHECK: movw [[GLOBDEST:r[0-9]+]], :lower16:var
15 ; CHECK-NEXT: movt [[GLOBDEST]], :upper16:var
16 ; CHECK-T1-LABEL: global:
17 ; CHECK-T1: movs [[GLOBDEST:r[0-9]+]], :upper8_15:var
18 ; CHECK-T1-NEXT: lsls [[GLOBDEST]], [[GLOBDEST]], #8
19 ; CHECK-T1-NEXT: adds [[GLOBDEST]], :upper0_7:var
20 ; CHECK-T1-NEXT: lsls [[GLOBDEST]], [[GLOBDEST]], #8
21 ; CHECK-T1-NEXT: adds [[GLOBDEST]], :lower8_15:var
22 ; CHECK-T1-NEXT: lsls [[GLOBDEST]], [[GLOBDEST]], #8
23 ; CHECK-T1-NEXT: adds [[GLOBDEST]], :lower0_7:var
25 %val = load i32, ptr @var
29 define i32 @jump_table(i32 %c, i32 %a, i32 %b) #0 {
30 ; CHECK-LABEL: jump_table:
31 ; CHECK-T2: adr.w [[REG_JT:r[0-9]+]], .LJTI1_0
32 ; CHECK-T2: add.w [[REG_ENTRY:r[0-9]+]], [[REG_JT]], {{r[0-9]+}}, lsl #2
33 ; CHECK-T2: mov pc, [[REG_ENTRY]]
35 ; CHECK-T2BASE: lsls [[REG_OFFSET:r[0-9]+]], {{r[0-9]+}}, #2
36 ; CHECK-T2BASE: adr [[REG_JT:r[0-9]+]], .LJTI1_0
37 ; CHECK-T2BASE: adds [[REG_ENTRY:r[0-9]+]], [[REG_JT]], [[REG_OFFSET]]
38 ; CHECK-T2BASE: mov pc, [[REG_ENTRY]]
40 ; CHECK-LABEL: .LJTI1_0:
48 ; CHECK-T1-LABEL: jump_table:
49 ; CHECK-T1: lsls [[REG_OFFSET:r[0-9]+]], {{r[0-9]+}}, #2
50 ; CHECK-T1-NEXT: movs [[REG_JT:r[0-9]+]], :upper8_15:.LJTI1_0
51 ; CHECK-T1-NEXT: lsls [[REG_JT]], [[REG_JT]], #8
52 ; CHECK-T1-NEXT: adds [[REG_JT]], :upper0_7:.LJTI1_0
53 ; CHECK-T1-NEXT: lsls [[REG_JT]], [[REG_JT]], #8
54 ; CHECK-T1-NEXT: adds [[REG_JT]], :lower8_15:.LJTI1_0
55 ; CHECK-T1-NEXT: lsls [[REG_JT]], [[REG_JT]], #8
56 ; CHECK-T1-NEXT: adds [[REG_JT]], :lower0_7:.LJTI1_0
57 ; CHECK-T1-NEXT: ldr [[REG_ENTRY:r[0-9]+]], [[[REG_JT]], [[REG_OFFSET]]]
58 ; CHECK-T1-NEXT: mov pc, [[REG_ENTRY]]
59 ; CHECK-T1: .section .rodata,"a",%progbits
60 ; CHECK-T1-NEXT: .p2align 2, 0x0
61 ; CHECK-T1-NEXT: .LJTI1_0:
62 ; CHECK-T1-NEXT: .long
63 ; CHECK-T1-NEXT: .long
64 ; CHECK-T1-NEXT: .long
65 ; CHECK-T1-NEXT: .long
66 ; CHECK-T1-NEXT: .long
67 ; CHECK-T1-NEXT: .long
70 switch i32 %c, label %return [
79 sw.bb: ; preds = %entry
80 %add = add nsw i32 %a, 6
83 sw.bb1: ; preds = %entry
84 %add2 = add nsw i32 %a, 4
87 sw.bb3: ; preds = %entry
88 %sub = add nsw i32 %a, -3
91 sw.bb4: ; preds = %entry
92 %add5 = add nsw i32 %b, 5
95 sw.bb6: ; preds = %entry
96 %add7 = add nsw i32 %a, 1
99 sw.bb8: ; preds = %entry
100 %add9 = add nsw i32 %a, 2
103 return: ; preds = %entry, %sw.bb8, %sw.bb6, %sw.bb4, %sw.bb3, %sw.bb1, %sw.bb
104 %retval.0 = phi i32 [ %add9, %sw.bb8 ], [ %add7, %sw.bb6 ], [ %add5, %sw.bb4 ], [ %sub, %sw.bb3 ], [ %add2, %sw.bb1 ], [ %add, %sw.bb ], [ 0, %entry ]
108 @.str = private unnamed_addr constant [4 x i8] c"FOO\00", align 1
110 define hidden ptr @string_literal() {
112 ; CHECK-LABEL: string_literal:
113 ; CHECK: movw [[STRLIT:r[0-9]+]], :lower16:.L.str
114 ; CHECK-NEXT: movt [[STRLIT]], :upper16:.L.str
115 ; CHECK-T1-LABEL: string_literal:
116 ; CHECK-T1: movs [[STRLIT:r[0-9]+]], :upper8_15:.L.str
117 ; CHECK-T1-NEXT: lsls [[STRLIT]], [[STRLIT]], #8
118 ; CHECK-T1-NEXT: adds [[STRLIT]], :upper0_7:.L.str
119 ; CHECK-T1-NEXT: lsls [[STRLIT]], [[STRLIT]], #8
120 ; CHECK-T1-NEXT: adds [[STRLIT]], :lower8_15:.L.str
121 ; CHECK-T1-NEXT: lsls [[STRLIT]], [[STRLIT]], #8
122 ; CHECK-T1-NEXT: adds [[STRLIT]], :lower0_7:.L.str
127 @external_global = external global i32
128 define i32 @test_external_global() {
130 ; CHECK-LABEL: external_global:
131 ; CHECK: movw [[EXTGLOB:r[0-9]+]], :lower16:external_global
132 ; CHECK-NEXT: movt [[EXTGLOB]], :upper16:external_global
133 ; CHECK-T1-LABEL: external_global:
134 ; CHECK-T1: movs [[EXTGLOB:r[0-9]+]], :upper8_15:external_global
135 ; CHECK-T1-NEXT: lsls [[EXTGLOB]], [[EXTGLOB]], #8
136 ; CHECK-T1-NEXT: adds [[EXTGLOB]], :upper0_7:external_global
137 ; CHECK-T1-NEXT: lsls [[EXTGLOB]], [[EXTGLOB]], #8
138 ; CHECK-T1-NEXT: adds [[EXTGLOB]], :lower8_15:external_global
139 ; CHECK-T1-NEXT: lsls [[EXTGLOB]], [[EXTGLOB]], #8
140 ; CHECK-T1-NEXT: adds [[EXTGLOB]], :lower0_7:external_global
142 %v = load i32, ptr @external_global
146 define i32 @test_imm() {
148 ; CHECK-LABEL: test_imm:
149 ; CHECK: movw [[IMMDEST:r[0-9]+]], #13124
150 ; CHECK-NEXT: movt [[IMMDEST]], #4386
152 ; CHECK-T1-LABEL: test_imm:
153 ; CHECK-T1: movs [[IMMDEST:r[0-9]+]], #17
154 ; CHECK-T1-NEXT: lsls [[IMMDEST]], [[IMMDEST]], #8
155 ; CHECK-T1-NEXT: adds [[IMMDEST]], #34
156 ; CHECK-T1-NEXT: lsls [[IMMDEST]], [[IMMDEST]], #8
157 ; CHECK-T1-NEXT: adds [[IMMDEST]], #51
158 ; CHECK-T1-NEXT: lsls [[IMMDEST]], [[IMMDEST]], #8
159 ; CHECK-T1-NEXT: adds [[IMMDEST]], #68
160 ; CHECK-T1-NEXT: bx lr
165 define i32 @test_imm_high_half() {
167 ; CHECK-LABEL: test_imm_high_half:
168 ; CHECK-T2BASE: movw [[IMMDEST:r[0-9]+]], #0
169 ; CHECK-T2: movs [[IMMDEST:r[0-9]+]], #0
170 ; CHECK-NEXT: movt [[IMMDEST]], #4386
172 ; CHECK-T1-LABEL: test_imm_high_half:
173 ; CHECK-T1: movs [[IMMDEST:r[0-9]+]], #17
174 ; CHECK-T1-NEXT: lsls [[IMMDEST]], [[IMMDEST]], #8
175 ; CHECK-T1-NEXT: adds [[IMMDEST]], #34
176 ; CHECK-T1-NEXT: lsls [[IMMDEST]], [[IMMDEST]], #16
177 ; CHECK-T1-NEXT: bx lr
182 define i32 @test_imm_low_half() {
183 ; CHECK-LABEL: test_imm_low_half:
184 ; CHECK: movw [[IMMDEST:r[0-9]+]], #13124
186 ; CHECK-T1-LABEL: test_imm_low_half:
187 ; CHECK-T1: movs [[IMMDEST]], #51
188 ; CHECK-T1-NEXT: lsls [[IMMDEST]], [[IMMDEST]], #8
189 ; CHECK-T1-NEXT: adds [[IMMDEST]], #68
190 ; CHECK-T1-NEXT: bx lr
196 define i32 @test_imm_middle_bytes() {
197 ; CHECK-LABEL: test_imm_middle_bytes:
198 ; CHECK: movw [[IMMDEST:r[0-9]+]], #13056
199 ; CHECK-NEXT: movt [[IMMDEST]], #34
201 ; CHECK-T1-LABEL: test_imm_middle_bytes:
202 ; CHECK-T1: movs [[IMMDEST]], #34
203 ; CHECK-T1-NEXT: lsls [[IMMDEST]], [[IMMDEST]], #8
204 ; CHECK-T1-NEXT: adds [[IMMDEST]], #51
205 ; CHECK-T1-NEXT: lsls [[IMMDEST]], [[IMMDEST]], #8
206 ; CHECK-T1-NEXT: bx lr
211 ; This struct is sized so that the byval call does an inline memcpy of
213 %struct.struct_t = type { [65553 x i8] }
214 @byval_arg = global %struct.struct_t zeroinitializer
215 declare void @byval_fn(ptr byval(%struct.struct_t))
217 define void @test_byval_call() {
219 ; CHECK-LABEL: test_byval_call:
220 ; CHECK-T2BASE: movw [[BYVAL_CPYSIZE:r[0-9]+]], #1
221 ; CHECK-T2: movs [[BYVAL_CPYSIZE:r[0-9]+]], #1
222 ; CHECK: movt [[BYVAL_CPYSIZE]], #1
223 ; CHECK-T1-LABEL: test_byval_call:
224 ; CHECK-T1: movs [[BYVAL_CPYSIZE:r[0-9]+]], #1
225 ; CHECK-T1: lsls [[BYVAL_CPYSIZE]], [[BYVAL_CPYSIZE]], #16
226 ; CHECK-T1: adds [[BYVAL_CPYSIZE]], #1
228 call void @byval_fn(ptr byval(%struct.struct_t) @byval_arg)