1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -inline < %s -S -o - | FileCheck %s
3 target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
4 target triple = "x86_64-apple-macosx10.15.0"
6 define void @caller1(i8 *%p1, i1 %b) {
7 ; CHECK-LABEL: @caller1(
9 ; CHECK-NEXT: [[COND:%.*]] = icmp eq i1 [[B:%.*]], true
10 ; CHECK-NEXT: br i1 [[COND]], label [[EXIT:%.*]], label [[SPLIT:%.*]]
12 ; CHECK-NEXT: call void @callee(i8* [[P1:%.*]], i32 0, i32 -1)
13 ; CHECK-NEXT: br label [[EXIT]]
15 ; CHECK-NEXT: ret void
18 %cond = icmp eq i1 %b, true
19 br i1 %cond, label %exit, label %split
22 ; This path may be generated from CS splitting and never taken at runtime.
23 call void @callee(i8* %p1, i32 0, i32 -1)
30 define void @callee(i8* %p1, i32 %l1, i32 %l2) {
32 %ext = zext i32 %l2 to i64
33 %vla = alloca float, i64 %ext, align 16
34 call void @extern_call(float* nonnull %vla) #3
39 define void @caller2_below_threshold(i8 *%p1, i1 %b) {
40 ; CHECK-LABEL: @caller2_below_threshold(
42 ; CHECK-NEXT: [[VLA_I:%.*]] = alloca float, i64 15000, align 16
43 ; CHECK-NEXT: [[COND:%.*]] = icmp eq i1 [[B:%.*]], true
44 ; CHECK-NEXT: br i1 [[COND]], label [[EXIT:%.*]], label [[SPLIT:%.*]]
46 ; CHECK-NEXT: [[SAVEDSTACK:%.*]] = call i8* @llvm.stacksave()
47 ; CHECK-NEXT: [[TMP0:%.*]] = bitcast float* [[VLA_I]] to i8*
48 ; CHECK-NEXT: call void @llvm.lifetime.start.p0i8(i64 60000, i8* [[TMP0]])
49 ; CHECK-NEXT: call void @extern_call(float* nonnull [[VLA_I]]) #3
50 ; CHECK-NEXT: [[TMP1:%.*]] = bitcast float* [[VLA_I]] to i8*
51 ; CHECK-NEXT: call void @llvm.lifetime.end.p0i8(i64 60000, i8* [[TMP1]])
52 ; CHECK-NEXT: call void @llvm.stackrestore(i8* [[SAVEDSTACK]])
53 ; CHECK-NEXT: br label [[EXIT]]
55 ; CHECK-NEXT: ret void
58 %cond = icmp eq i1 %b, true
59 br i1 %cond, label %exit, label %split
62 call void @callee(i8* %p1, i32 0, i32 15000)
69 define void @callee2_not_in_entry(i8* %p1, i32 %l1, i32 %l2) {
71 %ext = zext i32 %l2 to i64
72 %c = icmp eq i32 %l1, 42
73 br i1 %c, label %bb2, label %bb3
75 %vla = alloca float, i64 %ext, align 16
76 call void @extern_call(float* nonnull %vla) #3
82 define void @caller3_alloca_not_in_entry(i8 *%p1, i1 %b) {
83 ; CHECK-LABEL: @caller3_alloca_not_in_entry(
85 ; CHECK-NEXT: [[COND:%.*]] = icmp eq i1 [[B:%.*]], true
86 ; CHECK-NEXT: br i1 [[COND]], label [[EXIT:%.*]], label [[SPLIT:%.*]]
88 ; CHECK-NEXT: br label [[EXIT]]
90 ; CHECK-NEXT: ret void
93 %cond = icmp eq i1 %b, true
94 br i1 %cond, label %exit, label %split
97 call void @callee2_not_in_entry(i8* %p1, i32 0, i32 -1)
104 define void @caller4_over_threshold(i8 *%p1, i1 %b, i32 %len) {
105 ; CHECK-LABEL: @caller4_over_threshold(
107 ; CHECK-NEXT: [[COND:%.*]] = icmp eq i1 [[B:%.*]], true
108 ; CHECK-NEXT: br i1 [[COND]], label [[EXIT:%.*]], label [[SPLIT:%.*]]
110 ; CHECK-NEXT: call void @callee(i8* [[P1:%.*]], i32 0, i32 16500)
111 ; CHECK-NEXT: br label [[EXIT]]
113 ; CHECK-NEXT: ret void
116 %cond = icmp eq i1 %b, true
117 br i1 %cond, label %exit, label %split
120 call void @callee(i8* %p1, i32 0, i32 16500)
127 declare noalias i8* @malloc(i64)
128 define i8* @stack_allocate(i32 %size) #2 {
130 %cmp = icmp ult i32 %size, 100
131 %conv = zext i32 %size to i64
132 br i1 %cmp, label %if.then, label %if.end
134 if.then: ; preds = %entry
135 %0 = alloca i8, i64 %conv, align 8
138 if.end: ; preds = %entry
139 %call = tail call i8* @malloc(i64 %conv) #3
142 return: ; preds = %if.end, %if.then
143 %retval.0 = phi i8* [ %0, %if.then ], [ %call, %if.end ]
147 define i8* @test_stack_allocate_always(i32 %size) {
148 ; CHECK-LABEL: @test_stack_allocate_always(
150 ; CHECK-NEXT: [[SAVEDSTACK:%.*]] = call i8* @llvm.stacksave()
151 ; CHECK-NEXT: [[CMP_I:%.*]] = icmp ult i32 [[SIZE:%.*]], 100
152 ; CHECK-NEXT: [[CONV_I:%.*]] = zext i32 [[SIZE]] to i64
153 ; CHECK-NEXT: br i1 [[CMP_I]], label [[IF_THEN_I:%.*]], label [[IF_END_I:%.*]]
155 ; CHECK-NEXT: [[TMP0:%.*]] = alloca i8, i64 [[CONV_I]], align 8
156 ; CHECK-NEXT: br label [[STACK_ALLOCATE_EXIT:%.*]]
158 ; CHECK-NEXT: [[CALL_I:%.*]] = tail call i8* @malloc(i64 [[CONV_I]]) #3
159 ; CHECK-NEXT: br label [[STACK_ALLOCATE_EXIT]]
160 ; CHECK: stack_allocate.exit:
161 ; CHECK-NEXT: [[RETVAL_0_I:%.*]] = phi i8* [ [[TMP0]], [[IF_THEN_I]] ], [ [[CALL_I]], [[IF_END_I]] ]
162 ; CHECK-NEXT: call void @llvm.stackrestore(i8* [[SAVEDSTACK]])
163 ; CHECK-NEXT: ret i8* [[RETVAL_0_I]]
166 %call = tail call i8* @stack_allocate(i32 %size)
170 declare void @extern_call(float*)
172 attributes #1 = { argmemonly nounwind willreturn writeonly }
173 attributes #2 = { alwaysinline }
174 attributes #3 = { nounwind }