xref: /llvm-project/llvm/test/Transforms/Inline/ephemeral.ll (revision 151602c7a9935558ca671b35359989b261045db0)
1; RUN: opt -S -passes=inline %s -debug-only=inline-cost 2>&1 | FileCheck %s
2; REQUIRES: asserts
3
4@a = global i32 4
5
6; Only the load and ret should be included in the instruction count, not
7; the instructions feeding the assume.
8; CHECK: Analyzing call of inner...
9; CHECK: NumInstructions: 2
10define i32 @inner(ptr %y) {
11  %a1 = load volatile i32, ptr @a
12
13  ; Because these instructions are used only by the @llvm.assume intrinsic,
14  ; they're free and should not be included in the instruction count when
15  ; computing the inline cost.
16  %a2 = mul i32 %a1, %a1
17  %a3 = sub i32 %a1, %a2
18  %a4 = udiv i32 %a3, -13
19  %a5 = mul i32 %a4, %a4
20  %a6 = add i32 %a5, %a5
21  %ca = icmp sgt i32 %a6, -7
22  %r = call i1 @llvm.type.test(ptr %y, metadata !0)
23  %ca2 = icmp eq i1 %ca, %r
24  tail call void @llvm.assume(i1 %ca2)
25
26  ret i32 %a1
27}
28
29; Only the ret should be included in the instruction count, the load and icmp
30; are both ephemeral.
31; CHECK: Analyzing call of inner2...
32; CHECK: NumInstructions: 1
33define void @inner2(ptr %y) {
34  %v = load i8, ptr %y
35  %c = icmp eq i8 %v, 42
36  call void @llvm.assume(i1 %c)
37  ret void
38}
39
40define i32 @outer(ptr %y) optsize {
41   %r = call i32 @inner(ptr %y)
42   call void @inner2(ptr %y)
43   ret i32 %r
44}
45
46declare void @llvm.assume(i1) nounwind
47declare i1 @llvm.type.test(ptr, metadata) nounwind readnone
48
49!0 = !{i32 0, !"typeid1"}
50