1 ; RUN: opt < %s -inline-threshold=0 -always-inline -S | FileCheck %s 2 ; 3 ; Ensure the threshold has no impact on these decisions. 4 ; RUN: opt < %s -inline-threshold=20000000 -always-inline -S | FileCheck %s 5 ; RUN: opt < %s -inline-threshold=-20000000 -always-inline -S | FileCheck %s 6 7 define i32 @inner1() alwaysinline { 8 ret i32 1 9 } 10 define i32 @outer1() { 11 ; CHECK-LABEL: @outer1( 12 ; CHECK-NOT: call 13 ; CHECK: ret 14 15 %r = call i32 @inner1() 16 ret i32 %r 17 } 18 19 ; The always inliner can't DCE internal functions. PR2945 20 ; CHECK-LABEL: @pr2945( 21 define internal i32 @pr2945() nounwind { 22 ret i32 0 23 } 24 25 define internal void @inner2(i32 %N) alwaysinline { 26 %P = alloca i32, i32 %N 27 ret void 28 } 29 define void @outer2(i32 %N) { 30 ; The always inliner (unlike the normal one) should be willing to inline 31 ; a function with a dynamic alloca into one without a dynamic alloca. 32 ; rdar://6655932 33 ; 34 ; CHECK-LABEL: @outer2( 35 ; CHECK-NOT: call void @inner2 36 ; CHECK-NOT: call void @inner2 37 ; CHECK: ret void 38 39 call void @inner2( i32 %N ) 40 ret void 41 } 42 43 declare i32 @a() returns_twice 44 declare i32 @b() returns_twice 45 46 define i32 @inner3() alwaysinline { 47 entry: 48 %call = call i32 @a() returns_twice 49 %add = add nsw i32 1, %call 50 ret i32 %add 51 } 52 define i32 @outer3() { 53 entry: 54 ; CHECK-LABEL: @outer3( 55 ; CHECK-NOT: call i32 @a 56 ; CHECK: ret 57 58 %call = call i32 @inner3() 59 %add = add nsw i32 1, %call 60 ret i32 %add 61 } 62 63 define i32 @inner4() alwaysinline returns_twice { 64 entry: 65 %call = call i32 @b() returns_twice 66 %add = add nsw i32 1, %call 67 ret i32 %add 68 } 69 70 define i32 @outer4() { 71 entry: 72 ; CHECK-LABEL: @outer4( 73 ; CHECK: call i32 @b() 74 ; CHECK: ret 75 76 %call = call i32 @inner4() returns_twice 77 %add = add nsw i32 1, %call 78 ret i32 %add 79 } 80 81 define i32 @inner5(i8* %addr) alwaysinline { 82 entry: 83 indirectbr i8* %addr, [ label %one, label %two ] 84 85 one: 86 ret i32 42 87 88 two: 89 ret i32 44 90 } 91 define i32 @outer5(i32 %x) { 92 ; CHECK-LABEL: @outer5( 93 ; CHECK: call i32 @inner5 94 ; CHECK: ret 95 96 %cmp = icmp slt i32 %x, 42 97 %addr = select i1 %cmp, i8* blockaddress(@inner5, %one), i8* blockaddress(@inner5, %two) 98 %call = call i32 @inner5(i8* %addr) 99 ret i32 %call 100 } 101 102 define void @inner6(i32 %x) alwaysinline { 103 entry: 104 %icmp = icmp slt i32 %x, 0 105 br i1 %icmp, label %return, label %bb 106 107 bb: 108 %sub = sub nsw i32 %x, 1 109 call void @inner6(i32 %sub) 110 ret void 111 112 return: 113 ret void 114 } 115 define void @outer6() { 116 ; CHECK-LABEL: @outer6( 117 ; CHECK: call void @inner6(i32 42) 118 ; CHECK: ret 119 120 entry: 121 call void @inner6(i32 42) 122 ret void 123 } 124 125 define i32 @inner7() { 126 ret i32 1 127 } 128 define i32 @outer7() { 129 ; CHECK-LABEL: @outer7( 130 ; CHECK-NOT: call 131 ; CHECK: ret 132 133 %r = call i32 @inner7() alwaysinline 134 ret i32 %r 135 } 136