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