1; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2; RUN: llc -verify-machineinstrs -mtriple=aarch64-unknown-linux < %s | FileCheck %s
3; RUN: llc -verify-machineinstrs -mtriple=arm64-apple-ios < %s | FileCheck %s --check-prefix=CHECK-APPLE
4
5; Check CSR split can work properly for tests below.
6
7@a = common dso_local local_unnamed_addr global i32 0, align 4
8
9define dso_local signext i32 @test1(i32* %b) local_unnamed_addr uwtable  {
10; CHECK-LABEL: test1:
11; CHECK:       // %bb.0: // %entry
12; CHECK-NEXT:    stp x30, x19, [sp, #-16]! // 16-byte Folded Spill
13; CHECK-NEXT:    .cfi_def_cfa_offset 16
14; CHECK-NEXT:    .cfi_offset w19, -8
15; CHECK-NEXT:    .cfi_offset w30, -16
16; CHECK-NEXT:    .cfi_remember_state
17; CHECK-NEXT:    adrp x8, a
18; CHECK-NEXT:    ldrsw x8, [x8, :lo12:a]
19; CHECK-NEXT:    cmp x8, x0
20; CHECK-NEXT:    b.eq .LBB0_2
21; CHECK-NEXT:  // %bb.1: // %if.end
22; CHECK-NEXT:    ldp x30, x19, [sp], #16 // 16-byte Folded Reload
23; CHECK-NEXT:    .cfi_def_cfa_offset 0
24; CHECK-NEXT:    .cfi_restore w19
25; CHECK-NEXT:    .cfi_restore w30
26; CHECK-NEXT:    ret
27; CHECK-NEXT:  .LBB0_2: // %if.then
28; CHECK-NEXT:    .cfi_restore_state
29; CHECK-NEXT:    mov x19, x0
30; CHECK-NEXT:    bl callVoid
31; CHECK-NEXT:    mov x0, x19
32; CHECK-NEXT:    ldp x30, x19, [sp], #16 // 16-byte Folded Reload
33; CHECK-NEXT:    .cfi_def_cfa_offset 0
34; CHECK-NEXT:    .cfi_restore w19
35; CHECK-NEXT:    .cfi_restore w30
36; CHECK-NEXT:    b callNonVoid
37;
38; CHECK-APPLE-LABEL: test1:
39; CHECK-APPLE:       ; %bb.0: ; %entry
40; CHECK-APPLE-NEXT:    stp x20, x19, [sp, #-32]! ; 16-byte Folded Spill
41; CHECK-APPLE-NEXT:    .cfi_def_cfa_offset 32
42; CHECK-APPLE-NEXT:    stp x29, x30, [sp, #16] ; 16-byte Folded Spill
43; CHECK-APPLE-NEXT:    .cfi_offset w30, -8
44; CHECK-APPLE-NEXT:    .cfi_offset w29, -16
45; CHECK-APPLE-NEXT:    .cfi_offset w19, -24
46; CHECK-APPLE-NEXT:    .cfi_offset w20, -32
47; CHECK-APPLE-NEXT:    .cfi_remember_state
48; CHECK-APPLE-NEXT:  Lloh0:
49; CHECK-APPLE-NEXT:    adrp x8, _a@PAGE
50; CHECK-APPLE-NEXT:  Lloh1:
51; CHECK-APPLE-NEXT:    ldrsw x8, [x8, _a@PAGEOFF]
52; CHECK-APPLE-NEXT:    cmp x8, x0
53; CHECK-APPLE-NEXT:    b.eq LBB0_2
54; CHECK-APPLE-NEXT:  ; %bb.1: ; %if.end
55; CHECK-APPLE-NEXT:    ldp x29, x30, [sp, #16] ; 16-byte Folded Reload
56; CHECK-APPLE-NEXT:    ldp x20, x19, [sp], #32 ; 16-byte Folded Reload
57; CHECK-APPLE-NEXT:    .cfi_def_cfa_offset 0
58; CHECK-APPLE-NEXT:    .cfi_restore w30
59; CHECK-APPLE-NEXT:    .cfi_restore w29
60; CHECK-APPLE-NEXT:    .cfi_restore w19
61; CHECK-APPLE-NEXT:    .cfi_restore w20
62; CHECK-APPLE-NEXT:    ret
63; CHECK-APPLE-NEXT:  LBB0_2: ; %if.then
64; CHECK-APPLE-NEXT:    .cfi_restore_state
65; CHECK-APPLE-NEXT:    mov x19, x0
66; CHECK-APPLE-NEXT:    bl _callVoid
67; CHECK-APPLE-NEXT:    ldp x29, x30, [sp, #16] ; 16-byte Folded Reload
68; CHECK-APPLE-NEXT:    mov x0, x19
69; CHECK-APPLE-NEXT:    ldp x20, x19, [sp], #32 ; 16-byte Folded Reload
70; CHECK-APPLE-NEXT:    .cfi_def_cfa_offset 0
71; CHECK-APPLE-NEXT:    .cfi_restore w30
72; CHECK-APPLE-NEXT:    .cfi_restore w29
73; CHECK-APPLE-NEXT:    .cfi_restore w19
74; CHECK-APPLE-NEXT:    .cfi_restore w20
75; CHECK-APPLE-NEXT:    b _callNonVoid
76; CHECK-APPLE-NEXT:    .loh AdrpLdr Lloh0, Lloh1
77entry:
78  %0 = load i32, i32* @a, align 4, !tbaa !2
79  %conv = sext i32 %0 to i64
80  %1 = inttoptr i64 %conv to i32*
81  %cmp = icmp eq i32* %1, %b
82  br i1 %cmp, label %if.then, label %if.end
83
84if.then:                                          ; preds = %entry
85  %call = tail call signext i32 bitcast (i32 (...)* @callVoid to i32 ()*)()
86  %call2 = tail call signext i32 @callNonVoid(i32* %b)
87  br label %if.end
88
89if.end:                                           ; preds = %if.then, %entry
90  %retval.0 = phi i32 [ %call2, %if.then ], [ undef, %entry ]
91  ret i32 %retval.0
92}
93
94declare signext i32 @callVoid(...) local_unnamed_addr
95
96declare signext i32 @callNonVoid(i32*) local_unnamed_addr
97
98define dso_local signext i32 @test2(i32* %p1) local_unnamed_addr uwtable  {
99; CHECK-LABEL: test2:
100; CHECK:       // %bb.0: // %entry
101; CHECK-NEXT:    stp x30, x19, [sp, #-16]! // 16-byte Folded Spill
102; CHECK-NEXT:    .cfi_def_cfa_offset 16
103; CHECK-NEXT:    .cfi_offset w19, -8
104; CHECK-NEXT:    .cfi_offset w30, -16
105; CHECK-NEXT:    .cfi_remember_state
106; CHECK-NEXT:    cbz x0, .LBB1_3
107; CHECK-NEXT:  // %bb.1: // %entry
108; CHECK-NEXT:    adrp x8, a
109; CHECK-NEXT:    mov x19, x0
110; CHECK-NEXT:    ldrsw x8, [x8, :lo12:a]
111; CHECK-NEXT:    cmp x8, x0
112; CHECK-NEXT:    b.ne .LBB1_3
113; CHECK-NEXT:  // %bb.2: // %if.then2
114; CHECK-NEXT:    bl callVoid
115; CHECK-NEXT:    mov x0, x19
116; CHECK-NEXT:    ldp x30, x19, [sp], #16 // 16-byte Folded Reload
117; CHECK-NEXT:    .cfi_def_cfa_offset 0
118; CHECK-NEXT:    .cfi_restore w19
119; CHECK-NEXT:    .cfi_restore w30
120; CHECK-NEXT:    b callNonVoid
121; CHECK-NEXT:  .LBB1_3: // %return
122; CHECK-NEXT:    .cfi_restore_state
123; CHECK-NEXT:    mov w0, wzr
124; CHECK-NEXT:    ldp x30, x19, [sp], #16 // 16-byte Folded Reload
125; CHECK-NEXT:    .cfi_def_cfa_offset 0
126; CHECK-NEXT:    .cfi_restore w19
127; CHECK-NEXT:    .cfi_restore w30
128; CHECK-NEXT:    ret
129;
130; CHECK-APPLE-LABEL: test2:
131; CHECK-APPLE:       ; %bb.0: ; %entry
132; CHECK-APPLE-NEXT:    stp x20, x19, [sp, #-32]! ; 16-byte Folded Spill
133; CHECK-APPLE-NEXT:    .cfi_def_cfa_offset 32
134; CHECK-APPLE-NEXT:    stp x29, x30, [sp, #16] ; 16-byte Folded Spill
135; CHECK-APPLE-NEXT:    .cfi_offset w30, -8
136; CHECK-APPLE-NEXT:    .cfi_offset w29, -16
137; CHECK-APPLE-NEXT:    .cfi_offset w19, -24
138; CHECK-APPLE-NEXT:    .cfi_offset w20, -32
139; CHECK-APPLE-NEXT:    .cfi_remember_state
140; CHECK-APPLE-NEXT:    cbz x0, LBB1_3
141; CHECK-APPLE-NEXT:  ; %bb.1: ; %entry
142; CHECK-APPLE-NEXT:  Lloh2:
143; CHECK-APPLE-NEXT:    adrp x8, _a@PAGE
144; CHECK-APPLE-NEXT:    mov x19, x0
145; CHECK-APPLE-NEXT:  Lloh3:
146; CHECK-APPLE-NEXT:    ldrsw x8, [x8, _a@PAGEOFF]
147; CHECK-APPLE-NEXT:    cmp x8, x0
148; CHECK-APPLE-NEXT:    b.ne LBB1_3
149; CHECK-APPLE-NEXT:  ; %bb.2: ; %if.then2
150; CHECK-APPLE-NEXT:    bl _callVoid
151; CHECK-APPLE-NEXT:    ldp x29, x30, [sp, #16] ; 16-byte Folded Reload
152; CHECK-APPLE-NEXT:    mov x0, x19
153; CHECK-APPLE-NEXT:    ldp x20, x19, [sp], #32 ; 16-byte Folded Reload
154; CHECK-APPLE-NEXT:    .cfi_def_cfa_offset 0
155; CHECK-APPLE-NEXT:    .cfi_restore w30
156; CHECK-APPLE-NEXT:    .cfi_restore w29
157; CHECK-APPLE-NEXT:    .cfi_restore w19
158; CHECK-APPLE-NEXT:    .cfi_restore w20
159; CHECK-APPLE-NEXT:    b _callNonVoid
160; CHECK-APPLE-NEXT:  LBB1_3: ; %return
161; CHECK-APPLE-NEXT:    .cfi_restore_state
162; CHECK-APPLE-NEXT:    ldp x29, x30, [sp, #16] ; 16-byte Folded Reload
163; CHECK-APPLE-NEXT:    mov w0, wzr
164; CHECK-APPLE-NEXT:    ldp x20, x19, [sp], #32 ; 16-byte Folded Reload
165; CHECK-APPLE-NEXT:    .cfi_def_cfa_offset 0
166; CHECK-APPLE-NEXT:    .cfi_restore w30
167; CHECK-APPLE-NEXT:    .cfi_restore w29
168; CHECK-APPLE-NEXT:    .cfi_restore w19
169; CHECK-APPLE-NEXT:    .cfi_restore w20
170; CHECK-APPLE-NEXT:    ret
171; CHECK-APPLE-NEXT:    .loh AdrpLdr Lloh2, Lloh3
172entry:
173  %tobool = icmp eq i32* %p1, null
174  br i1 %tobool, label %return, label %if.end
175
176if.end:                                           ; preds = %entry
177  %0 = load i32, i32* @a, align 4, !tbaa !2
178  %conv = sext i32 %0 to i64
179  %1 = inttoptr i64 %conv to i32*
180  %cmp = icmp eq i32* %1, %p1
181  br i1 %cmp, label %if.then2, label %return
182
183if.then2:                                         ; preds = %if.end
184  %call = tail call signext i32 bitcast (i32 (...)* @callVoid to i32 ()*)()
185  %call3 = tail call signext i32 @callNonVoid(i32* nonnull %p1)
186  br label %return
187
188return:                                           ; preds = %if.end, %entry, %if.then2
189  %retval.0 = phi i32 [ %call3, %if.then2 ], [ 0, %entry ], [ 0, %if.end ]
190  ret i32 %retval.0
191}
192
193
194define dso_local i8* @test3(i8** nocapture %p1, i8 zeroext %p2) local_unnamed_addr uwtable  {
195; CHECK-LABEL: test3:
196; CHECK:       // %bb.0: // %entry
197; CHECK-NEXT:    str x30, [sp, #-32]! // 8-byte Folded Spill
198; CHECK-NEXT:    .cfi_def_cfa_offset 32
199; CHECK-NEXT:    stp x20, x19, [sp, #16] // 16-byte Folded Spill
200; CHECK-NEXT:    .cfi_offset w19, -8
201; CHECK-NEXT:    .cfi_offset w20, -16
202; CHECK-NEXT:    .cfi_offset w30, -32
203; CHECK-NEXT:    ldr x19, [x0]
204; CHECK-NEXT:    cbz x19, .LBB2_2
205; CHECK-NEXT:  // %bb.1: // %land.rhs
206; CHECK-NEXT:    mov x20, x0
207; CHECK-NEXT:    mov x0, x19
208; CHECK-NEXT:    bl bar
209; CHECK-NEXT:    str x0, [x20]
210; CHECK-NEXT:  .LBB2_2: // %land.end
211; CHECK-NEXT:    mov x0, x19
212; CHECK-NEXT:    ldp x20, x19, [sp, #16] // 16-byte Folded Reload
213; CHECK-NEXT:    ldr x30, [sp], #32 // 8-byte Folded Reload
214; CHECK-NEXT:    .cfi_def_cfa_offset 0
215; CHECK-NEXT:    .cfi_restore w19
216; CHECK-NEXT:    .cfi_restore w20
217; CHECK-NEXT:    .cfi_restore w30
218; CHECK-NEXT:    ret
219;
220; CHECK-APPLE-LABEL: test3:
221; CHECK-APPLE:       ; %bb.0: ; %entry
222; CHECK-APPLE-NEXT:    stp x20, x19, [sp, #-32]! ; 16-byte Folded Spill
223; CHECK-APPLE-NEXT:    .cfi_def_cfa_offset 32
224; CHECK-APPLE-NEXT:    stp x29, x30, [sp, #16] ; 16-byte Folded Spill
225; CHECK-APPLE-NEXT:    .cfi_offset w30, -8
226; CHECK-APPLE-NEXT:    .cfi_offset w29, -16
227; CHECK-APPLE-NEXT:    .cfi_offset w19, -24
228; CHECK-APPLE-NEXT:    .cfi_offset w20, -32
229; CHECK-APPLE-NEXT:    ldr x19, [x0]
230; CHECK-APPLE-NEXT:    cbz x19, LBB2_2
231; CHECK-APPLE-NEXT:  ; %bb.1: ; %land.rhs
232; CHECK-APPLE-NEXT:    mov x20, x0
233; CHECK-APPLE-NEXT:    mov x0, x19
234; CHECK-APPLE-NEXT:    bl _bar
235; CHECK-APPLE-NEXT:    str x0, [x20]
236; CHECK-APPLE-NEXT:  LBB2_2: ; %land.end
237; CHECK-APPLE-NEXT:    ldp x29, x30, [sp, #16] ; 16-byte Folded Reload
238; CHECK-APPLE-NEXT:    mov x0, x19
239; CHECK-APPLE-NEXT:    ldp x20, x19, [sp], #32 ; 16-byte Folded Reload
240; CHECK-APPLE-NEXT:    .cfi_def_cfa_offset 0
241; CHECK-APPLE-NEXT:    .cfi_restore w30
242; CHECK-APPLE-NEXT:    .cfi_restore w29
243; CHECK-APPLE-NEXT:    .cfi_restore w19
244; CHECK-APPLE-NEXT:    .cfi_restore w20
245; CHECK-APPLE-NEXT:    ret
246entry:
247  %0 = load i8*, i8** %p1, align 8, !tbaa !6
248  %tobool = icmp eq i8* %0, null
249  br i1 %tobool, label %land.end, label %land.rhs
250
251land.rhs:                                         ; preds = %entry
252  %call = tail call i8* @bar(i8* nonnull %0, i8 zeroext %p2)
253  store i8* %call, i8** %p1, align 8, !tbaa !6
254  br label %land.end
255
256land.end:                                         ; preds = %entry, %land.rhs
257  ret i8* %0
258}
259
260declare i8* @bar(i8*, i8 zeroext) local_unnamed_addr
261
262
263!llvm.module.flags = !{!0}
264!llvm.ident = !{!1}
265
266!0 = !{i32 1, !"wchar_size", i32 4}
267!1 = !{!"clang version 10.0.0 (trunk 367381) (llvm/trunk 367388)"}
268!2 = !{!3, !3, i64 0}
269!3 = !{!"int", !4, i64 0}
270!4 = !{!"omnipotent char", !5, i64 0}
271!5 = !{!"Simple C/C++ TBAA"}
272!6 = !{!7, !7, i64 0}
273!7 = !{!"any pointer", !4, i64 0}
274