1; RUN: opt -inline -mtriple=aarch64--linux-gnu -S -o - < %s -inline-threshold=0 | FileCheck %s 2 3target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128" 4target triple = "aarch64--linux-gnu" 5 6declare void @pad() 7@glbl = external global i32 8 9define i1 @outer1() { 10; CHECK-LABEL: @outer1( 11; CHECK-NOT: call i1 @inner1 12 %C = call i1 @inner1() 13 ret i1 %C 14} 15 16define i1 @inner1() { 17entry: 18 br label %if_true 19 20if_true: 21 %phi = phi i1 [0, %entry], [%phi, %if_true] ; Simplified to 0 22 br i1 %phi, label %if_true, label %exit 23 24exit: 25 store i32 0, i32* @glbl 26 store i32 1, i32* @glbl 27 store i32 2, i32* @glbl 28 store i32 3, i32* @glbl 29 store i32 4, i32* @glbl 30 ret i1 %phi 31} 32 33 34define i1 @outer2(i1 %val) { 35; CHECK-LABEL: @outer2( 36; CHECK: call i1 @inner2 37 %C = call i1 @inner2(i1 %val) 38 ret i1 %C 39} 40 41define i1 @inner2(i1 %val) { 42entry: 43 br label %if_true 44 45if_true: 46 %phi = phi i1 [%val, %entry], [%phi, %if_true] ; Cannot be simplified to a constant 47 br i1 %phi, label %if_true, label %exit 48 49exit: 50 call void @pad() 51 ret i1 %phi 52} 53 54 55define i1 @outer3(i1 %cond) { 56; CHECK-LABEL: @outer3( 57; CHECK-NOT: call i1 @inner3 58 %C = call i1 @inner3(i1 %cond) 59 ret i1 %C 60} 61 62define i1 @inner3(i1 %cond) { 63entry: 64 br i1 %cond, label %if_true, label %exit 65 66if_true: 67 br label %exit 68 69exit: 70 %phi = phi i32 [0, %entry], [0, %if_true] ; Simplified to 0 71 %cmp = icmp eq i32 %phi, 0 72 store i32 0, i32* @glbl 73 store i32 1, i32* @glbl 74 store i32 2, i32* @glbl 75 store i32 3, i32* @glbl 76 store i32 4, i32* @glbl 77 ret i1 %cmp 78} 79 80 81define i1 @outer4(i1 %cond) { 82; CHECK-LABEL: @outer4( 83; CHECK-NOT: call i1 @inner4 84 %C = call i1 @inner4(i1 %cond, i32 0) 85 ret i1 %C 86} 87 88define i1 @inner4(i1 %cond, i32 %val) { 89entry: 90 br i1 %cond, label %if_true, label %exit 91 92if_true: 93 br label %exit 94 95exit: 96 %phi = phi i32 [0, %entry], [%val, %if_true] ; Simplified to 0 97 %cmp = icmp eq i32 %phi, 0 98 call void @pad() 99 ret i1 %cmp 100} 101 102 103define i1 @outer5_1(i1 %cond) { 104; CHECK-LABEL: @outer5_1( 105; CHECK-NOT: call i1 @inner5 106 %C = call i1 @inner5(i1 %cond, i32 0, i32 0) 107 ret i1 %C 108} 109 110 111define i1 @outer5_2(i1 %cond) { 112; CHECK-LABEL: @outer5_2( 113; CHECK: call i1 @inner5 114 %C = call i1 @inner5(i1 %cond, i32 0, i32 1) 115 ret i1 %C 116} 117 118define i1 @inner5(i1 %cond, i32 %val1, i32 %val2) { 119entry: 120 br i1 %cond, label %if_true, label %exit 121 122if_true: 123 br label %exit 124 125exit: 126 %phi = phi i32 [%val1, %entry], [%val2, %if_true] ; Can be simplified to a constant if %val1 and %val2 are the same constants 127 %cmp = icmp eq i32 %phi, 0 128 call void @pad() 129 store i32 0, i32* @glbl 130 ret i1 %cmp 131} 132 133 134define i1 @outer6(i1 %cond, i32 %val) { 135; CHECK-LABEL: @outer6( 136; CHECK-NOT: call i1 @inner6 137 %C = call i1 @inner6(i1 true, i32 %val, i32 0) 138 ret i1 %C 139} 140 141define i1 @inner6(i1 %cond, i32 %val1, i32 %val2) { 142entry: 143 br i1 %cond, label %if_true, label %exit 144 145if_true: 146 br label %exit 147 148exit: 149 %phi = phi i32 [%val1, %entry], [%val2, %if_true] ; Simplified to 0 150 %cmp = icmp eq i32 %phi, 0 151 call void @pad() 152 store i32 0, i32* @glbl 153 store i32 1, i32* @glbl 154 ret i1 %cmp 155} 156 157 158define i1 @outer7(i1 %cond, i32 %val) { 159; CHECK-LABEL: @outer7( 160; CHECK-NOT: call i1 @inner7 161 %C = call i1 @inner7(i1 false, i32 0, i32 %val) 162 ret i1 %C 163} 164 165define i1 @inner7(i1 %cond, i32 %val1, i32 %val2) { 166entry: 167 br i1 %cond, label %if_true, label %exit 168 169if_true: 170 br label %exit 171 172exit: 173 %phi = phi i32 [%val1, %entry], [%val2, %if_true] ; Simplified to 0 174 %cmp = icmp eq i32 %phi, 0 175 call void @pad() 176 store i32 0, i32* @glbl 177 store i32 1, i32* @glbl 178 ret i1 %cmp 179} 180 181 182define i1 @outer8_1() { 183; CHECK-LABEL: @outer8_1( 184; CHECK-NOT: call i1 @inner8 185 %C = call i1 @inner8(i32 0) 186 ret i1 %C 187} 188 189 190 191define i1 @outer8_2() { 192; CHECK-LABEL: @outer8_2( 193; CHECK-NOT: call i1 @inner8 194 %C = call i1 @inner8(i32 3) 195 ret i1 %C 196} 197 198define i1 @inner8(i32 %cond) { 199entry: 200 switch i32 %cond, label %default [ i32 0, label %zero 201 i32 1, label %one 202 i32 2, label %two ] 203 204zero: 205 br label %exit 206 207one: 208 br label %exit 209 210two: 211 br label %exit 212 213default: 214 br label %exit 215 216exit: 217 %phi = phi i32 [0, %zero], [1, %one], [2, %two], [-1, %default] ; Can be simplified to a constant if the switch condition is known 218 %cmp = icmp eq i32 %phi, 0 219 call void @pad() 220 ret i1 %cmp 221} 222 223 224define i1 @outer9(i1 %cond) { 225; CHECK-LABEL: @outer9( 226; CHECK-NOT: call i1 @inner9 227 %C = call i1 @inner9(i32 0, i1 %cond) 228 ret i1 %C 229} 230 231define i1 @inner9(i32 %cond1, i1 %cond2) { 232entry: 233 switch i32 %cond1, label %exit [ i32 0, label %zero 234 i32 1, label %one 235 i32 2, label %two ] 236 237zero: 238 br label %exit 239 240one: 241 br label %exit 242 243two: 244 br i1 %cond2, label %two_true, label %two_false 245 246two_true: 247 br label %exit 248 249two_false: 250 br label %exit 251 252exit: 253 %phi = phi i32 [0, %zero], [1, %one], [2, %two_true], [2, %two_false], [-1, %entry] ; Simplified to 0 254 %cmp = icmp eq i32 %phi, 0 255 call void @pad() 256 store i32 0, i32* @glbl 257 ret i1 %cmp 258} 259 260 261define i32 @outer10(i1 %cond) { 262; CHECK-LABEL: @outer10( 263; CHECK-NOT: call i32 @inner10 264 %A = alloca i32 265 %C = call i32 @inner10(i1 %cond, i32* %A) 266 ret i32 %C 267} 268 269define i32 @inner10(i1 %cond, i32* %A) { 270entry: 271 br label %if_true 272 273if_true: 274 %phi = phi i32* [%A, %entry], [%phi, %if_true] ; Simplified to %A 275 %load = load i32, i32* %phi 276 br i1 %cond, label %if_true, label %exit 277 278exit: 279 call void @pad() 280 ret i32 %load 281} 282 283 284define i32 @outer11(i1 %cond, i32* %ptr) { 285; CHECK-LABEL: @outer11( 286; CHECK: call i32 @inner11 287 %C = call i32 @inner11(i1 %cond, i32* %ptr) 288 ret i32 %C 289} 290 291define i32 @inner11(i1 %cond, i32* %ptr) { 292entry: 293 br label %if_true 294 295if_true: 296 %phi = phi i32* [%ptr, %entry], [%phi, %if_true] ; Cannot be simplified 297 %load = load i32, i32* %phi 298 br i1 %cond, label %if_true, label %exit 299 300exit: 301 call void @pad() 302 ret i32 %load 303} 304 305 306define i32 @outer12(i1 %cond) { 307; CHECK-LABEL: @outer12( 308; CHECK-NOT: call i32 @inner12 309 %A = alloca i32 310 %C = call i32 @inner12(i1 %cond, i32* %A) 311 ret i32 %C 312} 313 314define i32 @inner12(i1 %cond, i32* %ptr) { 315entry: 316 br i1 %cond, label %if_true, label %exit 317 318if_true: 319 br label %exit 320 321exit: 322 %phi = phi i32* [%ptr, %entry], [%ptr, %if_true] ; Simplified to %A 323 %load = load i32, i32* %phi 324 call void @pad() 325 ret i32 %load 326} 327 328 329define i32 @outer13(i1 %cond) { 330; CHECK-LABEL: @outer13( 331; CHECK-NOT: call i32 @inner13 332 %A = alloca i32 333 %C = call i32 @inner13(i1 %cond, i32* %A) 334 ret i32 %C 335} 336 337define i32 @inner13(i1 %cond, i32* %ptr) { 338entry: 339 %gep1 = getelementptr inbounds i32, i32* %ptr, i32 2 340 %gep2 = getelementptr inbounds i32, i32* %ptr, i32 1 341 br i1 %cond, label %if_true, label %exit 342 343if_true: 344 %gep3 = getelementptr inbounds i32, i32* %gep2, i32 1 345 br label %exit 346 347exit: 348 %phi = phi i32* [%gep1, %entry], [%gep3, %if_true] ; Simplifeid to %gep1 349 %load = load i32, i32* %phi 350 call void @pad() 351 ret i32 %load 352} 353 354 355define i32 @outer14(i1 %cond) { 356; CHECK-LABEL: @outer14( 357; CHECK: call i32 @inner14 358 %A1 = alloca i32 359 %A2 = alloca i32 360 %C = call i32 @inner14(i1 %cond, i32* %A1, i32* %A2) 361 ret i32 %C 362} 363 364define i32 @inner14(i1 %cond, i32* %ptr1, i32* %ptr2) { 365entry: 366 br i1 %cond, label %if_true, label %exit 367 368if_true: 369 br label %exit 370 371exit: 372 %phi = phi i32* [%ptr1, %entry], [%ptr2, %if_true] ; Cannot be simplified 373 %load = load i32, i32* %phi 374 call void @pad() 375 store i32 0, i32* @glbl 376 ret i32 %load 377} 378 379 380define i32 @outer15(i1 %cond, i32* %ptr) { 381; CHECK-LABEL: @outer15( 382; CHECK-NOT: call i32 @inner15 383 %A = alloca i32 384 %C = call i32 @inner15(i1 true, i32* %ptr, i32* %A) 385 ret i32 %C 386} 387 388define i32 @inner15(i1 %cond, i32* %ptr1, i32* %ptr2) { 389entry: 390 br i1 %cond, label %if_true, label %exit 391 392if_true: 393 br label %exit 394 395exit: 396 %phi = phi i32* [%ptr1, %entry], [%ptr2, %if_true] ; Simplified to %A 397 %load = load i32, i32* %phi 398 call void @pad() 399 store i32 0, i32* @glbl 400 store i32 1, i32* @glbl 401 ret i32 %load 402} 403 404 405define i32 @outer16(i1 %cond, i32* %ptr) { 406; CHECK-LABEL: @outer16( 407; CHECK-NOT: call i32 @inner16 408 %A = alloca i32 409 %C = call i32 @inner16(i1 false, i32* %A, i32* %ptr) 410 ret i32 %C 411} 412 413define i32 @inner16(i1 %cond, i32* %ptr1, i32* %ptr2) { 414entry: 415 br i1 %cond, label %if_true, label %exit 416 417if_true: 418 br label %exit 419 420exit: 421 %phi = phi i32* [%ptr1, %entry], [%ptr2, %if_true] ; Simplified to %A 422 %load = load i32, i32* %phi 423 call void @pad() 424 store i32 0, i32* @glbl 425 store i32 1, i32* @glbl 426 ret i32 %load 427} 428 429 430define i1 @outer17(i1 %cond) { 431; CHECK-LABEL: @outer17( 432; CHECK: call i1 @inner17 433 %A = alloca i32 434 %C = call i1 @inner17(i1 %cond, i32* %A) 435 ret i1 %C 436} 437 438define i1 @inner17(i1 %cond, i32* %ptr) { 439entry: 440 br i1 %cond, label %if_true, label %exit 441 442if_true: 443 br label %exit 444 445exit: 446 %phi = phi i32* [null, %entry], [%ptr, %if_true] ; Cannot be mapped to a constant 447 %cmp = icmp eq i32* %phi, null 448 call void @pad() 449 ret i1 %cmp 450} 451 452 453define i1 @outer18(i1 %cond) { 454; CHECK-LABEL: @outer18( 455; CHECK-NOT: call i1 @inner18 456 %C = call i1 @inner18(i1 %cond, i1 true) 457 ret i1 %C 458} 459 460define i1 @inner18(i1 %cond1, i1 %cond2) { 461entry: 462 br i1 %cond1, label %block1, label %block2 463 464block1: 465 br i1 %cond2, label %block3, label %block4 466 467block2: 468 br i1 %cond2, label %block5, label %block4 469 470block3: 471 %phi = phi i32 [0, %block1], [1, %block4], [0, %block5] ; Simplified to 0 472 %cmp = icmp eq i32 %phi, 0 473 call void @pad() 474 ret i1 %cmp 475 476block4: ; Unreachable block 477 br label %block3 478 479block5: 480 br label %block3 481} 482 483 484define i1 @outer19(i1 %cond) { 485; CHECK-LABEL: @outer19( 486; CHECK: call i1 @inner19 487 %A = alloca i32 488 %C = call i1 @inner19(i1 %cond, i32* %A) 489 ret i1 %C 490} 491 492define i1 @inner19(i1 %cond, i32* %ptr) { 493entry: 494 br i1 %cond, label %if_true, label %exit 495 496if_true: 497 br label %exit 498 499exit: 500 %phi = phi i32* [%ptr, %entry], [null, %if_true] ; Cannot be mapped to a constant 501 %cmp = icmp eq i32* %phi, null 502 call void @pad() 503 ret i1 %cmp 504} 505