1; RUN: opt < %s -libcalls-shrinkwrap -S | FileCheck %s
2; New PM
3; RUN: opt < %s -passes=libcalls-shrinkwrap -S | FileCheck %s
4
5target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
6target triple = "x86_64-unknown-linux-gnu"
7
8define void @test_range_error(double %value) {
9entry:
10  %call_0 = call double @cosh(double %value)
11; CHECK: [[COND1:%[0-9]+]] = fcmp olt double %value, -7.100000e+02
12; CHECK: [[COND2:%[0-9]+]] = fcmp ogt double %value, 7.100000e+02
13; CHECK: [[COND:%[0-9]+]] = or i1 [[COND2]], [[COND1]]
14; CHECK: br i1 [[COND]], label %[[CALL_LABEL:cdce.call[0-9]*]], label %[[END_LABEL:cdce.end[0-9]*]], !prof ![[BRANCH_WEIGHT:[0-9]+]]
15; CHECK: [[CALL_LABEL]]:
16; CHECK-NEXT: %call_0 = call double @cosh(double %value)
17; CHECK-NEXT: br label %[[END_LABEL]]
18; CHECK: [[END_LABEL]]:
19
20  %call_1 = call double @exp(double %value)
21; CHECK: [[COND1:%[0-9]+]] = fcmp olt double %value, -7.450000e+02
22; CHECK: [[COND2:%[0-9]+]] = fcmp ogt double %value, 7.090000e+02
23; CHECK: [[COND:%[0-9]+]] = or i1 [[COND2]], [[COND1]]
24; CHECK: br i1 [[COND]], label %[[CALL_LABEL:cdce.call[0-9]*]], label %[[END_LABEL:cdce.end[0-9]*]], !prof ![[BRANCH_WEIGHT]]
25; CHECK: [[CALL_LABEL]]:
26; CHECK-NEXT: %call_1 = call double @exp(double %value)
27; CHECK-NEXT: br label %[[END_LABEL]]
28; CHECK: [[END_LABEL]]:
29
30  %call_3 = call double @exp2(double %value)
31; CHECK: [[COND1:%[0-9]+]] = fcmp olt double %value, -1.074000e+03
32; CHECK: [[COND2:%[0-9]+]] = fcmp ogt double %value, 1.023000e+03
33; CHECK: [[COND:%[0-9]+]] = or i1 [[COND2]], [[COND1]]
34; CHECK: br i1 [[COND]], label %[[CALL_LABEL:cdce.call[0-9]*]], label %[[END_LABEL:cdce.end[0-9]*]], !prof ![[BRANCH_WEIGHT]]
35; CHECK: [[CALL_LABEL]]:
36; CHECK-NEXT: %call_3 = call double @exp2(double %value)
37; CHECK-NEXT: br label %[[END_LABEL]]
38; CHECK: [[END_LABEL]]:
39
40  %call_4 = call double @sinh(double %value)
41; CHECK: [[COND1:%[0-9]+]] = fcmp olt double %value, -7.100000e+02
42; CHECK: [[COND2:%[0-9]+]] = fcmp ogt double %value, 7.100000e+02
43; CHECK: [[COND:%[0-9]+]] = or i1 [[COND2]], [[COND1]]
44; CHECK: br i1 [[COND]], label %[[CALL_LABEL:cdce.call[0-9]*]], label %[[END_LABEL:cdce.end[0-9]*]], !prof ![[BRANCH_WEIGHT]]
45; CHECK: [[CALL_LABEL]]:
46; CHECK-NEXT: %call_4 = call double @sinh(double %value)
47; CHECK-NEXT: br label %[[END_LABEL]]
48; CHECK: [[END_LABEL]]:
49
50  %call_5 = call double @expm1(double %value)
51; CHECK: [[COND:%[0-9]+]] = fcmp ogt double %value, 7.090000e+02
52; CHECK: br i1 [[COND]], label %[[CALL_LABEL:cdce.call[0-9]*]], label %[[END_LABEL:cdce.end[0-9]*]], !prof ![[BRANCH_WEIGHT]]
53; CHECK: [[CALL_LABEL]]:
54; CHECK-NEXT: %call_5 = call double @expm1(double %value)
55; CHECK-NEXT: br label %[[END_LABEL]]
56; CHECK: [[END_LABEL]]:
57
58  ret void
59}
60
61declare double @cosh(double)
62declare double @exp(double)
63declare double @exp2(double)
64declare double @sinh(double)
65declare double @expm1(double)
66
67define void @test_domain_error(double %value) {
68entry:
69  %call_00 = call double @acos(double %value)
70; CHECK: [[COND1:%[0-9]+]] = fcmp ogt double %value, 1.000000e+00
71; CHECK: [[COND2:%[0-9]+]] = fcmp olt double %value, -1.000000e+00
72; CHECK: [[COND:%[0-9]+]] = or i1 [[COND2]], [[COND1]]
73; CHECK: br i1 [[COND]], label %[[CALL_LABEL:cdce.call[0-9]*]], label %[[END_LABEL:cdce.end[0-9]*]], !prof ![[BRANCH_WEIGHT]]
74; CHECK: [[CALL_LABEL]]:
75; CHECK-NEXT: %call_00 = call double @acos(double %value)
76; CHECK-NEXT: br label %[[END_LABEL]]
77; CHECK: [[END_LABEL]]:
78
79  %call_01 = call double @asin(double %value)
80; CHECK: [[COND1:%[0-9]+]] = fcmp ogt double %value, 1.000000e+00
81; CHECK: [[COND2:%[0-9]+]] = fcmp olt double %value, -1.000000e+00
82; CHECK: [[COND:%[0-9]+]] = or i1 [[COND2]], [[COND1]]
83; CHECK: br i1 [[COND]], label %[[CALL_LABEL:cdce.call[0-9]*]], label %[[END_LABEL:cdce.end[0-9]*]], !prof ![[BRANCH_WEIGHT]]
84; CHECK: [[CALL_LABEL]]:
85; CHECK-NEXT: %call_01 = call double @asin(double %value)
86; CHECK-NEXT: br label %[[END_LABEL]]
87; CHECK: [[END_LABEL]]:
88
89  %call_02 = call double @cos(double %value)
90; CHECK: [[COND1:%[0-9]+]] = fcmp oeq double %value, 0xFFF0000000000000
91; CHECK: [[COND2:%[0-9]+]] = fcmp oeq double %value, 0x7FF0000000000000
92; CHECK: [[COND:%[0-9]+]] = or i1 [[COND2]], [[COND1]]
93; CHECK: br i1 [[COND]], label %[[CALL_LABEL:cdce.call[0-9]*]], label %[[END_LABEL:cdce.end[0-9]*]], !prof ![[BRANCH_WEIGHT]]
94; CHECK: [[CALL_LABEL]]:
95; CHECK-NEXT: %call_02 = call double @cos(double %value)
96; CHECK-NEXT: br label %[[END_LABEL]]
97; CHECK: [[END_LABEL]]:
98
99  %call_03 = call double @sin(double %value)
100; CHECK: [[COND1:%[0-9]+]] = fcmp oeq double %value, 0xFFF0000000000000
101; CHECK: [[COND2:%[0-9]+]] = fcmp oeq double %value, 0x7FF0000000000000
102; CHECK: [[COND:%[0-9]+]] = or i1 [[COND2]], [[COND1]]
103; CHECK: br i1 [[COND]], label %[[CALL_LABEL:cdce.call[0-9]*]], label %[[END_LABEL:cdce.end[0-9]*]], !prof ![[BRANCH_WEIGHT]]
104; CHECK: [[CALL_LABEL]]:
105; CHECK-NEXT: %call_03 = call double @sin(double %value)
106; CHECK-NEXT: br label %[[END_LABEL]]
107; CHECK: [[END_LABEL]]:
108
109  %call_04 = call double @acosh(double %value)
110; CHECK: [[COND:%[0-9]+]] = fcmp olt double %value, 1.000000e+00
111; CHECK: br i1 [[COND]], label %[[CALL_LABEL:cdce.call[0-9]*]], label %[[END_LABEL:cdce.end[0-9]*]], !prof ![[BRANCH_WEIGHT]]
112; CHECK: [[CALL_LABEL]]:
113; CHECK-NEXT: %call_04 = call double @acosh(double %value)
114; CHECK-NEXT: br label %[[END_LABEL]]
115; CHECK: [[END_LABEL]]:
116
117  %call_05 = call double @sqrt(double %value)
118; CHECK: [[COND:%[0-9]+]] = fcmp olt double %value, 0.000000e+00
119; CHECK: br i1 [[COND]], label %[[CALL_LABEL:cdce.call[0-9]*]], label %[[END_LABEL:cdce.end[0-9]*]], !prof ![[BRANCH_WEIGHT]]
120; CHECK: [[CALL_LABEL]]:
121; CHECK-NEXT: %call_05 = call double @sqrt(double %value)
122; CHECK-NEXT: br label %[[END_LABEL]]
123; CHECK: [[END_LABEL]]:
124
125  %call_06 = call double @atanh(double %value)
126; CHECK: [[COND1:%[0-9]+]] = fcmp oge double %value, 1.000000e+00
127; CHECK: [[COND2:%[0-9]+]] = fcmp ole double %value, -1.000000e+00
128; CHECK: [[COND:%[0-9]+]] = or i1 [[COND2]], [[COND1]]
129; CHECK: br i1 [[COND]], label %[[CALL_LABEL:cdce.call[0-9]*]], label %[[END_LABEL:cdce.end[0-9]*]], !prof ![[BRANCH_WEIGHT]]
130; CHECK: [[CALL_LABEL]]:
131; CHECK-NEXT: %call_06 = call double @atanh(double %value)
132; CHECK-NEXT: br label %[[END_LABEL]]
133; CHECK: [[END_LABEL]]:
134
135  %call_07 = call double @log(double %value)
136; CHECK: [[COND:%[0-9]+]] = fcmp ole double %value, 0.000000e+00
137; CHECK: br i1 [[COND]], label %[[CALL_LABEL:cdce.call[0-9]*]], label %[[END_LABEL:cdce.end[0-9]*]], !prof ![[BRANCH_WEIGHT]]
138; CHECK: [[CALL_LABEL]]:
139; CHECK-NEXT: %call_07 = call double @log(double %value)
140; CHECK-NEXT: br label %[[END_LABEL]]
141; CHECK: [[END_LABEL]]:
142
143  %call_08 = call double @log10(double %value)
144; CHECK: [[COND:%[0-9]+]] = fcmp ole double %value, 0.000000e+00
145; CHECK: br i1 [[COND]], label %[[CALL_LABEL:cdce.call[0-9]*]], label %[[END_LABEL:cdce.end[0-9]*]], !prof ![[BRANCH_WEIGHT]]
146; CHECK: [[CALL_LABEL]]:
147; CHECK-NEXT: %call_08 = call double @log10(double %value)
148; CHECK-NEXT: br label %[[END_LABEL]]
149; CHECK: [[END_LABEL]]:
150
151  %call_09 = call double @log2(double %value)
152; CHECK: [[COND:%[0-9]+]] = fcmp ole double %value, 0.000000e+00
153; CHECK: br i1 [[COND]], label %[[CALL_LABEL:cdce.call[0-9]*]], label %[[END_LABEL:cdce.end[0-9]*]], !prof ![[BRANCH_WEIGHT]]
154; CHECK: [[CALL_LABEL]]:
155; CHECK-NEXT: %call_09 = call double @log2(double %value)
156; CHECK-NEXT: br label %[[END_LABEL]]
157; CHECK: [[END_LABEL]]:
158
159  %call_10 = call double @logb(double %value)
160; CHECK: [[COND:%[0-9]+]] = fcmp ole double %value, 0.000000e+00
161; CHECK: br i1 [[COND]], label %[[CALL_LABEL:cdce.call[0-9]*]], label %[[END_LABEL:cdce.end[0-9]*]], !prof ![[BRANCH_WEIGHT]]
162; CHECK: [[CALL_LABEL]]:
163; CHECK-NEXT: %call_10 = call double @logb(double %value)
164; CHECK-NEXT: br label %[[END_LABEL]]
165; CHECK: [[END_LABEL]]:
166
167  %call_11 = call double @log1p(double %value)
168; CHECK: [[COND:%[0-9]+]] = fcmp ole double %value, -1.000000e+00
169; CHECK: br i1 [[COND]], label %[[CALL_LABEL:cdce.call[0-9]*]], label %[[END_LABEL:cdce.end[0-9]*]], !prof ![[BRANCH_WEIGHT]]
170; CHECK: [[CALL_LABEL]]:
171; CHECK-NEXT: %call_11 = call double @log1p(double %value)
172; CHECK-NEXT: br label %[[END_LABEL]]
173; CHECK: [[END_LABEL]]:
174
175  ret void
176}
177
178declare double @acos(double)
179declare double @asin(double)
180declare double @cos(double)
181declare double @sin(double)
182declare double @acosh(double)
183declare double @sqrt(double)
184declare double @atanh(double)
185declare double @log(double)
186declare double @log10(double)
187declare double @log2(double)
188declare double @logb(double)
189declare double @log1p(double)
190
191define void @test_pow(i32 %int_val, double %exp) {
192  %call = call double @pow(double 2.500000e+00, double %exp)
193; CHECK: [[COND:%[0-9]+]] = fcmp ogt double %exp, 1.270000e+02
194; CHECK: br i1 [[COND]], label %[[CALL_LABEL:cdce.call[0-9]*]], label %[[END_LABEL:cdce.end[0-9]*]], !prof ![[BRANCH_WEIGHT]]
195; CHECK: [[CALL_LABEL]]:
196; CHECK-NEXT: %call = call double @pow(double 2.500000e+00, double %exp)
197; CHECK-NEXT: br label %[[END_LABEL]]
198; CHECK: [[END_LABEL]]:
199
200  %conv = sitofp i32 %int_val to double
201  %call1 = call double @pow(double %conv, double %exp)
202; CHECK: [[COND1:%[0-9]+]] = fcmp ogt double %exp, 3.200000e+01
203; CHECK: [[COND2:%[0-9]+]] = fcmp ole double %conv, 0.000000e+00
204; CHECK: [[COND:%[0-9]+]] = or i1 [[COND2]], [[COND1]]
205; CHECK: br i1 [[COND]], label %[[CALL_LABEL:cdce.call[0-9]*]], label %[[END_LABEL:cdce.end[0-9]*]], !prof ![[BRANCH_WEIGHT]]
206; CHECK: [[CALL_LABEL]]:
207; CHECK-NEXT: %call1 = call double @pow(double %conv, double %exp)
208; CHECK-NEXT: br label %[[END_LABEL]]
209; CHECK: [[END_LABEL]]:
210
211  %conv2 = trunc i32 %int_val to i8
212  %conv3 = uitofp i8 %conv2 to double
213  %call4 = call double @pow(double %conv3, double %exp)
214; CHECK: [[COND1:%[0-9]+]] = fcmp ogt double %exp, 1.280000e+02
215; CHECK: [[COND2:%[0-9]+]] = fcmp ole double %conv3, 0.000000e+00
216; CHECK: [[COND:%[0-9]+]] = or i1 [[COND2]], [[COND1]]
217; CHECK: br i1 [[COND]], label %[[CALL_LABEL:cdce.call[0-9]*]], label %[[END_LABEL:cdce.end[0-9]*]], !prof ![[BRANCH_WEIGHT]]
218; CHECK: [[CALL_LABEL]]:
219; CHECK-NEXT: %call4 = call double @pow(double %conv3, double %exp)
220; CHECK-NEXT: br label %[[END_LABEL]]
221; CHECK: [[END_LABEL]]:
222
223
224  %conv5 = trunc i32 %int_val to i16
225  %conv6 = uitofp i16 %conv5 to double
226  %call7 = call double @pow(double %conv6, double %exp)
227; CHECK: [[COND1:%[0-9]+]] = fcmp ogt double %exp, 6.400000e+01
228; CHECK: [[COND2:%[0-9]+]] = fcmp ole double %conv6, 0.000000e+00
229; CHECK: [[COND:%[0-9]+]] = or i1 [[COND2]], [[COND1]]
230; CHECK: br i1 [[COND]], label %[[CALL_LABEL:cdce.call[0-9]*]], label %[[END_LABEL:cdce.end[0-9]*]], !prof ![[BRANCH_WEIGHT]]
231; CHECK: [[CALL_LABEL]]:
232; CHECK-NEXT: %call7 = call double @pow(double %conv6, double %exp)
233; CHECK-NEXT: br label %[[END_LABEL]]
234; CHECK: [[END_LABEL]]:
235
236  ret void
237}
238
239declare double @pow(double, double)
240
241; CHECK: ![[BRANCH_WEIGHT]] = !{!"branch_weights", i32 1, i32 2000}
242