xref: /llvm-project/llvm/test/Transforms/Inline/call-intrinsic-is-constant.ll (revision ca6aa4758559c31ac538a4f5a4814c254ec2f740)
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 2
2; RUN: opt %s -passes=inline -inline-threshold=20 -S | FileCheck %s
3
4declare i1 @llvm.is.constant.i64(i64)
5declare void @foo()
6
7define void @callee(i64 %val) {
8; CHECK-LABEL: define void @callee
9; CHECK-SAME: (i64 [[VAL:%.*]]) {
10; CHECK-NEXT:    [[COND:%.*]] = call i1 @llvm.is.constant.i64(i64 [[VAL]])
11; CHECK-NEXT:    br i1 [[COND]], label [[COND_TRUE:%.*]], label [[COND_FALSE:%.*]]
12; CHECK:       cond.true:
13; CHECK-NEXT:    call void @foo()
14; CHECK-NEXT:    call void @foo()
15; CHECK-NEXT:    ret void
16; CHECK:       cond.false:
17; CHECK-NEXT:    ret void
18;
19  %cond = call i1 @llvm.is.constant.i64(i64 %val)
20  br i1 %cond, label %cond.true, label %cond.false
21
22cond.true:
23; Rack up costs with a couple of function calls so that this function
24; gets inlined only when @llvm.is.constant.i64 is folded.  In reality,
25; the "then" clause of __builtin_constant_p tends to have statements
26; that fold very well, so the cost of the "then" clause is not a huge
27; concern.
28  call void @foo()
29  call void @foo()
30  ret void
31
32cond.false:
33  ret void
34}
35
36define void @caller(i64 %val) {
37; CHECK-LABEL: define void @caller
38; CHECK-SAME: (i64 [[VAL:%.*]]) {
39; CHECK-NEXT:    [[COND_I:%.*]] = call i1 @llvm.is.constant.i64(i64 [[VAL]])
40; CHECK-NEXT:    br i1 [[COND_I]], label [[COND_TRUE_I:%.*]], label [[COND_FALSE_I:%.*]]
41; CHECK:       cond.true.i:
42; CHECK-NEXT:    call void @foo()
43; CHECK-NEXT:    call void @foo()
44; CHECK-NEXT:    br label [[CALLEE_EXIT:%.*]]
45; CHECK:       cond.false.i:
46; CHECK-NEXT:    br label [[CALLEE_EXIT]]
47; CHECK:       callee.exit:
48; CHECK-NEXT:    ret void
49;
50  call void @callee(i64 %val)
51  ret void
52}
53