xref: /llvm-project/llvm/test/ThinLTO/X86/summary-matching.ll (revision e40cabfea48c617fe6efaace588e80474bc80fe8)
1;; Test to make sure that function's definiton and summary matches.
2; RUN: split-file %s %t
3; RUN: opt -thinlto-bc %t/main.ll >%t/main.o
4; RUN: opt -thinlto-bc %t/b.ll >%t/b.o
5; RUN: opt -thinlto-bc %t/c.ll >%t/c.o
6
7; RUN: llvm-lto2 run %t/b.o %t/c.o %t/main.o -enable-memprof-context-disambiguation \
8; RUN: -supports-hot-cold-new -o %t/a.out \
9; RUN: -r=%t/main.o,main,plx \
10; RUN: -r=%t/b.o,_Z1bv,plx \
11; RUN: -r=%t/b.o,_Z3fooIiET_S0_S0_,plx \
12; RUN: -r=%t/b.o,_Znwm \
13; RUN: -r=%t/c.o,_Z1cv,plx \
14; RUN: -r=%t/c.o,_Z3fooIiET_S0_S0_ \
15; RUN: -r=%t/c.o,_Z3barIiET_S0_S0_,plx \
16; RUN: -r=%t/c.o,_Znwm \
17; RUN: -r=%t/main.o,_Z1bv \
18; RUN: -r=%t/main.o,_Z1cv \
19; RUN: -r=%t/main.o,_Z3fooIiET_S0_S0_
20
21;; foo has two copys:
22;; foo in b.ll is prevailing and inlines bar.
23;; foo in c.ll isn't prevailing and doesn't inline bar.
24;; main will import foo in c.ll and foo's summary in b.ll default.
25
26;--- main.ll
27; ModuleID = 'main.cc'
28source_filename = "main.cc"
29target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
30target triple = "x86_64-unknown-linux-gnu"
31
32; Function Attrs: mustprogress norecurse uwtable
33define dso_local noundef i32 @main() #0 {
34entry:
35  %retval = alloca i32, align 4
36  store i32 0, ptr %retval, align 4
37  %call = call noundef i32 @_Z1bv(), !callsite !6
38  %call1 = call noundef i32 @_Z1cv(), !callsite !7
39  %add = add nsw i32 %call, %call1
40  %call2 = call noundef i32 @_Z3fooIiET_S0_S0_(i32 noundef 1, i32 noundef 2), !callsite !8
41  %add3 = add nsw i32 %add, %call2
42  ret i32 %add3
43}
44
45declare noundef i32 @_Z1bv() #1
46
47declare noundef i32 @_Z1cv() #1
48
49declare noundef i32 @_Z3fooIiET_S0_S0_(i32 noundef, i32 noundef) #1
50
51attributes #0 = { mustprogress norecurse uwtable "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
52attributes #1 = { "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
53
54!llvm.module.flags = !{!0, !1, !2, !3, !4}
55!llvm.ident = !{!5}
56
57!0 = !{i32 1, !"wchar_size", i32 4}
58!1 = !{i32 8, !"PIC Level", i32 2}
59!2 = !{i32 7, !"PIE Level", i32 2}
60!3 = !{i32 7, !"uwtable", i32 2}
61!4 = !{i32 7, !"frame-pointer", i32 2}
62!5 = !{!"clang version 19.0.0"}
63!6 = !{i64 1}
64!7 = !{i64 5}
65!8 = !{i64 7}
66
67;--- c.ll
68; ModuleID = 'c.cc'
69source_filename = "c.cc"
70target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
71target triple = "x86_64-unknown-linux-gnu"
72
73$_Z3fooIiET_S0_S0_ = comdat any
74
75$_Z3barIiET_S0_S0_ = comdat any
76
77; Function Attrs: mustprogress noinline optnone uwtable
78define dso_local noundef i32 @_Z1cv() #0 {
79entry:
80  %num1 = alloca i32, align 4
81  %num2 = alloca i32, align 4
82  store i32 1, ptr %num1, align 4
83  store i32 1, ptr %num2, align 4
84  %0 = load i32, ptr %num1, align 4
85  %1 = load i32, ptr %num2, align 4
86  %call = call noundef i32 @_Z3fooIiET_S0_S0_(i32 noundef %0, i32 noundef %1), !callsite !6
87  ret i32 %call
88}
89
90; Function Attrs: mustprogress uwtable
91define linkonce_odr dso_local noundef i32 @_Z3fooIiET_S0_S0_(i32 noundef %a, i32 noundef %b) #3 comdat {
92entry:
93  %a.addr = alloca i32, align 4
94  %b.addr = alloca i32, align 4
95  %rtn = alloca i32, align 4
96  store i32 %a, ptr %a.addr, align 4
97  store i32 %b, ptr %b.addr, align 4
98  %0 = load i32, ptr %a.addr, align 4
99  %1 = load i32, ptr %b.addr, align 4
100  %call = call noundef i32 @_Z3barIiET_S0_S0_(i32 noundef %0, i32 noundef %1), !callsite !7
101  store i32 %call, ptr %rtn, align 4
102  %2 = load i32, ptr %rtn, align 4
103  ret i32 %2
104}
105
106; Function Attrs: mustprogress noinline optnone uwtable
107define linkonce_odr dso_local noundef i32 @_Z3barIiET_S0_S0_(i32 noundef %a, i32 noundef %b) #0 comdat {
108entry:
109  %a.addr = alloca i32, align 4
110  %b.addr = alloca i32, align 4
111  %c = alloca ptr, align 8
112  %d = alloca ptr, align 8
113  store i32 %a, ptr %a.addr, align 4
114  store i32 %b, ptr %b.addr, align 4
115  %0 = load i32, ptr %a.addr, align 4
116  %add = add nsw i32 %0, 1
117  store i32 %add, ptr %a.addr, align 4
118  %1 = load i32, ptr %b.addr, align 4
119  %add1 = add nsw i32 %1, 1
120  store i32 %add1, ptr %b.addr, align 4
121  %2 = load i32, ptr %a.addr, align 4
122  %add2 = add nsw i32 %2, 1
123  store i32 %add2, ptr %a.addr, align 4
124  %3 = load i32, ptr %b.addr, align 4
125  %add3 = add nsw i32 %3, 1
126  store i32 %add3, ptr %b.addr, align 4
127  %4 = load i32, ptr %a.addr, align 4
128  %add4 = add nsw i32 %4, 1
129  store i32 %add4, ptr %a.addr, align 4
130  %5 = load i32, ptr %b.addr, align 4
131  %add5 = add nsw i32 %5, 1
132  store i32 %add5, ptr %b.addr, align 4
133  %6 = load i32, ptr %a.addr, align 4
134  %add6 = add nsw i32 %6, 1
135  store i32 %add6, ptr %a.addr, align 4
136  %7 = load i32, ptr %b.addr, align 4
137  %add7 = add nsw i32 %7, 1
138  store i32 %add7, ptr %b.addr, align 4
139  %8 = load i32, ptr %a.addr, align 4
140  %add8 = add nsw i32 %8, 1
141  store i32 %add8, ptr %a.addr, align 4
142  %9 = load i32, ptr %b.addr, align 4
143  %add9 = add nsw i32 %9, 1
144  store i32 %add9, ptr %b.addr, align 4
145  %10 = load i32, ptr %a.addr, align 4
146  %add10 = add nsw i32 %10, 1
147  store i32 %add10, ptr %a.addr, align 4
148  %11 = load i32, ptr %b.addr, align 4
149  %add11 = add nsw i32 %11, 1
150  store i32 %add11, ptr %b.addr, align 4
151  %12 = load i32, ptr %a.addr, align 4
152  %add12 = add nsw i32 %12, 1
153  store i32 %add12, ptr %a.addr, align 4
154  %13 = load i32, ptr %b.addr, align 4
155  %add13 = add nsw i32 %13, 1
156  store i32 %add13, ptr %b.addr, align 4
157  %14 = load i32, ptr %a.addr, align 4
158  %add14 = add nsw i32 %14, 1
159  store i32 %add14, ptr %a.addr, align 4
160  %15 = load i32, ptr %b.addr, align 4
161  %add15 = add nsw i32 %15, 1
162  store i32 %add15, ptr %b.addr, align 4
163  %16 = load i32, ptr %a.addr, align 4
164  %add16 = add nsw i32 %16, 1
165  store i32 %add16, ptr %a.addr, align 4
166  %17 = load i32, ptr %b.addr, align 4
167  %add17 = add nsw i32 %17, 1
168  store i32 %add17, ptr %b.addr, align 4
169  %18 = load i32, ptr %a.addr, align 4
170  %add18 = add nsw i32 %18, 1
171  store i32 %add18, ptr %a.addr, align 4
172  %19 = load i32, ptr %b.addr, align 4
173  %add19 = add nsw i32 %19, 1
174  store i32 %add19, ptr %b.addr, align 4
175  %20 = load i32, ptr %a.addr, align 4
176  %add20 = add nsw i32 %20, 1
177  store i32 %add20, ptr %a.addr, align 4
178  %21 = load i32, ptr %b.addr, align 4
179  %add21 = add nsw i32 %21, 1
180  store i32 %add21, ptr %b.addr, align 4
181  %22 = load i32, ptr %a.addr, align 4
182  %add22 = add nsw i32 %22, 1
183  store i32 %add22, ptr %a.addr, align 4
184  %23 = load i32, ptr %b.addr, align 4
185  %add23 = add nsw i32 %23, 1
186  store i32 %add23, ptr %b.addr, align 4
187  %call = call noalias noundef nonnull ptr @_Znwm(i64 noundef 4) #2, !callsite !8
188  store i32 1, ptr %call, align 4
189  store ptr %call, ptr %c, align 8
190  %call24 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 4) #2, !callsite !9
191  store i32 1, ptr %call24, align 4
192  store ptr %call24, ptr %d, align 8
193  %24 = load i32, ptr %a.addr, align 4
194  %25 = load i32, ptr %b.addr, align 4
195  %cmp = icmp sgt i32 %24, %25
196  br i1 %cmp, label %cond.true, label %cond.false
197
198cond.true:                                        ; preds = %entry
199  %26 = load i32, ptr %a.addr, align 4
200  br label %cond.end
201
202cond.false:                                       ; preds = %entry
203  %27 = load i32, ptr %b.addr, align 4
204  br label %cond.end
205
206cond.end:                                         ; preds = %cond.false, %cond.true
207  %cond = phi i32 [ %26, %cond.true ], [ %27, %cond.false ]
208  ret i32 %cond
209}
210
211; Function Attrs: nobuiltin allocsize(0)
212declare noundef nonnull ptr @_Znwm(i64 noundef) #1
213
214attributes #0 = { mustprogress noinline optnone uwtable "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
215attributes #1 = { nobuiltin allocsize(0) "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
216attributes #2 = { builtin allocsize(0) }
217attributes #3 = { mustprogress uwtable "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
218
219!llvm.module.flags = !{!0, !1, !2, !3, !4}
220!llvm.ident = !{!5}
221
222!0 = !{i32 1, !"wchar_size", i32 4}
223!1 = !{i32 8, !"PIC Level", i32 2}
224!2 = !{i32 7, !"PIE Level", i32 2}
225!3 = !{i32 7, !"uwtable", i32 2}
226!4 = !{i32 7, !"frame-pointer", i32 2}
227!5 = !{!"clang version 19.0.0"}
228!6 = !{i64 6}
229!7 = !{i64 3}
230!8 = !{i64 4}
231!9 = !{i64 9}
232
233;--- b.ll
234; ModuleID = 'b.cc'
235source_filename = "b.cc"
236target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
237target triple = "x86_64-unknown-linux-gnu"
238
239$_Z3fooIiET_S0_S0_ = comdat any
240
241; Function Attrs: mustprogress noinline optnone uwtable
242define dso_local noundef i32 @_Z1bv() #0 {
243entry:
244  %num1 = alloca i32, align 4
245  %num2 = alloca i32, align 4
246  store i32 0, ptr %num1, align 4
247  store i32 0, ptr %num2, align 4
248  %0 = load i32, ptr %num1, align 4
249  %1 = load i32, ptr %num2, align 4
250  %call = call noundef i32 @_Z3fooIiET_S0_S0_(i32 noundef %0, i32 noundef %1), !callsite !6
251  ret i32 %call
252}
253
254; Function Attrs: mustprogress uwtable
255define linkonce_odr dso_local noundef i32 @_Z3fooIiET_S0_S0_(i32 noundef %a, i32 noundef %b) #3 comdat {
256entry:
257  %a.addr.i = alloca i32, align 4
258  %b.addr.i = alloca i32, align 4
259  %c.i = alloca ptr, align 8
260  %d.i = alloca ptr, align 8
261  %a.addr = alloca i32, align 4
262  %b.addr = alloca i32, align 4
263  %rtn = alloca i32, align 4
264  store i32 %a, ptr %a.addr, align 4
265  store i32 %b, ptr %b.addr, align 4
266  %0 = load i32, ptr %a.addr, align 4
267  %1 = load i32, ptr %b.addr, align 4
268  store i32 %0, ptr %a.addr.i, align 4
269  store i32 %1, ptr %b.addr.i, align 4
270  %2 = load i32, ptr %a.addr.i, align 4
271  %add.i = add nsw i32 %2, 1
272  store i32 %add.i, ptr %a.addr.i, align 4
273  %3 = load i32, ptr %b.addr.i, align 4
274  %add1.i = add nsw i32 %3, 1
275  store i32 %add1.i, ptr %b.addr.i, align 4
276  %4 = load i32, ptr %a.addr.i, align 4
277  %add2.i = add nsw i32 %4, 1
278  store i32 %add2.i, ptr %a.addr.i, align 4
279  %5 = load i32, ptr %b.addr.i, align 4
280  %add3.i = add nsw i32 %5, 1
281  store i32 %add3.i, ptr %b.addr.i, align 4
282  %6 = load i32, ptr %a.addr.i, align 4
283  %add4.i = add nsw i32 %6, 1
284  store i32 %add4.i, ptr %a.addr.i, align 4
285  %7 = load i32, ptr %b.addr.i, align 4
286  %add5.i = add nsw i32 %7, 1
287  store i32 %add5.i, ptr %b.addr.i, align 4
288  %8 = load i32, ptr %a.addr.i, align 4
289  %add6.i = add nsw i32 %8, 1
290  store i32 %add6.i, ptr %a.addr.i, align 4
291  %9 = load i32, ptr %b.addr.i, align 4
292  %add7.i = add nsw i32 %9, 1
293  store i32 %add7.i, ptr %b.addr.i, align 4
294  %10 = load i32, ptr %a.addr.i, align 4
295  %add8.i = add nsw i32 %10, 1
296  store i32 %add8.i, ptr %a.addr.i, align 4
297  %11 = load i32, ptr %b.addr.i, align 4
298  %add9.i = add nsw i32 %11, 1
299  store i32 %add9.i, ptr %b.addr.i, align 4
300  %12 = load i32, ptr %a.addr.i, align 4
301  %add10.i = add nsw i32 %12, 1
302  store i32 %add10.i, ptr %a.addr.i, align 4
303  %13 = load i32, ptr %b.addr.i, align 4
304  %add11.i = add nsw i32 %13, 1
305  store i32 %add11.i, ptr %b.addr.i, align 4
306  %14 = load i32, ptr %a.addr.i, align 4
307  %add12.i = add nsw i32 %14, 1
308  store i32 %add12.i, ptr %a.addr.i, align 4
309  %15 = load i32, ptr %b.addr.i, align 4
310  %add13.i = add nsw i32 %15, 1
311  store i32 %add13.i, ptr %b.addr.i, align 4
312  %16 = load i32, ptr %a.addr.i, align 4
313  %add14.i = add nsw i32 %16, 1
314  store i32 %add14.i, ptr %a.addr.i, align 4
315  %17 = load i32, ptr %b.addr.i, align 4
316  %add15.i = add nsw i32 %17, 1
317  store i32 %add15.i, ptr %b.addr.i, align 4
318  %18 = load i32, ptr %a.addr.i, align 4
319  %add16.i = add nsw i32 %18, 1
320  store i32 %add16.i, ptr %a.addr.i, align 4
321  %19 = load i32, ptr %b.addr.i, align 4
322  %add17.i = add nsw i32 %19, 1
323  store i32 %add17.i, ptr %b.addr.i, align 4
324  %20 = load i32, ptr %a.addr.i, align 4
325  %add18.i = add nsw i32 %20, 1
326  store i32 %add18.i, ptr %a.addr.i, align 4
327  %21 = load i32, ptr %b.addr.i, align 4
328  %add19.i = add nsw i32 %21, 1
329  store i32 %add19.i, ptr %b.addr.i, align 4
330  %22 = load i32, ptr %a.addr.i, align 4
331  %add20.i = add nsw i32 %22, 1
332  store i32 %add20.i, ptr %a.addr.i, align 4
333  %23 = load i32, ptr %b.addr.i, align 4
334  %add21.i = add nsw i32 %23, 1
335  store i32 %add21.i, ptr %b.addr.i, align 4
336  %24 = load i32, ptr %a.addr.i, align 4
337  %add22.i = add nsw i32 %24, 1
338  store i32 %add22.i, ptr %a.addr.i, align 4
339  %25 = load i32, ptr %b.addr.i, align 4
340  %add23.i = add nsw i32 %25, 1
341  store i32 %add23.i, ptr %b.addr.i, align 4
342  %call.i = call noalias noundef nonnull ptr @_Znwm(i64 noundef 4) #2, !callsite !7
343  store i32 1, ptr %call.i, align 4
344  store ptr %call.i, ptr %c.i, align 8
345  %call24.i = call noalias noundef nonnull ptr @_Znwm(i64 noundef 4) #2, !callsite !8
346  store i32 1, ptr %call24.i, align 4
347  store ptr %call24.i, ptr %d.i, align 8
348  %26 = load i32, ptr %a.addr.i, align 4
349  %27 = load i32, ptr %b.addr.i, align 4
350  %cmp.i = icmp sgt i32 %26, %27
351  br i1 %cmp.i, label %cond.true.i, label %cond.false.i
352
353cond.true.i:                                      ; preds = %entry
354  %28 = load i32, ptr %a.addr.i, align 4
355  br label %_Z3barIiET_S0_S0_.exit
356
357cond.false.i:                                     ; preds = %entry
358  %29 = load i32, ptr %b.addr.i, align 4
359  br label %_Z3barIiET_S0_S0_.exit
360
361_Z3barIiET_S0_S0_.exit:                           ; preds = %cond.true.i, %cond.false.i
362  %cond.i = phi i32 [ %28, %cond.true.i ], [ %29, %cond.false.i ]
363  store i32 %cond.i, ptr %rtn, align 4
364  %30 = load i32, ptr %rtn, align 4
365  ret i32 %30
366}
367
368; Function Attrs: nobuiltin allocsize(0)
369declare noundef nonnull ptr @_Znwm(i64 noundef) #1
370
371attributes #0 = { mustprogress noinline optnone uwtable "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
372attributes #1 = { nobuiltin allocsize(0) "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
373attributes #2 = { builtin allocsize(0) }
374attributes #3 = { mustprogress uwtable "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
375
376!llvm.module.flags = !{!0, !1, !2, !3, !4}
377!llvm.ident = !{!5}
378
379!0 = !{i32 1, !"wchar_size", i32 4}
380!1 = !{i32 8, !"PIC Level", i32 2}
381!2 = !{i32 7, !"PIE Level", i32 2}
382!3 = !{i32 7, !"uwtable", i32 2}
383!4 = !{i32 7, !"frame-pointer", i32 2}
384!5 = !{!"clang version 19.0.0"}
385!6 = !{i64 2}
386!7 = !{i64 4, i64 3}
387!8 = !{i64 9, i64 3}
388