1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature --check-attributes --check-globals
2; RUN: opt -attributor -enable-new-pm=0 -attributor-manifest-internal  -attributor-max-iterations-verify -attributor-annotate-decl-cs -attributor-max-iterations=16 -S < %s | FileCheck %s --check-prefixes=CHECK,NOT_CGSCC_NPM,NOT_CGSCC_OPM,NOT_TUNIT_NPM,IS__TUNIT____,IS________OPM,IS__TUNIT_OPM
3; RUN: opt -aa-pipeline=basic-aa -passes=attributor -attributor-manifest-internal  -attributor-max-iterations-verify -attributor-annotate-decl-cs -attributor-max-iterations=16 -S < %s | FileCheck %s --check-prefixes=CHECK,NOT_CGSCC_OPM,NOT_CGSCC_NPM,NOT_TUNIT_OPM,IS__TUNIT____,IS________NPM,IS__TUNIT_NPM
4; RUN: opt -attributor-cgscc -enable-new-pm=0 -attributor-manifest-internal  -attributor-annotate-decl-cs -S < %s | FileCheck %s --check-prefixes=CHECK,NOT_TUNIT_NPM,NOT_TUNIT_OPM,NOT_CGSCC_NPM,IS__CGSCC____,IS________OPM,IS__CGSCC_OPM
5; RUN: opt -aa-pipeline=basic-aa -passes=attributor-cgscc -attributor-manifest-internal  -attributor-annotate-decl-cs -S < %s | FileCheck %s --check-prefixes=CHECK,NOT_TUNIT_NPM,NOT_TUNIT_OPM,NOT_CGSCC_OPM,IS__CGSCC____,IS________NPM,IS__CGSCC_NPM
6
7target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
8declare void @f(i32)
9declare token @llvm.call.preallocated.setup(i32)
10declare i8* @llvm.call.preallocated.arg(token, i32)
11
12@ConstAS3Ptr = addrspace(3) global i32 0, align 4
13
14;.
15; CHECK: @[[CONSTAS3PTR:[a-zA-Z0-9_$"\\.-]+]] = addrspace(3) global i32 0, align 4
16; CHECK: @[[S:[a-zA-Z0-9_$"\\.-]+]] = external global [[STRUCT_X:%.*]]
17; CHECK: @[[G:[a-zA-Z0-9_$"\\.-]+]] = internal constant { [2 x i8*] } { [2 x i8*] [i8* bitcast (void (i8***)* @f1 to i8*), i8* bitcast (void (i1 (i8*)*)* @f2 to i8*)] }
18;.
19define internal i32 addrspace(3)* @const_ptr_return_as3() {
20; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn
21; IS__CGSCC____-LABEL: define {{[^@]+}}@const_ptr_return_as3
22; IS__CGSCC____-SAME: () #[[ATTR1:[0-9]+]] {
23; IS__CGSCC____-NEXT:    ret i32 addrspace(3)* undef
24;
25  ret i32 addrspace(3)* @ConstAS3Ptr
26}
27define internal i32* @const_ptr_return() {
28; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn
29; IS__CGSCC____-LABEL: define {{[^@]+}}@const_ptr_return
30; IS__CGSCC____-SAME: () #[[ATTR1]] {
31; IS__CGSCC____-NEXT:    ret i32* undef
32;
33  ret i32* addrspacecast (i32 addrspace(3)* @ConstAS3Ptr to i32*)
34}
35
36; Test1: Replace argument with constant
37define internal void @test1(i32 %a) {
38; CHECK-LABEL: define {{[^@]+}}@test1() {
39; CHECK-NEXT:    tail call void @f(i32 noundef 1)
40; CHECK-NEXT:    ret void
41;
42  tail call void @f(i32 %a)
43  ret void
44}
45
46define void @test1_helper() {
47; CHECK-LABEL: define {{[^@]+}}@test1_helper() {
48; CHECK-NEXT:    tail call void @test1()
49; CHECK-NEXT:    ret void
50;
51  tail call void @test1(i32 1)
52  ret void
53}
54
55; TEST 2 : Simplify return value
56define i32 @return0() {
57; IS__TUNIT____: Function Attrs: nofree nosync nounwind readnone willreturn
58; IS__TUNIT____-LABEL: define {{[^@]+}}@return0
59; IS__TUNIT____-SAME: () #[[ATTR1:[0-9]+]] {
60; IS__TUNIT____-NEXT:    ret i32 0
61;
62; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn
63; IS__CGSCC____-LABEL: define {{[^@]+}}@return0
64; IS__CGSCC____-SAME: () #[[ATTR1]] {
65; IS__CGSCC____-NEXT:    ret i32 0
66;
67  ret i32 0
68}
69
70define i32 @return1() {
71; IS__TUNIT____: Function Attrs: nofree nosync nounwind readnone willreturn
72; IS__TUNIT____-LABEL: define {{[^@]+}}@return1
73; IS__TUNIT____-SAME: () #[[ATTR1]] {
74; IS__TUNIT____-NEXT:    ret i32 1
75;
76; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn
77; IS__CGSCC____-LABEL: define {{[^@]+}}@return1
78; IS__CGSCC____-SAME: () #[[ATTR1]] {
79; IS__CGSCC____-NEXT:    ret i32 1
80;
81  ret i32 1
82}
83
84define i32 @test2_1(i1 %c) {
85; IS__TUNIT____: Function Attrs: nofree nosync nounwind readnone willreturn
86; IS__TUNIT____-LABEL: define {{[^@]+}}@test2_1
87; IS__TUNIT____-SAME: (i1 [[C:%.*]]) #[[ATTR1]] {
88; IS__TUNIT____-NEXT:    br i1 [[C]], label [[IF_TRUE:%.*]], label [[IF_FALSE:%.*]]
89; IS__TUNIT____:       if.true:
90; IS__TUNIT____-NEXT:    [[RET0:%.*]] = add i32 0, 1
91; IS__TUNIT____-NEXT:    br label [[END:%.*]]
92; IS__TUNIT____:       if.false:
93; IS__TUNIT____-NEXT:    br label [[END]]
94; IS__TUNIT____:       end:
95; IS__TUNIT____-NEXT:    [[RET:%.*]] = phi i32 [ [[RET0]], [[IF_TRUE]] ], [ 1, [[IF_FALSE]] ]
96; IS__TUNIT____-NEXT:    ret i32 1
97;
98; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn
99; IS__CGSCC____-LABEL: define {{[^@]+}}@test2_1
100; IS__CGSCC____-SAME: (i1 [[C:%.*]]) #[[ATTR1]] {
101; IS__CGSCC____-NEXT:    br i1 [[C]], label [[IF_TRUE:%.*]], label [[IF_FALSE:%.*]]
102; IS__CGSCC____:       if.true:
103; IS__CGSCC____-NEXT:    [[RET0:%.*]] = add i32 0, 1
104; IS__CGSCC____-NEXT:    br label [[END:%.*]]
105; IS__CGSCC____:       if.false:
106; IS__CGSCC____-NEXT:    br label [[END]]
107; IS__CGSCC____:       end:
108; IS__CGSCC____-NEXT:    [[RET:%.*]] = phi i32 [ [[RET0]], [[IF_TRUE]] ], [ 1, [[IF_FALSE]] ]
109; IS__CGSCC____-NEXT:    ret i32 1
110;
111  br i1 %c, label %if.true, label %if.false
112if.true:
113  %call = tail call i32 @return0()
114  %ret0 = add i32 %call, 1
115  br label %end
116if.false:
117  %ret1 = tail call i32 @return1()
118  br label %end
119end:
120
121  %ret = phi i32 [ %ret0, %if.true ], [ %ret1, %if.false ]
122
123  ret i32 1
124}
125
126
127
128define i32 @test2_2(i1 %c) {
129; IS__TUNIT____: Function Attrs: nofree nosync nounwind readnone willreturn
130; IS__TUNIT____-LABEL: define {{[^@]+}}@test2_2
131; IS__TUNIT____-SAME: (i1 [[C:%.*]]) #[[ATTR1]] {
132; IS__TUNIT____-NEXT:    ret i32 1
133;
134; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn
135; IS__CGSCC____-LABEL: define {{[^@]+}}@test2_2
136; IS__CGSCC____-SAME: (i1 [[C:%.*]]) #[[ATTR1]] {
137; IS__CGSCC____-NEXT:    ret i32 1
138;
139  %ret = tail call i32 @test2_1(i1 %c)
140  ret i32 %ret
141}
142
143declare void @use(i32)
144define void @test3(i1 %c) {
145; CHECK-LABEL: define {{[^@]+}}@test3
146; CHECK-SAME: (i1 [[C:%.*]]) {
147; CHECK-NEXT:    br i1 [[C]], label [[IF_TRUE:%.*]], label [[IF_FALSE:%.*]]
148; CHECK:       if.true:
149; CHECK-NEXT:    br label [[END:%.*]]
150; CHECK:       if.false:
151; CHECK-NEXT:    br label [[END]]
152; CHECK:       end:
153; CHECK-NEXT:    [[R:%.*]] = phi i32 [ 1, [[IF_TRUE]] ], [ 1, [[IF_FALSE]] ]
154; CHECK-NEXT:    tail call void @use(i32 noundef 1)
155; CHECK-NEXT:    ret void
156;
157  br i1 %c, label %if.true, label %if.false
158if.true:
159  br label %end
160if.false:
161  %ret1 = tail call i32 @return1()
162  br label %end
163end:
164
165  %r = phi i32 [ 1, %if.true ], [ %ret1, %if.false ]
166
167  tail call void @use(i32 %r)
168  ret void
169}
170
171define void @test-select-phi(i1 %c) {
172; CHECK-LABEL: define {{[^@]+}}@test-select-phi
173; CHECK-SAME: (i1 [[C:%.*]]) {
174; CHECK-NEXT:    tail call void @use(i32 noundef 1)
175; CHECK-NEXT:    [[SELECT_NOT_SAME:%.*]] = select i1 [[C]], i32 1, i32 0
176; CHECK-NEXT:    tail call void @use(i32 noundef [[SELECT_NOT_SAME]])
177; CHECK-NEXT:    br i1 [[C]], label [[IF_TRUE:%.*]], label [[IF_FALSE:%.*]]
178; CHECK:       if-true:
179; CHECK-NEXT:    br label [[END:%.*]]
180; CHECK:       if-false:
181; CHECK-NEXT:    br label [[END]]
182; CHECK:       end:
183; CHECK-NEXT:    [[PHI_SAME:%.*]] = phi i32 [ 1, [[IF_TRUE]] ], [ 1, [[IF_FALSE]] ]
184; CHECK-NEXT:    [[PHI_NOT_SAME:%.*]] = phi i32 [ 0, [[IF_TRUE]] ], [ 1, [[IF_FALSE]] ]
185; CHECK-NEXT:    [[PHI_SAME_PROP:%.*]] = phi i32 [ 1, [[IF_TRUE]] ], [ 1, [[IF_FALSE]] ]
186; CHECK-NEXT:    [[PHI_SAME_UNDEF:%.*]] = phi i32 [ 1, [[IF_TRUE]] ], [ undef, [[IF_FALSE]] ]
187; CHECK-NEXT:    [[SELECT_NOT_SAME_UNDEF:%.*]] = select i1 [[C]], i32 [[PHI_NOT_SAME]], i32 undef
188; CHECK-NEXT:    tail call void @use(i32 noundef 1)
189; CHECK-NEXT:    tail call void @use(i32 noundef [[PHI_NOT_SAME]])
190; CHECK-NEXT:    tail call void @use(i32 noundef 1)
191; CHECK-NEXT:    tail call void @use(i32 1)
192; CHECK-NEXT:    tail call void @use(i32 [[SELECT_NOT_SAME_UNDEF]])
193; CHECK-NEXT:    ret void
194;
195  %select-same = select i1 %c, i32 1, i32 1
196  tail call void @use(i32 %select-same)
197
198  %select-not-same = select i1 %c, i32 1, i32 0
199  tail call void @use(i32 %select-not-same)
200  br i1 %c, label %if-true, label %if-false
201if-true:
202  br label %end
203if-false:
204  br label %end
205end:
206  %phi-same = phi i32 [ 1, %if-true ], [ 1, %if-false ]
207  %phi-not-same = phi i32 [ 0, %if-true ], [ 1, %if-false ]
208  %phi-same-prop = phi i32 [ 1, %if-true ], [ %select-same, %if-false ]
209  %phi-same-undef = phi i32 [ 1, %if-true ], [ undef, %if-false ]
210  %select-not-same-undef = select i1 %c, i32 %phi-not-same, i32 undef
211
212
213  tail call void @use(i32 %phi-same)
214
215  tail call void @use(i32 %phi-not-same)
216
217  tail call void @use(i32 %phi-same-prop)
218
219  tail call void @use(i32 %phi-same-undef)
220
221  tail call void @use(i32 %select-not-same-undef)
222
223  ret void
224
225}
226
227define i32 @ipccp1(i32 %a) {
228; IS__TUNIT____: Function Attrs: nofree nosync nounwind readnone willreturn
229; IS__TUNIT____-LABEL: define {{[^@]+}}@ipccp1
230; IS__TUNIT____-SAME: (i32 returned [[A:%.*]]) #[[ATTR1]] {
231; IS__TUNIT____-NEXT:    br i1 true, label [[T:%.*]], label [[F:%.*]]
232; IS__TUNIT____:       t:
233; IS__TUNIT____-NEXT:    ret i32 [[A]]
234; IS__TUNIT____:       f:
235; IS__TUNIT____-NEXT:    unreachable
236;
237; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn
238; IS__CGSCC____-LABEL: define {{[^@]+}}@ipccp1
239; IS__CGSCC____-SAME: (i32 returned [[A:%.*]]) #[[ATTR1]] {
240; IS__CGSCC____-NEXT:    br i1 true, label [[T:%.*]], label [[F:%.*]]
241; IS__CGSCC____:       t:
242; IS__CGSCC____-NEXT:    ret i32 [[A]]
243; IS__CGSCC____:       f:
244; IS__CGSCC____-NEXT:    unreachable
245;
246  br i1 true, label %t, label %f
247t:
248  ret i32 %a
249f:
250  %r = call i32 @ipccp1(i32 5)
251  ret i32 %r
252}
253
254define internal i1 @ipccp2i(i1 %a) {
255; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn
256; IS__CGSCC____-LABEL: define {{[^@]+}}@ipccp2i
257; IS__CGSCC____-SAME: () #[[ATTR1]] {
258; IS__CGSCC____-NEXT:    br label [[T:%.*]]
259; IS__CGSCC____:       t:
260; IS__CGSCC____-NEXT:    ret i1 undef
261; IS__CGSCC____:       f:
262; IS__CGSCC____-NEXT:    unreachable
263;
264  br i1 %a, label %t, label %f
265t:
266  ret i1 %a
267f:
268  %r = call i1 @ipccp2i(i1 false)
269  ret i1 %r
270}
271
272define i1 @ipccp2() {
273; IS__TUNIT____: Function Attrs: nofree nosync nounwind readnone willreturn
274; IS__TUNIT____-LABEL: define {{[^@]+}}@ipccp2
275; IS__TUNIT____-SAME: () #[[ATTR1]] {
276; IS__TUNIT____-NEXT:    ret i1 true
277;
278; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn
279; IS__CGSCC____-LABEL: define {{[^@]+}}@ipccp2
280; IS__CGSCC____-SAME: () #[[ATTR1]] {
281; IS__CGSCC____-NEXT:    ret i1 true
282;
283  %r = call i1 @ipccp2i(i1 true)
284  ret i1 %r
285}
286
287define internal i1 @ipccp2ib(i1 %a) {
288; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn
289; IS__CGSCC____-LABEL: define {{[^@]+}}@ipccp2ib
290; IS__CGSCC____-SAME: () #[[ATTR1]] {
291; IS__CGSCC____-NEXT:    br label [[T:%.*]]
292; IS__CGSCC____:       t:
293; IS__CGSCC____-NEXT:    ret i1 undef
294; IS__CGSCC____:       f:
295; IS__CGSCC____-NEXT:    unreachable
296;
297  br i1 %a, label %t, label %f
298t:
299  ret i1 true
300f:
301  %r = call i1 @ipccp2ib(i1 false)
302  ret i1 %r
303}
304
305define i1 @ipccp2b() {
306; IS__TUNIT____: Function Attrs: nofree nosync nounwind readnone willreturn
307; IS__TUNIT____-LABEL: define {{[^@]+}}@ipccp2b
308; IS__TUNIT____-SAME: () #[[ATTR1]] {
309; IS__TUNIT____-NEXT:    ret i1 true
310;
311; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn
312; IS__CGSCC____-LABEL: define {{[^@]+}}@ipccp2b
313; IS__CGSCC____-SAME: () #[[ATTR1]] {
314; IS__CGSCC____-NEXT:    ret i1 true
315;
316  %r = call i1 @ipccp2ib(i1 true)
317  ret i1 %r
318}
319
320define internal i32 @ipccp3i(i32 %a) {
321; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn
322; IS__CGSCC____-LABEL: define {{[^@]+}}@ipccp3i
323; IS__CGSCC____-SAME: () #[[ATTR1]] {
324; IS__CGSCC____-NEXT:    br label [[T:%.*]]
325; IS__CGSCC____:       t:
326; IS__CGSCC____-NEXT:    ret i32 undef
327; IS__CGSCC____:       f:
328; IS__CGSCC____-NEXT:    unreachable
329;
330  %c = icmp eq i32 %a, 7
331  br i1 %c, label %t, label %f
332t:
333  ret i32 %a
334f:
335  %r = call i32 @ipccp3i(i32 5)
336  ret i32 %r
337}
338
339define i32 @ipccp3() {
340; IS__TUNIT____: Function Attrs: nofree nosync nounwind readnone willreturn
341; IS__TUNIT____-LABEL: define {{[^@]+}}@ipccp3
342; IS__TUNIT____-SAME: () #[[ATTR1]] {
343; IS__TUNIT____-NEXT:    ret i32 7
344;
345; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn
346; IS__CGSCC____-LABEL: define {{[^@]+}}@ipccp3
347; IS__CGSCC____-SAME: () #[[ATTR1]] {
348; IS__CGSCC____-NEXT:    ret i32 7
349;
350  %r = call i32 @ipccp3i(i32 7)
351  ret i32 %r
352}
353
354define internal i32 @ipccp4ia(i1 %c) {
355; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn
356; IS__CGSCC____-LABEL: define {{[^@]+}}@ipccp4ia
357; IS__CGSCC____-SAME: () #[[ATTR1]] {
358; IS__CGSCC____-NEXT:    br label [[T:%.*]]
359; IS__CGSCC____:       t:
360; IS__CGSCC____-NEXT:    ret i32 undef
361; IS__CGSCC____:       f:
362; IS__CGSCC____-NEXT:    unreachable
363;
364  br i1 %c, label %t, label %f
365t:
366  ret i32 0
367f:
368  ret i32 1
369}
370define internal i32 @ipccp4ib(i32 %a) {
371; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn
372; IS__CGSCC____-LABEL: define {{[^@]+}}@ipccp4ib
373; IS__CGSCC____-SAME: () #[[ATTR1]] {
374; IS__CGSCC____-NEXT:    [[C:%.*]] = icmp eq i32 7, 7
375; IS__CGSCC____-NEXT:    br i1 true, label [[T:%.*]], label [[F:%.*]]
376; IS__CGSCC____:       t:
377; IS__CGSCC____-NEXT:    ret i32 undef
378; IS__CGSCC____:       f:
379; IS__CGSCC____-NEXT:    unreachable
380;
381  %c = icmp eq i32 %a, 7
382  br i1 %c, label %t, label %f
383t:
384  %r = call i32 @ipccp4ia(i1 %c)
385  ret i32 %r
386f:
387  ret i32 1
388}
389
390define i32 @ipccp4(i1 %c) {
391; IS__TUNIT____: Function Attrs: nofree nosync nounwind readnone willreturn
392; IS__TUNIT____-LABEL: define {{[^@]+}}@ipccp4
393; IS__TUNIT____-SAME: (i1 [[C:%.*]]) #[[ATTR1]] {
394; IS__TUNIT____-NEXT:    br i1 [[C]], label [[T:%.*]], label [[F:%.*]]
395; IS__TUNIT____:       t:
396; IS__TUNIT____-NEXT:    br label [[F]]
397; IS__TUNIT____:       f:
398; IS__TUNIT____-NEXT:    ret i32 0
399;
400; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn
401; IS__CGSCC____-LABEL: define {{[^@]+}}@ipccp4
402; IS__CGSCC____-SAME: (i1 [[C:%.*]]) #[[ATTR1]] {
403; IS__CGSCC____-NEXT:    br i1 [[C]], label [[T:%.*]], label [[F:%.*]]
404; IS__CGSCC____:       t:
405; IS__CGSCC____-NEXT:    br label [[F]]
406; IS__CGSCC____:       f:
407; IS__CGSCC____-NEXT:    ret i32 0
408;
409  br i1 %c, label %t, label %f
410t:
411  %q = call i32 @ipccp4ia(i1 undef)
412  br label %f
413f:
414  %r = call i32 @ipccp4ib(i32 7)
415  ret i32 %r
416}
417
418; Do not touch complicated arguments (for now)
419%struct.X = type { i8* }
420define internal i32* @test_inalloca(i32* inalloca(i32) %a) {
421; IS__TUNIT____: Function Attrs: nofree nosync nounwind readnone willreturn
422; IS__TUNIT____-LABEL: define {{[^@]+}}@test_inalloca
423; IS__TUNIT____-SAME: (i32* noalias nofree nonnull returned writeonly inalloca(i32) dereferenceable(4) "no-capture-maybe-returned" [[A:%.*]]) #[[ATTR1]] {
424; IS__TUNIT____-NEXT:    ret i32* [[A]]
425;
426; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn
427; IS__CGSCC____-LABEL: define {{[^@]+}}@test_inalloca
428; IS__CGSCC____-SAME: (i32* noalias nofree noundef nonnull returned writeonly inalloca(i32) dereferenceable(4) "no-capture-maybe-returned" [[A:%.*]]) #[[ATTR1]] {
429; IS__CGSCC____-NEXT:    ret i32* [[A]]
430;
431  ret i32* %a
432}
433define i32* @complicated_args_inalloca(i32* %arg) {
434; IS__TUNIT____: Function Attrs: nofree nosync nounwind readnone willreturn
435; IS__TUNIT____-LABEL: define {{[^@]+}}@complicated_args_inalloca
436; IS__TUNIT____-SAME: (i32* nofree readnone "no-capture-maybe-returned" [[ARG:%.*]]) #[[ATTR1]] {
437; IS__TUNIT____-NEXT:    [[CALL:%.*]] = call nonnull dereferenceable(4) i32* @test_inalloca(i32* noalias nofree writeonly inalloca(i32) "no-capture-maybe-returned" [[ARG]]) #[[ATTR1]]
438; IS__TUNIT____-NEXT:    ret i32* [[CALL]]
439;
440; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn
441; IS__CGSCC____-LABEL: define {{[^@]+}}@complicated_args_inalloca
442; IS__CGSCC____-SAME: (i32* nofree noundef nonnull readnone returned dereferenceable(4) "no-capture-maybe-returned" [[ARG:%.*]]) #[[ATTR1]] {
443; IS__CGSCC____-NEXT:    ret i32* [[ARG]]
444;
445  %call = call i32* @test_inalloca(i32* inalloca(i32) %arg)
446  ret i32* %call
447}
448
449define internal i32* @test_preallocated(i32* preallocated(i32) %a) {
450; IS__TUNIT____: Function Attrs: nofree nosync nounwind readnone willreturn
451; IS__TUNIT____-LABEL: define {{[^@]+}}@test_preallocated
452; IS__TUNIT____-SAME: (i32* noalias nofree noundef nonnull returned writeonly preallocated(i32) align 536870912 dereferenceable(4) "no-capture-maybe-returned" [[A:%.*]]) #[[ATTR1]] {
453; IS__TUNIT____-NEXT:    ret i32* [[A]]
454;
455; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn
456; IS__CGSCC____-LABEL: define {{[^@]+}}@test_preallocated
457; IS__CGSCC____-SAME: (i32* noalias nofree noundef nonnull returned writeonly preallocated(i32) align 536870912 dereferenceable(4) "no-capture-maybe-returned" [[A:%.*]]) #[[ATTR1]] {
458; IS__CGSCC____-NEXT:    ret i32* [[A]]
459;
460  ret i32* %a
461}
462define i32* @complicated_args_preallocated() {
463; IS__TUNIT_OPM: Function Attrs: nofree nosync nounwind willreturn
464; IS__TUNIT_OPM-LABEL: define {{[^@]+}}@complicated_args_preallocated
465; IS__TUNIT_OPM-SAME: () #[[ATTR0:[0-9]+]] {
466; IS__TUNIT_OPM-NEXT:    [[C:%.*]] = call token @llvm.call.preallocated.setup(i32 noundef 1) #[[ATTR5:[0-9]+]]
467; IS__TUNIT_OPM-NEXT:    [[CALL:%.*]] = call noundef nonnull align 536870912 dereferenceable(4) i32* @test_preallocated(i32* noalias nocapture nofree noundef writeonly preallocated(i32) align 536870912 null) #[[ATTR1]] [ "preallocated"(token [[C]]) ]
468; IS__TUNIT_OPM-NEXT:    ret i32* [[CALL]]
469;
470; IS__TUNIT_NPM: Function Attrs: nofree nosync nounwind willreturn
471; IS__TUNIT_NPM-LABEL: define {{[^@]+}}@complicated_args_preallocated
472; IS__TUNIT_NPM-SAME: () #[[ATTR0:[0-9]+]] {
473; IS__TUNIT_NPM-NEXT:    [[C:%.*]] = call token @llvm.call.preallocated.setup(i32 noundef 1) #[[ATTR4:[0-9]+]]
474; IS__TUNIT_NPM-NEXT:    [[CALL:%.*]] = call noundef nonnull align 536870912 dereferenceable(4) i32* @test_preallocated(i32* noalias nocapture nofree noundef writeonly preallocated(i32) align 536870912 null) #[[ATTR1]] [ "preallocated"(token [[C]]) ]
475; IS__TUNIT_NPM-NEXT:    ret i32* [[CALL]]
476;
477; IS__CGSCC_OPM: Function Attrs: nofree nosync nounwind willreturn
478; IS__CGSCC_OPM-LABEL: define {{[^@]+}}@complicated_args_preallocated
479; IS__CGSCC_OPM-SAME: () #[[ATTR0:[0-9]+]] {
480; IS__CGSCC_OPM-NEXT:    [[C:%.*]] = call token @llvm.call.preallocated.setup(i32 noundef 1) #[[ATTR5:[0-9]+]]
481; IS__CGSCC_OPM-NEXT:    ret i32* null
482;
483; IS__CGSCC_NPM: Function Attrs: nofree nosync nounwind willreturn
484; IS__CGSCC_NPM-LABEL: define {{[^@]+}}@complicated_args_preallocated
485; IS__CGSCC_NPM-SAME: () #[[ATTR0:[0-9]+]] {
486; IS__CGSCC_NPM-NEXT:    [[C:%.*]] = call token @llvm.call.preallocated.setup(i32 noundef 1) #[[ATTR4:[0-9]+]]
487; IS__CGSCC_NPM-NEXT:    ret i32* null
488;
489  %c = call token @llvm.call.preallocated.setup(i32 1)
490  %call = call i32* @test_preallocated(i32* preallocated(i32) null) ["preallocated"(token %c)]
491  ret i32* %call
492}
493
494define internal void @test_sret(%struct.X* sret(%struct.X) %a, %struct.X** %b) {
495;
496; IS__TUNIT____: Function Attrs: argmemonly nofree nosync nounwind willreturn writeonly
497; IS__TUNIT____-LABEL: define {{[^@]+}}@test_sret
498; IS__TUNIT____-SAME: (%struct.X* noalias nofree noundef nonnull writeonly sret([[STRUCT_X:%.*]]) align 536870912 dereferenceable(8) [[A:%.*]], %struct.X** nocapture nofree noundef nonnull writeonly align 8 dereferenceable(8) [[B:%.*]]) #[[ATTR2:[0-9]+]] {
499; IS__TUNIT____-NEXT:    store %struct.X* [[A]], %struct.X** [[B]], align 8
500; IS__TUNIT____-NEXT:    ret void
501;
502; IS__CGSCC____: Function Attrs: argmemonly nofree norecurse nosync nounwind willreturn writeonly
503; IS__CGSCC____-LABEL: define {{[^@]+}}@test_sret
504; IS__CGSCC____-SAME: (%struct.X* noalias nofree noundef nonnull writeonly sret([[STRUCT_X:%.*]]) align 536870912 dereferenceable(8) [[A:%.*]], %struct.X** nocapture nofree noundef nonnull writeonly align 8 dereferenceable(8) [[B:%.*]]) #[[ATTR2:[0-9]+]] {
505; IS__CGSCC____-NEXT:    store %struct.X* [[A]], %struct.X** [[B]], align 8
506; IS__CGSCC____-NEXT:    ret void
507;
508  store %struct.X* %a, %struct.X** %b
509  ret void
510}
511; FIXME: Alignment and dereferenceability are not propagated to the argument
512define void @complicated_args_sret(%struct.X** %b) {
513;
514; IS__TUNIT_OPM: Function Attrs: argmemonly nofree nosync nounwind willreturn writeonly
515; IS__TUNIT_OPM-LABEL: define {{[^@]+}}@complicated_args_sret
516; IS__TUNIT_OPM-SAME: (%struct.X** nocapture nofree writeonly [[B:%.*]]) #[[ATTR2]] {
517; IS__TUNIT_OPM-NEXT:    call void @test_sret(%struct.X* noalias nocapture nofree noundef writeonly sret([[STRUCT_X:%.*]]) align 536870912 null, %struct.X** nocapture nofree writeonly align 8 [[B]]) #[[ATTR4:[0-9]+]]
518; IS__TUNIT_OPM-NEXT:    ret void
519;
520; IS__TUNIT_NPM: Function Attrs: argmemonly nofree nosync nounwind willreturn writeonly
521; IS__TUNIT_NPM-LABEL: define {{[^@]+}}@complicated_args_sret
522; IS__TUNIT_NPM-SAME: (%struct.X** nocapture nofree writeonly [[B:%.*]]) #[[ATTR2]] {
523; IS__TUNIT_NPM-NEXT:    call void @test_sret(%struct.X* noalias nocapture nofree noundef writeonly sret([[STRUCT_X:%.*]]) align 536870912 null, %struct.X** nocapture nofree writeonly align 8 [[B]]) #[[ATTR3:[0-9]+]]
524; IS__TUNIT_NPM-NEXT:    ret void
525;
526; IS__CGSCC____: Function Attrs: argmemonly nofree norecurse nosync nounwind willreturn writeonly
527; IS__CGSCC____-LABEL: define {{[^@]+}}@complicated_args_sret
528; IS__CGSCC____-SAME: (%struct.X** nocapture nofree noundef nonnull writeonly align 8 dereferenceable(8) [[B:%.*]]) #[[ATTR2]] {
529; IS__CGSCC____-NEXT:    unreachable
530;
531  call void @test_sret(%struct.X* sret(%struct.X) null, %struct.X** %b)
532  ret void
533}
534
535define internal %struct.X* @test_nest(%struct.X* nest %a) {
536; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn
537; IS__CGSCC____-LABEL: define {{[^@]+}}@test_nest
538; IS__CGSCC____-SAME: (%struct.X* nest noalias nocapture nofree readnone align 536870912 [[A:%.*]]) #[[ATTR1]] {
539; IS__CGSCC____-NEXT:    ret %struct.X* undef
540;
541  ret %struct.X* %a
542}
543define %struct.X* @complicated_args_nest() {
544; IS__TUNIT____: Function Attrs: nofree nosync nounwind readnone willreturn
545; IS__TUNIT____-LABEL: define {{[^@]+}}@complicated_args_nest
546; IS__TUNIT____-SAME: () #[[ATTR1]] {
547; IS__TUNIT____-NEXT:    ret %struct.X* null
548;
549; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn
550; IS__CGSCC____-LABEL: define {{[^@]+}}@complicated_args_nest
551; IS__CGSCC____-SAME: () #[[ATTR1]] {
552; IS__CGSCC____-NEXT:    ret %struct.X* null
553;
554  %call = call %struct.X* @test_nest(%struct.X* null)
555  ret %struct.X* %call
556}
557
558@S = external global %struct.X
559define internal void @test_byval(%struct.X* byval(%struct.X) %a) {
560; IS__CGSCC_OPM: Function Attrs: nofree norecurse nosync nounwind readnone willreturn
561; IS__CGSCC_OPM-LABEL: define {{[^@]+}}@test_byval
562; IS__CGSCC_OPM-SAME: (%struct.X* noalias nocapture nofree noundef nonnull writeonly byval([[STRUCT_X:%.*]]) align 8 dereferenceable(8) [[A:%.*]]) #[[ATTR1]] {
563; IS__CGSCC_OPM-NEXT:    [[G0:%.*]] = getelementptr [[STRUCT_X]], %struct.X* [[A]], i32 0, i32 0
564; IS__CGSCC_OPM-NEXT:    store i8* null, i8** [[G0]], align 8
565; IS__CGSCC_OPM-NEXT:    ret void
566;
567; IS__CGSCC_NPM: Function Attrs: nofree norecurse nosync nounwind readnone willreturn
568; IS__CGSCC_NPM-LABEL: define {{[^@]+}}@test_byval
569; IS__CGSCC_NPM-SAME: (i8* noalias nocapture nofree readnone [[TMP0:%.*]]) #[[ATTR1]] {
570; IS__CGSCC_NPM-NEXT:    [[A_PRIV:%.*]] = alloca [[STRUCT_X:%.*]], align 8
571; IS__CGSCC_NPM-NEXT:    [[A_PRIV_CAST:%.*]] = bitcast %struct.X* [[A_PRIV]] to i8**
572; IS__CGSCC_NPM-NEXT:    [[G0:%.*]] = getelementptr [[STRUCT_X]], %struct.X* [[A_PRIV]], i32 0, i32 0
573; IS__CGSCC_NPM-NEXT:    store i8* null, i8** [[G0]], align 8
574; IS__CGSCC_NPM-NEXT:    ret void
575;
576  %g0 = getelementptr %struct.X, %struct.X* %a, i32 0, i32 0
577  store i8* null, i8** %g0
578  ret void
579}
580define void @complicated_args_byval() {
581; IS__TUNIT____: Function Attrs: nofree nosync nounwind readnone willreturn
582; IS__TUNIT____-LABEL: define {{[^@]+}}@complicated_args_byval
583; IS__TUNIT____-SAME: () #[[ATTR1]] {
584; IS__TUNIT____-NEXT:    ret void
585;
586; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn
587; IS__CGSCC____-LABEL: define {{[^@]+}}@complicated_args_byval
588; IS__CGSCC____-SAME: () #[[ATTR1]] {
589; IS__CGSCC____-NEXT:    ret void
590;
591  call void @test_byval(%struct.X* byval(%struct.X) @S)
592  ret void
593}
594
595declare void @sync()
596; Make sure we *do not* load @S here!
597define internal i8*@test_byval2(%struct.X* byval(%struct.X) %a) {
598; IS________OPM-LABEL: define {{[^@]+}}@test_byval2
599; IS________OPM-SAME: (%struct.X* noalias nocapture nofree noundef nonnull readonly byval([[STRUCT_X:%.*]]) align 8 dereferenceable(8) [[A:%.*]]) {
600; IS________OPM-NEXT:    call void @sync()
601; IS________OPM-NEXT:    [[G0:%.*]] = getelementptr [[STRUCT_X]], %struct.X* [[A]], i32 0, i32 0
602; IS________OPM-NEXT:    [[L:%.*]] = load i8*, i8** [[G0]], align 8
603; IS________OPM-NEXT:    ret i8* [[L]]
604;
605; IS__TUNIT_NPM-LABEL: define {{[^@]+}}@test_byval2
606; IS__TUNIT_NPM-SAME: (i8* [[TMP0:%.*]]) {
607; IS__TUNIT_NPM-NEXT:    [[A_PRIV:%.*]] = alloca [[STRUCT_X:%.*]], align 8
608; IS__TUNIT_NPM-NEXT:    [[A_PRIV_CAST:%.*]] = bitcast %struct.X* [[A_PRIV]] to i8**
609; IS__TUNIT_NPM-NEXT:    store i8* [[TMP0]], i8** [[A_PRIV_CAST]], align 8
610; IS__TUNIT_NPM-NEXT:    call void @sync()
611; IS__TUNIT_NPM-NEXT:    [[G0:%.*]] = getelementptr [[STRUCT_X]], %struct.X* [[A_PRIV]], i32 0, i32 0
612; IS__TUNIT_NPM-NEXT:    [[L:%.*]] = load i8*, i8** [[G0]], align 8
613; IS__TUNIT_NPM-NEXT:    ret i8* [[L]]
614;
615; IS__CGSCC_NPM-LABEL: define {{[^@]+}}@test_byval2
616; IS__CGSCC_NPM-SAME: (i8* noalias nofree readnone returned "no-capture-maybe-returned" [[TMP0:%.*]]) {
617; IS__CGSCC_NPM-NEXT:    [[A_PRIV:%.*]] = alloca [[STRUCT_X:%.*]], align 8
618; IS__CGSCC_NPM-NEXT:    [[A_PRIV_CAST:%.*]] = bitcast %struct.X* [[A_PRIV]] to i8**
619; IS__CGSCC_NPM-NEXT:    store i8* [[TMP0]], i8** [[A_PRIV_CAST]], align 8
620; IS__CGSCC_NPM-NEXT:    call void @sync()
621; IS__CGSCC_NPM-NEXT:    [[G0:%.*]] = getelementptr [[STRUCT_X]], %struct.X* [[A_PRIV]], i32 0, i32 0
622; IS__CGSCC_NPM-NEXT:    [[L:%.*]] = load i8*, i8** [[G0]], align 8
623; IS__CGSCC_NPM-NEXT:    ret i8* [[TMP0]]
624;
625  call void @sync()
626  %g0 = getelementptr %struct.X, %struct.X* %a, i32 0, i32 0
627  %l = load i8*, i8** %g0
628  ret i8* %l
629}
630define i8* @complicated_args_byval2() {
631;
632; IS__TUNIT_OPM-LABEL: define {{[^@]+}}@complicated_args_byval2() {
633; IS__TUNIT_OPM-NEXT:    [[C:%.*]] = call i8* @test_byval2(%struct.X* nocapture nofree noundef nonnull readonly byval([[STRUCT_X:%.*]]) align 8 dereferenceable(8) @S)
634; IS__TUNIT_OPM-NEXT:    ret i8* [[C]]
635;
636; IS__TUNIT_NPM-LABEL: define {{[^@]+}}@complicated_args_byval2() {
637; IS__TUNIT_NPM-NEXT:    [[S_CAST:%.*]] = bitcast %struct.X* @S to i8**
638; IS__TUNIT_NPM-NEXT:    [[TMP1:%.*]] = load i8*, i8** [[S_CAST]], align 8
639; IS__TUNIT_NPM-NEXT:    [[C:%.*]] = call i8* @test_byval2(i8* [[TMP1]])
640; IS__TUNIT_NPM-NEXT:    ret i8* [[C]]
641;
642; IS__CGSCC_OPM-LABEL: define {{[^@]+}}@complicated_args_byval2() {
643; IS__CGSCC_OPM-NEXT:    [[C:%.*]] = call i8* @test_byval2(%struct.X* noalias nocapture nofree noundef nonnull readonly byval([[STRUCT_X:%.*]]) align 8 dereferenceable(8) @S)
644; IS__CGSCC_OPM-NEXT:    ret i8* [[C]]
645;
646; IS__CGSCC_NPM-LABEL: define {{[^@]+}}@complicated_args_byval2() {
647; IS__CGSCC_NPM-NEXT:    [[TMP1:%.*]] = load i8*, i8** getelementptr inbounds ([[STRUCT_X:%.*]], %struct.X* @S, i32 0, i32 0), align 8
648; IS__CGSCC_NPM-NEXT:    [[C:%.*]] = call i8* @test_byval2(i8* noalias nofree readnone "no-capture-maybe-returned" [[TMP1]])
649; IS__CGSCC_NPM-NEXT:    ret i8* [[TMP1]]
650;
651  %c = call i8* @test_byval2(%struct.X* byval(%struct.X) @S)
652  ret i8* %c
653}
654
655define void @fixpoint_changed(i32* %p) {
656; IS__TUNIT_OPM: Function Attrs: argmemonly nofree nosync nounwind writeonly
657; IS__TUNIT_OPM-LABEL: define {{[^@]+}}@fixpoint_changed
658; IS__TUNIT_OPM-SAME: (i32* nocapture nofree writeonly [[P:%.*]]) #[[ATTR3:[0-9]+]] {
659; IS__TUNIT_OPM-NEXT:  entry:
660; IS__TUNIT_OPM-NEXT:    br label [[FOR_COND:%.*]]
661; IS__TUNIT_OPM:       for.cond:
662; IS__TUNIT_OPM-NEXT:    [[J_0:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[INC:%.*]], [[SW_EPILOG:%.*]] ]
663; IS__TUNIT_OPM-NEXT:    [[CMP:%.*]] = icmp slt i32 [[J_0]], 30
664; IS__TUNIT_OPM-NEXT:    br i1 [[CMP]], label [[FOR_BODY:%.*]], label [[FOR_END:%.*]]
665; IS__TUNIT_OPM:       for.body:
666; IS__TUNIT_OPM-NEXT:    switch i32 [[J_0]], label [[SW_EPILOG]] [
667; IS__TUNIT_OPM-NEXT:    i32 1, label [[SW_BB:%.*]]
668; IS__TUNIT_OPM-NEXT:    ]
669; IS__TUNIT_OPM:       sw.bb:
670; IS__TUNIT_OPM-NEXT:    br label [[SW_EPILOG]]
671; IS__TUNIT_OPM:       sw.epilog:
672; IS__TUNIT_OPM-NEXT:    [[X_0:%.*]] = phi i32 [ 255, [[FOR_BODY]] ], [ 253, [[SW_BB]] ]
673; IS__TUNIT_OPM-NEXT:    store i32 [[X_0]], i32* [[P]], align 4
674; IS__TUNIT_OPM-NEXT:    [[INC]] = add nsw i32 [[J_0]], 1
675; IS__TUNIT_OPM-NEXT:    br label [[FOR_COND]]
676; IS__TUNIT_OPM:       for.end:
677; IS__TUNIT_OPM-NEXT:    ret void
678;
679; IS__TUNIT_NPM: Function Attrs: argmemonly nofree nosync nounwind willreturn writeonly
680; IS__TUNIT_NPM-LABEL: define {{[^@]+}}@fixpoint_changed
681; IS__TUNIT_NPM-SAME: (i32* nocapture nofree writeonly [[P:%.*]]) #[[ATTR2]] {
682; IS__TUNIT_NPM-NEXT:  entry:
683; IS__TUNIT_NPM-NEXT:    br label [[FOR_COND:%.*]]
684; IS__TUNIT_NPM:       for.cond:
685; IS__TUNIT_NPM-NEXT:    [[J_0:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[INC:%.*]], [[SW_EPILOG:%.*]] ]
686; IS__TUNIT_NPM-NEXT:    [[CMP:%.*]] = icmp slt i32 [[J_0]], 30
687; IS__TUNIT_NPM-NEXT:    br i1 [[CMP]], label [[FOR_BODY:%.*]], label [[FOR_END:%.*]]
688; IS__TUNIT_NPM:       for.body:
689; IS__TUNIT_NPM-NEXT:    switch i32 [[J_0]], label [[SW_EPILOG]] [
690; IS__TUNIT_NPM-NEXT:    i32 1, label [[SW_BB:%.*]]
691; IS__TUNIT_NPM-NEXT:    ]
692; IS__TUNIT_NPM:       sw.bb:
693; IS__TUNIT_NPM-NEXT:    br label [[SW_EPILOG]]
694; IS__TUNIT_NPM:       sw.epilog:
695; IS__TUNIT_NPM-NEXT:    [[X_0:%.*]] = phi i32 [ 255, [[FOR_BODY]] ], [ 253, [[SW_BB]] ]
696; IS__TUNIT_NPM-NEXT:    store i32 [[X_0]], i32* [[P]], align 4
697; IS__TUNIT_NPM-NEXT:    [[INC]] = add nsw i32 [[J_0]], 1
698; IS__TUNIT_NPM-NEXT:    br label [[FOR_COND]]
699; IS__TUNIT_NPM:       for.end:
700; IS__TUNIT_NPM-NEXT:    ret void
701;
702; IS__CGSCC_OPM: Function Attrs: argmemonly nofree norecurse nosync nounwind writeonly
703; IS__CGSCC_OPM-LABEL: define {{[^@]+}}@fixpoint_changed
704; IS__CGSCC_OPM-SAME: (i32* nocapture nofree writeonly [[P:%.*]]) #[[ATTR3:[0-9]+]] {
705; IS__CGSCC_OPM-NEXT:  entry:
706; IS__CGSCC_OPM-NEXT:    br label [[FOR_COND:%.*]]
707; IS__CGSCC_OPM:       for.cond:
708; IS__CGSCC_OPM-NEXT:    [[J_0:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[INC:%.*]], [[SW_EPILOG:%.*]] ]
709; IS__CGSCC_OPM-NEXT:    [[CMP:%.*]] = icmp slt i32 [[J_0]], 30
710; IS__CGSCC_OPM-NEXT:    br i1 [[CMP]], label [[FOR_BODY:%.*]], label [[FOR_END:%.*]]
711; IS__CGSCC_OPM:       for.body:
712; IS__CGSCC_OPM-NEXT:    switch i32 [[J_0]], label [[SW_EPILOG]] [
713; IS__CGSCC_OPM-NEXT:    i32 1, label [[SW_BB:%.*]]
714; IS__CGSCC_OPM-NEXT:    ]
715; IS__CGSCC_OPM:       sw.bb:
716; IS__CGSCC_OPM-NEXT:    br label [[SW_EPILOG]]
717; IS__CGSCC_OPM:       sw.epilog:
718; IS__CGSCC_OPM-NEXT:    [[X_0:%.*]] = phi i32 [ 255, [[FOR_BODY]] ], [ 253, [[SW_BB]] ]
719; IS__CGSCC_OPM-NEXT:    store i32 [[X_0]], i32* [[P]], align 4
720; IS__CGSCC_OPM-NEXT:    [[INC]] = add nsw i32 [[J_0]], 1
721; IS__CGSCC_OPM-NEXT:    br label [[FOR_COND]]
722; IS__CGSCC_OPM:       for.end:
723; IS__CGSCC_OPM-NEXT:    ret void
724;
725; IS__CGSCC_NPM: Function Attrs: argmemonly nofree norecurse nosync nounwind willreturn writeonly
726; IS__CGSCC_NPM-LABEL: define {{[^@]+}}@fixpoint_changed
727; IS__CGSCC_NPM-SAME: (i32* nocapture nofree writeonly [[P:%.*]]) #[[ATTR2]] {
728; IS__CGSCC_NPM-NEXT:  entry:
729; IS__CGSCC_NPM-NEXT:    br label [[FOR_COND:%.*]]
730; IS__CGSCC_NPM:       for.cond:
731; IS__CGSCC_NPM-NEXT:    [[J_0:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[INC:%.*]], [[SW_EPILOG:%.*]] ]
732; IS__CGSCC_NPM-NEXT:    [[CMP:%.*]] = icmp slt i32 [[J_0]], 30
733; IS__CGSCC_NPM-NEXT:    br i1 [[CMP]], label [[FOR_BODY:%.*]], label [[FOR_END:%.*]]
734; IS__CGSCC_NPM:       for.body:
735; IS__CGSCC_NPM-NEXT:    switch i32 [[J_0]], label [[SW_EPILOG]] [
736; IS__CGSCC_NPM-NEXT:    i32 1, label [[SW_BB:%.*]]
737; IS__CGSCC_NPM-NEXT:    ]
738; IS__CGSCC_NPM:       sw.bb:
739; IS__CGSCC_NPM-NEXT:    br label [[SW_EPILOG]]
740; IS__CGSCC_NPM:       sw.epilog:
741; IS__CGSCC_NPM-NEXT:    [[X_0:%.*]] = phi i32 [ 255, [[FOR_BODY]] ], [ 253, [[SW_BB]] ]
742; IS__CGSCC_NPM-NEXT:    store i32 [[X_0]], i32* [[P]], align 4
743; IS__CGSCC_NPM-NEXT:    [[INC]] = add nsw i32 [[J_0]], 1
744; IS__CGSCC_NPM-NEXT:    br label [[FOR_COND]]
745; IS__CGSCC_NPM:       for.end:
746; IS__CGSCC_NPM-NEXT:    ret void
747;
748entry:
749  br label %for.cond
750
751for.cond:
752  %j.0 = phi i32 [ 0, %entry ], [ %inc, %sw.epilog ]
753  %cmp = icmp slt i32 %j.0, 30
754  br i1 %cmp, label %for.body, label %for.end
755
756for.body:
757  switch i32 %j.0, label %sw.epilog [
758  i32 1, label %sw.bb
759  ]
760
761sw.bb:
762  br label %sw.epilog
763
764sw.epilog:
765  %x.0 = phi i32 [ 255, %for.body ], [ 253, %sw.bb ]
766  store i32 %x.0, i32* %p
767  %inc = add nsw i32 %j.0, 1
768  br label %for.cond
769
770for.end:
771  ret void
772}
773
774; Check we merge undef and a constant properly.
775define i8 @caller0() {
776; IS__TUNIT____: Function Attrs: nofree nosync nounwind readnone willreturn
777; IS__TUNIT____-LABEL: define {{[^@]+}}@caller0
778; IS__TUNIT____-SAME: () #[[ATTR1]] {
779; IS__TUNIT____-NEXT:    ret i8 49
780;
781; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn
782; IS__CGSCC____-LABEL: define {{[^@]+}}@caller0
783; IS__CGSCC____-SAME: () #[[ATTR1]] {
784; IS__CGSCC____-NEXT:    ret i8 49
785;
786  %c = call i8 @callee(i8 undef)
787  ret i8 %c
788}
789define i8 @caller1() {
790; IS__TUNIT____: Function Attrs: nofree nosync nounwind readnone willreturn
791; IS__TUNIT____-LABEL: define {{[^@]+}}@caller1
792; IS__TUNIT____-SAME: () #[[ATTR1]] {
793; IS__TUNIT____-NEXT:    ret i8 49
794;
795; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn
796; IS__CGSCC____-LABEL: define {{[^@]+}}@caller1
797; IS__CGSCC____-SAME: () #[[ATTR1]] {
798; IS__CGSCC____-NEXT:    ret i8 49
799;
800  %c = call i8 @callee(i8 undef)
801  ret i8 %c
802}
803define i8 @caller2() {
804; IS__TUNIT____: Function Attrs: nofree nosync nounwind readnone willreturn
805; IS__TUNIT____-LABEL: define {{[^@]+}}@caller2
806; IS__TUNIT____-SAME: () #[[ATTR1]] {
807; IS__TUNIT____-NEXT:    ret i8 49
808;
809; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn
810; IS__CGSCC____-LABEL: define {{[^@]+}}@caller2
811; IS__CGSCC____-SAME: () #[[ATTR1]] {
812; IS__CGSCC____-NEXT:    ret i8 49
813;
814  %c = call i8 @callee(i8 undef)
815  ret i8 %c
816}
817define i8 @caller_middle() {
818; IS__TUNIT____: Function Attrs: nofree nosync nounwind readnone willreturn
819; IS__TUNIT____-LABEL: define {{[^@]+}}@caller_middle
820; IS__TUNIT____-SAME: () #[[ATTR1]] {
821; IS__TUNIT____-NEXT:    ret i8 49
822;
823; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn
824; IS__CGSCC____-LABEL: define {{[^@]+}}@caller_middle
825; IS__CGSCC____-SAME: () #[[ATTR1]] {
826; IS__CGSCC____-NEXT:    ret i8 49
827;
828  %c = call i8 @callee(i8 42)
829  ret i8 %c
830}
831define i8 @caller3() {
832; IS__TUNIT____: Function Attrs: nofree nosync nounwind readnone willreturn
833; IS__TUNIT____-LABEL: define {{[^@]+}}@caller3
834; IS__TUNIT____-SAME: () #[[ATTR1]] {
835; IS__TUNIT____-NEXT:    ret i8 49
836;
837; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn
838; IS__CGSCC____-LABEL: define {{[^@]+}}@caller3
839; IS__CGSCC____-SAME: () #[[ATTR1]] {
840; IS__CGSCC____-NEXT:    ret i8 49
841;
842  %c = call i8 @callee(i8 undef)
843  ret i8 %c
844}
845define i8 @caller4() {
846; IS__TUNIT____: Function Attrs: nofree nosync nounwind readnone willreturn
847; IS__TUNIT____-LABEL: define {{[^@]+}}@caller4
848; IS__TUNIT____-SAME: () #[[ATTR1]] {
849; IS__TUNIT____-NEXT:    ret i8 49
850;
851; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn
852; IS__CGSCC____-LABEL: define {{[^@]+}}@caller4
853; IS__CGSCC____-SAME: () #[[ATTR1]] {
854; IS__CGSCC____-NEXT:    ret i8 49
855;
856  %c = call i8 @callee(i8 undef)
857  ret i8 %c
858}
859define internal i8 @callee(i8 %a) {
860; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn
861; IS__CGSCC____-LABEL: define {{[^@]+}}@callee
862; IS__CGSCC____-SAME: () #[[ATTR1]] {
863; IS__CGSCC____-NEXT:    ret i8 undef
864;
865  %c = add i8 %a, 7
866  ret i8 %c
867}
868
869define void @user_as3() {
870; IS__TUNIT_OPM: Function Attrs: nofree nosync nounwind willreturn writeonly
871; IS__TUNIT_OPM-LABEL: define {{[^@]+}}@user_as3
872; IS__TUNIT_OPM-SAME: () #[[ATTR4]] {
873; IS__TUNIT_OPM-NEXT:    store i32 0, i32 addrspace(3)* @ConstAS3Ptr, align 4
874; IS__TUNIT_OPM-NEXT:    ret void
875;
876; IS__TUNIT_NPM: Function Attrs: nofree nosync nounwind willreturn writeonly
877; IS__TUNIT_NPM-LABEL: define {{[^@]+}}@user_as3
878; IS__TUNIT_NPM-SAME: () #[[ATTR3]] {
879; IS__TUNIT_NPM-NEXT:    store i32 0, i32 addrspace(3)* @ConstAS3Ptr, align 4
880; IS__TUNIT_NPM-NEXT:    ret void
881;
882; IS__CGSCC_OPM: Function Attrs: nofree norecurse nosync nounwind willreturn writeonly
883; IS__CGSCC_OPM-LABEL: define {{[^@]+}}@user_as3
884; IS__CGSCC_OPM-SAME: () #[[ATTR4:[0-9]+]] {
885; IS__CGSCC_OPM-NEXT:    store i32 0, i32 addrspace(3)* @ConstAS3Ptr, align 4
886; IS__CGSCC_OPM-NEXT:    ret void
887;
888; IS__CGSCC_NPM: Function Attrs: nofree norecurse nosync nounwind willreturn writeonly
889; IS__CGSCC_NPM-LABEL: define {{[^@]+}}@user_as3
890; IS__CGSCC_NPM-SAME: () #[[ATTR3:[0-9]+]] {
891; IS__CGSCC_NPM-NEXT:    store i32 0, i32 addrspace(3)* @ConstAS3Ptr, align 4
892; IS__CGSCC_NPM-NEXT:    ret void
893;
894  %call = call fastcc i32 addrspace(3)* @const_ptr_return_as3()
895  store i32 0, i32 addrspace(3)* %call
896  ret void
897}
898define void @user() {
899; IS__TUNIT_OPM: Function Attrs: nofree nosync nounwind willreturn writeonly
900; IS__TUNIT_OPM-LABEL: define {{[^@]+}}@user
901; IS__TUNIT_OPM-SAME: () #[[ATTR4]] {
902; IS__TUNIT_OPM-NEXT:    store i32 0, i32* addrspacecast (i32 addrspace(3)* @ConstAS3Ptr to i32*), align 4
903; IS__TUNIT_OPM-NEXT:    ret void
904;
905; IS__TUNIT_NPM: Function Attrs: nofree nosync nounwind willreturn writeonly
906; IS__TUNIT_NPM-LABEL: define {{[^@]+}}@user
907; IS__TUNIT_NPM-SAME: () #[[ATTR3]] {
908; IS__TUNIT_NPM-NEXT:    store i32 0, i32* addrspacecast (i32 addrspace(3)* @ConstAS3Ptr to i32*), align 4
909; IS__TUNIT_NPM-NEXT:    ret void
910;
911; IS__CGSCC_OPM: Function Attrs: nofree norecurse nosync nounwind willreturn writeonly
912; IS__CGSCC_OPM-LABEL: define {{[^@]+}}@user
913; IS__CGSCC_OPM-SAME: () #[[ATTR4]] {
914; IS__CGSCC_OPM-NEXT:    store i32 0, i32* addrspacecast (i32 addrspace(3)* @ConstAS3Ptr to i32*), align 4
915; IS__CGSCC_OPM-NEXT:    ret void
916;
917; IS__CGSCC_NPM: Function Attrs: nofree norecurse nosync nounwind willreturn writeonly
918; IS__CGSCC_NPM-LABEL: define {{[^@]+}}@user
919; IS__CGSCC_NPM-SAME: () #[[ATTR3]] {
920; IS__CGSCC_NPM-NEXT:    store i32 0, i32* addrspacecast (i32 addrspace(3)* @ConstAS3Ptr to i32*), align 4
921; IS__CGSCC_NPM-NEXT:    ret void
922;
923  %call = call fastcc i32* @const_ptr_return()
924  store i32 0, i32* %call
925  ret void
926}
927
928
929define i1 @test_merge_with_undef_values_ptr(i1 %c) {
930; IS__TUNIT____: Function Attrs: nofree nosync nounwind readnone willreturn
931; IS__TUNIT____-LABEL: define {{[^@]+}}@test_merge_with_undef_values_ptr
932; IS__TUNIT____-SAME: (i1 [[C:%.*]]) #[[ATTR1]] {
933; IS__TUNIT____-NEXT:    ret i1 false
934;
935; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn
936; IS__CGSCC____-LABEL: define {{[^@]+}}@test_merge_with_undef_values_ptr
937; IS__CGSCC____-SAME: (i1 [[C:%.*]]) #[[ATTR1]] {
938; IS__CGSCC____-NEXT:    ret i1 false
939;
940  %r1 = call i1 @undef_then_null(i1 %c, i32* undef, i32* undef)
941  ret i1 %r1
942}
943define internal i1 @undef_then_null(i1 %c, i32* %i32Aptr, i32* %i32Bptr) {
944; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn
945; IS__CGSCC____-LABEL: define {{[^@]+}}@undef_then_null
946; IS__CGSCC____-SAME: (i1 [[C:%.*]]) #[[ATTR1]] {
947; IS__CGSCC____-NEXT:    br i1 [[C]], label [[A:%.*]], label [[B:%.*]]
948; IS__CGSCC____:       a:
949; IS__CGSCC____-NEXT:    ret i1 undef
950; IS__CGSCC____:       b:
951; IS__CGSCC____-NEXT:    ret i1 undef
952;
953  %cmp1 = icmp eq i32* %i32Aptr, %i32Bptr
954  %cmp2 = icmp eq i1 %cmp1, false
955  %or = or i1 %cmp2, %c
956  br i1 %or, label %a, label %b
957a:
958  %r2 = call i1 @undef_then_null(i1 false, i32* null, i32* null)
959  ret i1 %r2
960b:
961  ret i1 %cmp2
962}
963
964define i1 @test_merge_with_undef_values(i1 %c) {
965; IS__TUNIT____: Function Attrs: nofree nosync nounwind readnone willreturn
966; IS__TUNIT____-LABEL: define {{[^@]+}}@test_merge_with_undef_values
967; IS__TUNIT____-SAME: (i1 [[C:%.*]]) #[[ATTR1]] {
968; IS__TUNIT____-NEXT:    ret i1 false
969;
970; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn
971; IS__CGSCC____-LABEL: define {{[^@]+}}@test_merge_with_undef_values
972; IS__CGSCC____-SAME: (i1 [[C:%.*]]) #[[ATTR1]] {
973; IS__CGSCC____-NEXT:    ret i1 false
974;
975  %r1 = call i1 @undef_then_1(i1 %c, i32 undef, i32 undef)
976  ret i1 %r1
977}
978define internal i1 @undef_then_1(i1 %c, i32 %i32A, i32 %i32B) {
979;
980; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn
981; IS__CGSCC____-LABEL: define {{[^@]+}}@undef_then_1
982; IS__CGSCC____-SAME: (i1 [[C:%.*]]) #[[ATTR1]] {
983; IS__CGSCC____-NEXT:    br i1 [[C]], label [[A:%.*]], label [[B:%.*]]
984; IS__CGSCC____:       a:
985; IS__CGSCC____-NEXT:    ret i1 undef
986; IS__CGSCC____:       b:
987; IS__CGSCC____-NEXT:    ret i1 undef
988;
989  %cmp1 = icmp eq i32 %i32A, %i32B
990  %cmp2 = icmp eq i1 %cmp1, false
991  %or = or i1 %cmp2, %c
992  br i1 %or, label %a, label %b
993a:
994  %r2 = call i1 @undef_then_1(i1 false, i32 1, i32 1)
995  ret i1 %r2
996b:
997  ret i1 %cmp2
998}
999
1000define i32 @test_select(i32 %c) {
1001; IS__TUNIT____: Function Attrs: nofree nosync nounwind readnone willreturn
1002; IS__TUNIT____-LABEL: define {{[^@]+}}@test_select
1003; IS__TUNIT____-SAME: (i32 [[C:%.*]]) #[[ATTR1]] {
1004; IS__TUNIT____-NEXT:    ret i32 42
1005;
1006; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn
1007; IS__CGSCC____-LABEL: define {{[^@]+}}@test_select
1008; IS__CGSCC____-SAME: (i32 [[C:%.*]]) #[[ATTR1]] {
1009; IS__CGSCC____-NEXT:    ret i32 42
1010;
1011  %call = call i32 @select(i1 1, i32 42, i32 %c)
1012  ret i32 %call
1013}
1014
1015define internal i32 @select(i1 %a, i32 %b, i32 %c) {
1016; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn
1017; IS__CGSCC____-LABEL: define {{[^@]+}}@select
1018; IS__CGSCC____-SAME: () #[[ATTR1]] {
1019; IS__CGSCC____-NEXT:    ret i32 undef
1020;
1021  %s = select i1 %a, i32 %b, i32 %c
1022  ret i32 %s
1023}
1024
1025define i1 @icmp() {
1026; IS__TUNIT____: Function Attrs: nofree nosync nounwind readnone willreturn
1027; IS__TUNIT____-LABEL: define {{[^@]+}}@icmp
1028; IS__TUNIT____-SAME: () #[[ATTR1]] {
1029; IS__TUNIT____-NEXT:    ret i1 true
1030;
1031; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn
1032; IS__CGSCC____-LABEL: define {{[^@]+}}@icmp
1033; IS__CGSCC____-SAME: () #[[ATTR1]] {
1034; IS__CGSCC____-NEXT:    ret i1 true
1035;
1036  %c = icmp eq i8* null, null
1037  ret i1 %c
1038}
1039
1040define void @test_callee_is_undef(void (i32)* %fn) {
1041; IS__TUNIT____-LABEL: define {{[^@]+}}@test_callee_is_undef
1042; IS__TUNIT____-SAME: (void (i32)* nocapture nofree [[FN:%.*]]) {
1043; IS__TUNIT____-NEXT:    call void @callee_is_undef()
1044; IS__TUNIT____-NEXT:    call void @unknown_calle_arg_is_undef(void (i32)* nocapture nofree [[FN]])
1045; IS__TUNIT____-NEXT:    ret void
1046;
1047; IS__CGSCC____-LABEL: define {{[^@]+}}@test_callee_is_undef
1048; IS__CGSCC____-SAME: (void (i32)* nocapture nofree [[FN:%.*]]) {
1049; IS__CGSCC____-NEXT:    unreachable
1050;
1051  call void @callee_is_undef(void ()* undef)
1052  call void @unknown_calle_arg_is_undef(void (i32)* %fn, i32 undef)
1053  ret void
1054}
1055define internal void @callee_is_undef(void ()* %fn) {
1056;
1057; IS__TUNIT____-LABEL: define {{[^@]+}}@callee_is_undef() {
1058; IS__TUNIT____-NEXT:    call void undef()
1059; IS__TUNIT____-NEXT:    ret void
1060;
1061; IS__CGSCC____-LABEL: define {{[^@]+}}@callee_is_undef
1062; IS__CGSCC____-SAME: (void ()* nocapture nofree noundef nonnull [[FN:%.*]]) {
1063; IS__CGSCC____-NEXT:    call void [[FN]]()
1064; IS__CGSCC____-NEXT:    ret void
1065;
1066  call void %fn()
1067  ret void
1068}
1069define internal void @unknown_calle_arg_is_undef(void (i32)* %fn, i32 %arg) {
1070;
1071; CHECK-LABEL: define {{[^@]+}}@unknown_calle_arg_is_undef
1072; CHECK-SAME: (void (i32)* nocapture nofree noundef nonnull [[FN:%.*]]) {
1073; CHECK-NEXT:    call void [[FN]](i32 undef)
1074; CHECK-NEXT:    ret void
1075;
1076  call void %fn(i32 %arg)
1077  ret void
1078}
1079
1080; Taken from 50683
1081; {{{
1082
1083@g = internal constant { [2 x i8*] } { [2 x i8*] [i8* bitcast (void (i8***)* @f1 to i8*), i8* bitcast (void (i1 (i8*)*)* @f2 to i8*)] }
1084
1085define internal void @f1(i8*** %a) {
1086; IS__TUNIT____: Function Attrs: argmemonly nofree nosync nounwind willreturn writeonly
1087; IS__TUNIT____-LABEL: define {{[^@]+}}@f1
1088; IS__TUNIT____-SAME: (i8*** nocapture nofree noundef nonnull writeonly align 8 dereferenceable(8) [[A:%.*]]) #[[ATTR2]] {
1089; IS__TUNIT____-NEXT:  entry:
1090; IS__TUNIT____-NEXT:    [[X:%.*]] = getelementptr { [2 x i8*] }, { [2 x i8*] }* @g, i32 0, i32 0, i32 0
1091; IS__TUNIT____-NEXT:    store i8** [[X]], i8*** [[A]], align 8
1092; IS__TUNIT____-NEXT:    ret void
1093;
1094; IS__CGSCC____: Function Attrs: argmemonly nofree norecurse nosync nounwind willreturn writeonly
1095; IS__CGSCC____-LABEL: define {{[^@]+}}@f1
1096; IS__CGSCC____-SAME: (i8*** nocapture nofree noundef nonnull writeonly align 8 dereferenceable(8) [[A:%.*]]) #[[ATTR2]] {
1097; IS__CGSCC____-NEXT:  entry:
1098; IS__CGSCC____-NEXT:    [[X:%.*]] = getelementptr { [2 x i8*] }, { [2 x i8*] }* @g, i32 0, i32 0, i32 0
1099; IS__CGSCC____-NEXT:    store i8** [[X]], i8*** [[A]], align 8
1100; IS__CGSCC____-NEXT:    ret void
1101;
1102entry:
1103  %x = getelementptr { [2 x i8*] }, { [2 x i8*] }* @g, i32 0, i32 0, i32 0
1104  store i8** %x , i8*** %a, align 8
1105  ret void
1106}
1107
1108define internal void @f2(i1 (i8*)* %a) {
1109; CHECK-LABEL: define {{[^@]+}}@f2
1110; CHECK-SAME: (i1 (i8*)* [[A:%.*]]) {
1111; CHECK-NEXT:  cont461:
1112; CHECK-NEXT:    [[C1:%.*]] = bitcast i1 (i8*)* [[A]] to i8*
1113; CHECK-NEXT:    call void @f3(i8* [[C1]], i1 (i8*)* nocapture nofree [[A]])
1114; CHECK-NEXT:    ret void
1115;
1116cont461:
1117  %c1 = bitcast i1 (i8*)* %a to i8*
1118  call void @f3(i8* %c1, i1 (i8*)* %a)
1119  ret void
1120}
1121
1122define internal void @f3(i8* %a1, i1 (i8*)* %a) {
1123; CHECK-LABEL: define {{[^@]+}}@f3
1124; CHECK-SAME: (i8* [[A1:%.*]], i1 (i8*)* nocapture nofree [[A:%.*]]) {
1125; CHECK-NEXT:  entry:
1126; CHECK-NEXT:    [[CALL20:%.*]] = call i1 @f9()
1127; CHECK-NEXT:    br i1 [[CALL20]], label [[LAND_LHS_TRUE:%.*]], label [[IF_END40:%.*]]
1128; CHECK:       land.lhs.true:
1129; CHECK-NEXT:    [[TMP0:%.*]] = call i1 [[A]](i8* [[A1]])
1130; CHECK-NEXT:    br label [[IF_END40]]
1131; CHECK:       if.end40:
1132; CHECK-NEXT:    ret void
1133;
1134entry:
1135  %call20 = call i1 @f9()
1136  br i1 %call20, label %land.lhs.true, label %if.end40
1137
1138land.lhs.true:
1139  call i1 %a(i8* %a1)
1140  br label %if.end40
1141
1142if.end40:
1143  ret void
1144}
1145
1146define linkonce_odr i1 @f9() {
1147; CHECK-LABEL: define {{[^@]+}}@f9() {
1148; CHECK-NEXT:  entry:
1149; CHECK-NEXT:    ret i1 false
1150;
1151entry:
1152  ret i1 false
1153}
1154
1155; }}}
1156
1157
1158define i1 @test_cmp_null_after_cast() {
1159; IS__TUNIT____: Function Attrs: nofree nosync nounwind readnone willreturn
1160; IS__TUNIT____-LABEL: define {{[^@]+}}@test_cmp_null_after_cast
1161; IS__TUNIT____-SAME: () #[[ATTR1]] {
1162; IS__TUNIT____-NEXT:    ret i1 true
1163;
1164; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn
1165; IS__CGSCC____-LABEL: define {{[^@]+}}@test_cmp_null_after_cast
1166; IS__CGSCC____-SAME: () #[[ATTR1]] {
1167; IS__CGSCC____-NEXT:    ret i1 true
1168;
1169  %c = call i1 @cmp_null_after_cast(i32 0, i8 0)
1170  ret i1 %c
1171}
1172define internal i1 @cmp_null_after_cast(i32 %a, i8 %b) {
1173; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn
1174; IS__CGSCC____-LABEL: define {{[^@]+}}@cmp_null_after_cast
1175; IS__CGSCC____-SAME: () #[[ATTR1]] {
1176; IS__CGSCC____-NEXT:    ret i1 undef
1177;
1178  %t = trunc i32 %a to i8
1179  %c = icmp eq i8 %t, %b
1180  ret i1 %c
1181}
1182
1183
1184declare i8* @m()
1185
1186define i32 @test(i1 %c) {
1187; CHECK-LABEL: define {{[^@]+}}@test
1188; CHECK-SAME: (i1 [[C:%.*]]) {
1189; CHECK-NEXT:    [[R1:%.*]] = call i32 @ctx_test1(i1 [[C]])
1190; CHECK-NEXT:    [[R2:%.*]] = call i32 @ctx_test2(i1 [[C]]), !range [[RNG0:![0-9]+]]
1191; CHECK-NEXT:    [[ADD:%.*]] = add i32 [[R1]], [[R2]]
1192; CHECK-NEXT:    ret i32 [[ADD]]
1193;
1194  %r1 = call i32 @ctx_test1(i1 %c)
1195  %r2 = call i32 @ctx_test2(i1 %c)
1196  %add = add i32 %r1, %r2
1197  ret i32 %add
1198}
1199
1200define internal i32 @ctx_test1(i1 %c) {
1201; CHECK-LABEL: define {{[^@]+}}@ctx_test1
1202; CHECK-SAME: (i1 [[C:%.*]]) {
1203; CHECK-NEXT:  entry:
1204; CHECK-NEXT:    br i1 [[C]], label [[THEN:%.*]], label [[JOIN:%.*]]
1205; CHECK:       then:
1206; CHECK-NEXT:    [[M:%.*]] = tail call i8* @m()
1207; CHECK-NEXT:    [[I:%.*]] = ptrtoint i8* [[M]] to i64
1208; CHECK-NEXT:    br label [[JOIN]]
1209; CHECK:       join:
1210; CHECK-NEXT:    [[PHI:%.*]] = phi i64 [ [[I]], [[THEN]] ], [ undef, [[ENTRY:%.*]] ]
1211; CHECK-NEXT:    [[RET:%.*]] = trunc i64 [[PHI]] to i32
1212; CHECK-NEXT:    ret i32 [[RET]]
1213;
1214entry:
1215  br i1 %c, label %then, label %join
1216
1217then:
1218  %m = tail call i8* @m()
1219  %i = ptrtoint i8* %m to i64
1220  br label %join
1221
1222join:
1223  %phi = phi i64 [ %i, %then ], [ undef, %entry ]
1224  %ret = trunc i64 %phi to i32
1225  ret i32 %ret
1226}
1227
1228define internal i32 @ctx_test2(i1 %c) {
1229; CHECK-LABEL: define {{[^@]+}}@ctx_test2
1230; CHECK-SAME: (i1 [[C:%.*]]) {
1231; CHECK-NEXT:  entry:
1232; CHECK-NEXT:    br i1 [[C]], label [[THEN:%.*]], label [[JOIN:%.*]]
1233; CHECK:       then:
1234; CHECK-NEXT:    [[M:%.*]] = tail call i8* @m()
1235; CHECK-NEXT:    [[I:%.*]] = ptrtoint i8* [[M]] to i32
1236; CHECK-NEXT:    br label [[JOIN]]
1237; CHECK:       join:
1238; CHECK-NEXT:    [[PHI:%.*]] = phi i32 [ [[I]], [[THEN]] ], [ undef, [[ENTRY:%.*]] ]
1239; CHECK-NEXT:    [[RET:%.*]] = lshr i32 [[PHI]], 1
1240; CHECK-NEXT:    ret i32 [[RET]]
1241;
1242entry:
1243  br i1 %c, label %then, label %join
1244
1245then:
1246  %m = tail call i8* @m()
1247  %i = ptrtoint i8* %m to i32
1248  br label %join
1249
1250join:
1251  %phi = phi i32 [ %i, %then ], [ undef, %entry ]
1252  %ret = lshr i32 %phi, 1
1253  ret i32 %ret
1254
1255  uselistorder label %join, { 1, 0 }
1256}
1257
1258;.
1259; IS__TUNIT_OPM: attributes #[[ATTR0]] = { nofree nosync nounwind willreturn }
1260; IS__TUNIT_OPM: attributes #[[ATTR1]] = { nofree nosync nounwind readnone willreturn }
1261; IS__TUNIT_OPM: attributes #[[ATTR2]] = { argmemonly nofree nosync nounwind willreturn writeonly }
1262; IS__TUNIT_OPM: attributes #[[ATTR3]] = { argmemonly nofree nosync nounwind writeonly }
1263; IS__TUNIT_OPM: attributes #[[ATTR4]] = { nofree nosync nounwind willreturn writeonly }
1264; IS__TUNIT_OPM: attributes #[[ATTR5]] = { willreturn }
1265;.
1266; IS__TUNIT_NPM: attributes #[[ATTR0]] = { nofree nosync nounwind willreturn }
1267; IS__TUNIT_NPM: attributes #[[ATTR1]] = { nofree nosync nounwind readnone willreturn }
1268; IS__TUNIT_NPM: attributes #[[ATTR2]] = { argmemonly nofree nosync nounwind willreturn writeonly }
1269; IS__TUNIT_NPM: attributes #[[ATTR3]] = { nofree nosync nounwind willreturn writeonly }
1270; IS__TUNIT_NPM: attributes #[[ATTR4]] = { willreturn }
1271;.
1272; IS__CGSCC_OPM: attributes #[[ATTR0]] = { nofree nosync nounwind willreturn }
1273; IS__CGSCC_OPM: attributes #[[ATTR1]] = { nofree norecurse nosync nounwind readnone willreturn }
1274; IS__CGSCC_OPM: attributes #[[ATTR2]] = { argmemonly nofree norecurse nosync nounwind willreturn writeonly }
1275; IS__CGSCC_OPM: attributes #[[ATTR3]] = { argmemonly nofree norecurse nosync nounwind writeonly }
1276; IS__CGSCC_OPM: attributes #[[ATTR4]] = { nofree norecurse nosync nounwind willreturn writeonly }
1277; IS__CGSCC_OPM: attributes #[[ATTR5]] = { willreturn }
1278;.
1279; IS__CGSCC_NPM: attributes #[[ATTR0]] = { nofree nosync nounwind willreturn }
1280; IS__CGSCC_NPM: attributes #[[ATTR1]] = { nofree norecurse nosync nounwind readnone willreturn }
1281; IS__CGSCC_NPM: attributes #[[ATTR2]] = { argmemonly nofree norecurse nosync nounwind willreturn writeonly }
1282; IS__CGSCC_NPM: attributes #[[ATTR3]] = { nofree norecurse nosync nounwind willreturn writeonly }
1283; IS__CGSCC_NPM: attributes #[[ATTR4]] = { willreturn }
1284;.
1285; CHECK: [[RNG0]] = !{i32 0, i32 -2147483648}
1286;.
1287