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