1; RUN: opt < %s -inline-threshold=0 -always-inline -enable-new-pm=0 -S | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-CALL 2; 3; Ensure the threshold has no impact on these decisions. 4; RUN: opt < %s -inline-threshold=20000000 -always-inline -enable-new-pm=0 -S | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-CALL 5; RUN: opt < %s -inline-threshold=-20000000 -always-inline -enable-new-pm=0 -S | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-CALL 6; 7; The new pass manager doesn't re-use any threshold based infrastructure for 8; the always inliner, but test that we get the correct result. The new PM 9; always inliner also doesn't support inlining call-site alwaysinline 10; annotations. It isn't clear that this is a reasonable use case for 11; 'alwaysinline'. 12; RUN: opt < %s -inline-threshold=0 -passes=always-inline -S | FileCheck %s --check-prefix=CHECK 13; RUN: opt < %s -inline-threshold=20000000 -passes=always-inline -S | FileCheck %s --check-prefix=CHECK 14; RUN: opt < %s -inline-threshold=-20000000 -passes=always-inline -S | FileCheck %s --check-prefix=CHECK 15 16define internal i32 @inner1() alwaysinline { 17; CHECK-NOT: @inner1( 18 ret i32 1 19} 20define i32 @outer1() { 21; CHECK-LABEL: @outer1( 22; CHECK-NOT: call 23; CHECK: ret 24 25 %r = call i32 @inner1() 26 ret i32 %r 27} 28 29; The always inliner can't DCE arbitrary internal functions. PR2945 30define internal i32 @pr2945() nounwind { 31; CHECK-LABEL: @pr2945( 32 ret i32 0 33} 34 35define internal void @inner2(i32 %N) alwaysinline { 36; CHECK-NOT: @inner2( 37 %P = alloca i32, i32 %N 38 ret void 39} 40define void @outer2(i32 %N) { 41; The always inliner (unlike the normal one) should be willing to inline 42; a function with a dynamic alloca into one without a dynamic alloca. 43; rdar://6655932 44; 45; CHECK-LABEL: @outer2( 46; CHECK-NOT: call void @inner2 47; CHECK-NOT: call void @inner2 48; CHECK: ret void 49 50 call void @inner2( i32 %N ) 51 ret void 52} 53 54declare i32 @a() returns_twice 55declare i32 @b() returns_twice 56 57; Cannot alwaysinline when that would introduce a returns_twice call. 58define internal i32 @inner3() alwaysinline { 59; CHECK-LABEL: @inner3( 60entry: 61 %call = call i32 @a() returns_twice 62 %add = add nsw i32 1, %call 63 ret i32 %add 64} 65define i32 @outer3() { 66entry: 67; CHECK-LABEL: @outer3( 68; CHECK-NOT: call i32 @a 69; CHECK: ret 70 71 %call = call i32 @inner3() 72 %add = add nsw i32 1, %call 73 ret i32 %add 74} 75 76define internal i32 @inner4() alwaysinline returns_twice { 77; CHECK-NOT: @inner4( 78entry: 79 %call = call i32 @b() returns_twice 80 %add = add nsw i32 1, %call 81 ret i32 %add 82} 83 84define i32 @outer4() { 85entry: 86; CHECK-LABEL: @outer4( 87; CHECK: call i32 @b() 88; CHECK: ret 89 90 %call = call i32 @inner4() returns_twice 91 %add = add nsw i32 1, %call 92 ret i32 %add 93} 94 95; We can't inline this even though it has alwaysinline! 96define internal i32 @inner5(i8* %addr) alwaysinline { 97; CHECK-LABEL: @inner5( 98entry: 99 indirectbr i8* %addr, [ label %one, label %two ] 100 101one: 102 ret i32 42 103 104two: 105 ret i32 44 106} 107define i32 @outer5(i32 %x) { 108; CHECK-LABEL: @outer5( 109; CHECK: call i32 @inner5 110; CHECK: ret 111 112 %cmp = icmp slt i32 %x, 42 113 %addr = select i1 %cmp, i8* blockaddress(@inner5, %one), i8* blockaddress(@inner5, %two) 114 %call = call i32 @inner5(i8* %addr) 115 ret i32 %call 116} 117 118; We alwaysinline a function that call itself recursively. 119define internal void @inner6(i32 %x) alwaysinline { 120; CHECK-LABEL: @inner6( 121entry: 122 %icmp = icmp slt i32 %x, 0 123 br i1 %icmp, label %return, label %bb 124 125bb: 126 %sub = sub nsw i32 %x, 1 127 call void @inner6(i32 %sub) 128 ret void 129 130return: 131 ret void 132} 133define void @outer6() { 134; CHECK-LABEL: @outer6( 135; CHECK: call void @inner6(i32 42) 136; CHECK: ret 137 138entry: 139 call void @inner6(i32 42) 140 ret void 141} 142 143; This is not an alwaysinline function and is actually external. 144define i32 @inner7() { 145; CHECK-LABEL: @inner7( 146 ret i32 1 147} 148define i32 @outer7() { 149; CHECK-CALL-LABEL: @outer7( 150; CHECK-CALL-NOT: call 151; CHECK-CALL: ret 152 153 %r = call i32 @inner7() alwaysinline 154 ret i32 %r 155} 156 157define internal float* @inner8(float* nocapture align 128 %a) alwaysinline { 158; CHECK-NOT: @inner8( 159 ret float* %a 160} 161define float @outer8(float* nocapture %a) { 162; CHECK-LABEL: @outer8( 163; CHECK-NOT: call float* @inner8 164; CHECK: ret 165 166 %inner_a = call float* @inner8(float* %a) 167 %f = load float, float* %inner_a, align 4 168 ret float %f 169} 170 171 172; The 'inner9*' and 'outer9' functions are designed to check that we remove 173; a function that is inlined by the always inliner even when it is used by 174; a complex constant expression prior to being inlined. 175 176; The 'a' function gets used in a complex constant expression that, despite 177; being constant folded, means it isn't dead. As a consequence it shouldn't be 178; deleted. If it is, then the constant expression needs to become more complex 179; to accurately test this scenario. 180define internal void @inner9a(i1 %b) alwaysinline { 181; CHECK-LABEL: @inner9a( 182entry: 183 ret void 184} 185 186define internal void @inner9b(i1 %b) alwaysinline { 187; CHECK-NOT: @inner9b( 188entry: 189 ret void 190} 191 192declare void @dummy9(i1 %b) 193 194define void @outer9() { 195; CHECK-LABEL: @outer9( 196entry: 197 ; First we use @inner9a in a complex constant expression that may get folded 198 ; but won't get removed, and then we call it which will get inlined. Despite 199 ; this the function can't be deleted because of the constant expression 200 ; usage. 201 %sink = alloca i1 202 store volatile i1 icmp eq (i64 ptrtoint (void (i1)* @inner9a to i64), i64 ptrtoint(void (i1)* @dummy9 to i64)), i1* %sink 203; CHECK: store volatile 204 call void @inner9a(i1 false) 205; CHECK-NOT: call void @inner9a 206 207 ; Next we call @inner9b passing in a constant expression. This constant 208 ; expression will in fact be removed by inlining, so we should also be able 209 ; to delete the function. 210 call void @inner9b(i1 icmp eq (i64 ptrtoint (void (i1)* @inner9b to i64), i64 ptrtoint(void (i1)* @dummy9 to i64))) 211; CHECK-NOT: @inner9b 212 213 ret void 214; CHECK: ret void 215} 216 217; The 'inner10' and 'outer10' functions test a frustrating consequence of the 218; current 'alwaysinline' semantic model. Because such functions are allowed to 219; be external functions, it may be necessary to both inline all of their uses 220; and leave them in the final output. These tests can be removed if and when 221; we restrict alwaysinline further. 222define void @inner10() alwaysinline { 223; CHECK-LABEL: @inner10( 224entry: 225 ret void 226} 227 228define void @outer10() { 229; CHECK-LABEL: @outer10( 230entry: 231 call void @inner10() 232; CHECK-NOT: call void @inner10 233 234 ret void 235; CHECK: ret void 236} 237 238; The 'inner11' and 'outer11' functions test another dimension of non-internal 239; functions with alwaysinline. These functions use external linkages that we can 240; actually remove safely and so we should. 241define linkonce void @inner11a() alwaysinline { 242; CHECK-NOT: @inner11a( 243entry: 244 ret void 245} 246 247define available_externally void @inner11b() alwaysinline { 248; CHECK-NOT: @inner11b( 249entry: 250 ret void 251} 252 253define void @outer11() { 254; CHECK-LABEL: @outer11( 255entry: 256 call void @inner11a() 257 call void @inner11b() 258; CHECK-NOT: call void @inner11a 259; CHECK-NOT: call void @inner11b 260 261 ret void 262; CHECK: ret void 263} 264 265; The 'inner12' and 'outer12' functions test that we don't remove functions 266; which are part of a comdat group even if they otherwise seem dead. 267$comdat12 = comdat any 268 269define linkonce void @inner12() alwaysinline comdat($comdat12) { 270; CHECK-LABEL: @inner12( 271 ret void 272} 273 274define void @outer12() comdat($comdat12) { 275; CHECK-LABEL: @outer12( 276entry: 277 call void @inner12() 278; CHECK-NOT: call void @inner12 279 280 ret void 281; CHECK: ret void 282} 283 284; The 'inner13*' and 'outer13' functions test that we do remove functions 285; which are part of a comdat group where all of the members are removed during 286; always inlining. 287$comdat13 = comdat any 288 289define linkonce void @inner13a() alwaysinline comdat($comdat13) { 290; CHECK-NOT: @inner13a( 291 ret void 292} 293 294define linkonce void @inner13b() alwaysinline comdat($comdat13) { 295; CHECK-NOT: @inner13b( 296 ret void 297} 298 299define void @outer13() { 300; CHECK-LABEL: @outer13( 301entry: 302 call void @inner13a() 303 call void @inner13b() 304; CHECK-NOT: call void @inner13a 305; CHECK-NOT: call void @inner13b 306 307 ret void 308; CHECK: ret void 309} 310 311define void @inner14() readnone nounwind { 312; CHECK: define void @inner14 313 ret void 314} 315 316define void @outer14() { 317; CHECK: call void @inner14 318 call void @inner14() 319 ret void 320} 321