machine-copy-remove.mir 11.6 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610
# RUN: llc -mtriple=aarch64--linux-gnu -run-pass=aarch64-copyelim %s -verify-machineinstrs -o - | FileCheck %s
---
# Check that bb.0 COPY is seen through to allow the bb.1 COPY of XZR to be removed.
# CHECK-LABEL: name: test1
# CHECK-NOT: COPY $xzr
name:            test1
tracksRegLiveness: true
body:             |
  bb.0:
    liveins: $x0, $x1

    $x0 = COPY $x1
    CBNZX $x1, %bb.2

  bb.1:
    $x0 = COPY $xzr
    B %bb.3

  bb.2:
    liveins: $x1

    $x0 = LDRXui $x1, 0

  bb.3:
    liveins: $x0

    RET_ReallyLR implicit $x0

...
# Similar to test1, but with reversed COPY.
# CHECK-LABEL: name: test2
# CHECK-NOT: COPY $xzr
name:            test2
tracksRegLiveness: true
body:             |
  bb.0:
    liveins: $x0, $x1

    $x1 = COPY $x0
    CBNZX $x1, %bb.2

  bb.1:
    $x0 = COPY $xzr
    B %bb.3

  bb.2:
    liveins: $x1

    $x0 = LDRXui $x1, 0

  bb.3:
    liveins: $x0

    RET_ReallyLR implicit $x0

...
# Similar to test1, but with a clobber that prevents removal of the XZR COPY.
# CHECK-LABEL: name: test3
# CHECK: COPY $xzr
name:            test3
tracksRegLiveness: true
body:             |
  bb.0:
    liveins: $x0, $x1, $x2

    $x0 = COPY $x1
    $x1 = LDRXui $x1, 0
    CBNZX $x1, %bb.2

  bb.1:
    $x0 = COPY $xzr
    B %bb.3

  bb.2:
    liveins: $x1

    $x0 = LDRXui $x1, 0

  bb.3:
    liveins: $x0

    RET_ReallyLR implicit $x0

...
# Similar to test2, but with a clobber that prevents removal of the XZR COPY.
# CHECK-LABEL: name: test4
# CHECK: COPY $xzr
name:            test4
tracksRegLiveness: true
body:             |
  bb.0:
    liveins: $x0, $x1, $x2

    $x1 = COPY $x0
    $x1 = LDRXui $x1, 0
    CBNZX $x1, %bb.2

  bb.1:
    $x0 = COPY $xzr
    B %bb.3

  bb.2:
    liveins: $x1

    $x0 = LDRXui $x1, 0

  bb.3:
    liveins: $x0

    RET_ReallyLR implicit $x0

...
# Similar to test2, but with a clobber that prevents removal of the XZR COPY.
# CHECK-LABEL: name: test5
# CHECK: COPY $xzr
name:            test5
tracksRegLiveness: true
body:             |
  bb.0:
    liveins: $x0, $x1, $x2

    $x1 = COPY $x0
    $x0 = LDRXui $x1, 0
    CBNZX $x1, %bb.2

  bb.1:
    $x0 = COPY $xzr
    B %bb.3

  bb.2:
    liveins: $x1

    $x0 = LDRXui $x1, 0

  bb.3:
    liveins: $x0

    RET_ReallyLR implicit $x0

...
# Similar to test1, but with two levels of COPYs.
# CHECK-LABEL: name: test6
# CHECK-NOT: COPY $xzr
name:            test6
tracksRegLiveness: true
body:             |
  bb.0:
    liveins: $x0, $x1, $x2

    $x2 = COPY $x0
    $x1 = COPY $x2
    CBNZX $x1, %bb.2

  bb.1:
    $x0 = COPY $xzr
    B %bb.3

  bb.2:
    liveins: $x1

    $x0 = LDRXui $x1, 0

  bb.3:
    liveins: $x0

    RET_ReallyLR implicit $x0

...
# Similar to test1, but with two levels of COPYs and a clobber preventing COPY of XZR removal.
# CHECK-LABEL: name: test7
# CHECK: COPY $xzr
name:            test7
tracksRegLiveness: true
body:             |
  bb.0:
    liveins: $x0, $x1, $x2

    $x2 = COPY $x0
    $x0 = LDRXui $x1, 0
    $x1 = COPY $x2
    CBNZX $x1, %bb.2

  bb.1:
    $x0 = COPY $xzr
    B %bb.3

  bb.2:
    liveins: $x1

    $x0 = LDRXui $x1, 0

  bb.3:
    liveins: $x0

    RET_ReallyLR implicit $x0

...
# Check that the TargetRegs vector clobber update loop in
#  AArch64RedundantCopyElimination::optimizeCopy works correctly.
# CHECK-LABEL: name: test8
# CHECK: x0 = COPY $xzr
# CHECK: x1 = COPY $xzr
name:            test8
tracksRegLiveness: true
body:             |
  bb.0:
    liveins: $x0, $x1

    $x1 = COPY $x0
    CBNZX $x1, %bb.2

  bb.1:
    liveins: $x0, $x2

    $x0, $x1 = LDPXi $x2, 0
    $x0 = COPY $xzr
    $x1 = COPY $xzr
    B %bb.3

  bb.2:
    liveins: $x1

    $x0 = LDRXui $x1, 0

  bb.3:
    liveins: $x0

    RET_ReallyLR implicit $x0

...
# Check that copy isn't removed from a block with multiple predecessors.
# CHECK-LABEL: name: test9
# CHECK: x0 = COPY $xzr
# CHECK-NEXT: B %bb.3
name:            test9
tracksRegLiveness: true
body:             |
  bb.0:
    liveins: $x0, $x1

    CBNZX $x0, %bb.2

  bb.1:
    liveins: $x0, $x2

    $x0 = COPY $xzr
    B %bb.3

  bb.2:
    liveins: $x1

    $x0 = LDRXui $x1, 0

    CBNZX $x1, %bb.1

  bb.3:
    liveins: $x0

    RET_ReallyLR implicit $x0

...
# Eliminate redundant MOVi32imm 7 in bb.1
# Note: 32-bit compare/32-bit move imm
# Kill marker should be removed from compare.
# CHECK-LABEL: name: test10
# CHECK: SUBSWri $w0, 7, 0, implicit-def $nzcv
# CHECK: bb.1:
# CHECK-NOT: MOVi32imm
name:            test10
tracksRegLiveness: true
body:             |
  bb.0.entry:
    liveins: $w0, $x1

    dead $wzr = SUBSWri killed $w0, 7, 0, implicit-def $nzcv
    Bcc 1, %bb.2, implicit killed $nzcv
    B %bb.1

  bb.1:
    liveins: $x1

    $w0 = MOVi32imm 7
    STRWui killed $w0, killed $x1, 0

  bb.2:
    RET_ReallyLR
...
# Eliminate redundant MOVi32imm 7 in bb.1
# Note: 64-bit compare/32-bit move imm w/implicit def
# Kill marker should be removed from compare.
# CHECK-LABEL: name: test11
# CHECK: SUBSXri $x0, 7, 0, implicit-def $nzcv
# CHECK: bb.1:
# CHECK-NOT: MOVi32imm
name:            test11
tracksRegLiveness: true
body:             |
  bb.0.entry:
    liveins: $x0, $x1

    dead $xzr = SUBSXri killed $x0, 7, 0, implicit-def $nzcv
    Bcc 1, %bb.2, implicit killed $nzcv
    B %bb.1

  bb.1:
    liveins: $x1

    $w0 = MOVi32imm 7, implicit-def $x0
    STRXui killed $x0, killed $x1, 0

  bb.2:
    RET_ReallyLR
...
# Eliminate redundant MOVi32imm 7 in bb.1
# Note: 64-bit compare/32-bit move imm
# Kill marker should be removed from compare.
# CHECK-LABEL: name: test12
# CHECK: SUBSXri $x0, 7, 0, implicit-def $nzcv
# CHECK: bb.1:
# CHECK-NOT: MOVi32imm
name:            test12
tracksRegLiveness: true
body:             |
  bb.0.entry:
    liveins: $x0, $x1

    dead $xzr = SUBSXri killed $x0, 7, 0, implicit-def $nzcv
    Bcc 1, %bb.2, implicit killed $nzcv
    B %bb.1

  bb.1:
    liveins: $x1

    $w0 = MOVi32imm 7
    STRWui killed $w0, killed $x1, 0

  bb.2:
    RET_ReallyLR
...
# Don't eliminate MOVi32imm 7 in bb.1 as we don't necessarily know the upper 32-bits.
# Note: 32-bit compare/32-bit move imm w/implicit def
# Kill marker should remain on compare.
# CHECK-LABEL: name: test13
# CHECK: SUBSWri killed $w0, 7, 0, implicit-def $nzcv
# CHECK: bb.1:
# CHECK: MOVi32imm
name:            test13
tracksRegLiveness: true
body:             |
  bb.0.entry:
    liveins: $w0, $x1

    dead $wzr = SUBSWri killed $w0, 7, 0, implicit-def $nzcv
    Bcc 1, %bb.2, implicit killed $nzcv
    B %bb.1

  bb.1:
    liveins: $x1

    $w0 = MOVi32imm 7, implicit-def $x0
    STRXui killed $x0, killed $x1, 0

  bb.2:
    RET_ReallyLR
...
# We can't eliminate the MOVi32imm because of the clobbering LDRWui.
# CHECK-LABEL: name: test14
# CHECK: bb.1:
# CHECK: MOVi32imm
name:            test14
tracksRegLiveness: true
body:             |
  bb.0.entry:
    liveins: $w0, $x1, $x2

    dead $wzr = SUBSWri killed $w0, 7, 0, implicit-def $nzcv
    $w0 = LDRWui $x1, 0
    STRWui killed $w0, killed $x2, 0
    Bcc 1, %bb.2, implicit killed $nzcv
    B %bb.1

  bb.1:
    liveins: $x1

    $w0 = MOVi32imm 7
    STRWui killed $w0, killed $x1, 0

  bb.2:
    RET_ReallyLR
...
# We can't eliminate the MOVi32imm because of the clobbering LDRWui.
# CHECK-LABEL: name: test15
# CHECK: bb.1:
# CHECK: MOVi32imm
name:            test15
tracksRegLiveness: true
body:             |
  bb.0.entry:
    liveins: $w0, $x1, $x2

    dead $wzr = SUBSWri killed $w0, 7, 0, implicit-def $nzcv
    Bcc 1, %bb.2, implicit killed $nzcv
    B %bb.1

  bb.1:
    liveins: $x1, $x2

    $w0 = LDRWui $x1, 0
    STRWui killed $w0, killed $x2, 0
    $w0 = MOVi32imm 7
    STRWui killed $w0, killed $x1, 0

  bb.2:
    RET_ReallyLR
...
# Check that bb.0 COPY is seen through to allow the bb.1 MOVi32imm to be removed.
# CHECK-LABEL: name: test16
# CHECK: bb.1:
# CHECK-NOT: MOVi32imm
name:            test16
tracksRegLiveness: true
body:             |
  bb.0.entry:
    liveins: $w0, $x1

    dead $wzr = SUBSWri $w0, 7, 0, implicit-def $nzcv
    $w2 = COPY $w0
    Bcc 1, %bb.2, implicit killed $nzcv
    B %bb.1

  bb.1:
    liveins: $x1

    $w2 = MOVi32imm 7
    STRWui killed $w2, killed $x1, 0

  bb.2:
    RET_ReallyLR
...
# Check that bb.1 MOVi32imm is not removed due to self clobbering compare.
# CHECK-LABEL: name: test17
# CHECK: bb.1:
# CHECK: MOVi32imm
name:            test17
tracksRegLiveness: true
body:             |
  bb.0.entry:
    liveins: $w0, $x1

    dead $w0 = SUBSWri killed $w0, 7, 0, implicit-def $nzcv
    Bcc 1, %bb.2, implicit killed $nzcv
    B %bb.1

  bb.1:
    liveins: $x1

    $w0 = MOVi32imm 7
    STRWui killed $w0, killed $x1, 0

  bb.2:
    RET_ReallyLR
...
# Make sure the MOVi64imm is not removed.  In one version of this patch the
# MOVi64imm immediate was truncated to 32 bits and incorrectly matched because
# the low 32 bits of 4252017623040 are all zero.
# CHECK-LABEL: name: test18
# CHECK: bb.1:
# CHECK: MOVi64imm
name:            test18
tracksRegLiveness: true
body:             |
  bb.0.entry:
    liveins: $x0, $x1

    CBNZX killed $x0, %bb.2
    B %bb.1

  bb.1:
    liveins: $x1

    $x0 = MOVi64imm 4252017623040
    STRXui killed $x0, killed $x1, 0

  bb.2:
    RET_ReallyLR
...
# Eliminate redundant MOVi32imm -1 in bb.1
# Note: 32-bit compare/32-bit move imm
# Kill marker should be removed from compare.
# CHECK-LABEL: name: test19
# CHECK: ADDSWri $w0, 1, 0, implicit-def $nzcv
# CHECK: bb.1:
# CHECK-NOT: MOVi32imm
name:            test19
tracksRegLiveness: true
body:             |
  bb.0.entry:
    liveins: $w0, $x1

    dead $wzr = ADDSWri killed $w0, 1, 0, implicit-def $nzcv
    Bcc 1, %bb.2, implicit killed $nzcv
    B %bb.1

  bb.1:
    liveins: $x1

    $w0 = MOVi32imm -1
    STRWui killed $w0, killed $x1, 0

  bb.2:
    RET_ReallyLR
...
# Eliminate redundant MOVi64imm -1 in bb.1
# Note: 64-bit compare/64-bit move imm
# Kill marker should be removed from compare.
# CHECK-LABEL: name: test20
# CHECK: ADDSXri $x0, 1, 0, implicit-def $nzcv
# CHECK: bb.1:
# CHECK-NOT: MOVi64imm
name:            test20
tracksRegLiveness: true
body:             |
  bb.0:
    liveins: $x0, $x1

    dead $xzr = ADDSXri killed $x0, 1, 0, implicit-def $nzcv
    Bcc 1, %bb.2, implicit killed $nzcv
    B %bb.1

  bb.1:
    liveins: $x1

    $x0 = MOVi64imm -1
    STRXui killed $x0, killed $x1, 0

  bb.2:
    RET_ReallyLR
...
# Eliminate redundant MOVi32imm -1 in bb.1
# Note: 64-bit compare/32-bit move imm
# Kill marker should be removed from compare.
# CHECK-LABEL: name: test21
# CHECK: ADDSXri $x0, 1, 0, implicit-def $nzcv
# CHECK: bb.1:
# CHECK-NOT: MOVi32imm
name:            test21
tracksRegLiveness: true
body:             |
  bb.0.entry:
    liveins: $x0, $x1

    dead $xzr = ADDSXri killed $x0, 1, 0, implicit-def $nzcv
    Bcc 1, %bb.2, implicit killed $nzcv
    B %bb.1

  bb.1:
    liveins: $x1

    $w0 = MOVi32imm -1
    STRWui killed $w0, killed $x1, 0

  bb.2:
    RET_ReallyLR
...
# Don't eliminate MOVi64imm -1 in bb.1 as we don't necessarily know the upper 32-bits.
# Note: 32-bit compare/64-bit move imm
# CHECK-LABEL: name: test22
# CHECK: bb.1:
# CHECK: MOVi64imm
name:            test22
tracksRegLiveness: true
body:             |
  bb.0.entry:
    liveins: $w0, $x1

    dead $wzr = ADDSWri killed $w0, 1, 0, implicit-def $nzcv
    Bcc 1, %bb.2, implicit killed $nzcv
    B %bb.1

  bb.1:
    liveins: $x1

    $x0 = MOVi64imm -1
    STRXui killed $x0, killed $x1, 0

  bb.2:
    RET_ReallyLR
...
# Eliminate redundant MOVi32imm 4096 in bb.1 when the compare has a shifted immediate.
# CHECK-LABEL: name: test23
# CHECK: bb.1:
# CHECK-NOT: MOVi32imm
name:            test23
tracksRegLiveness: true
body:             |
  bb.0.entry:
    liveins: $w0, $x1

    dead $wzr = SUBSWri killed $w0, 1, 12, implicit-def $nzcv
    Bcc 1, %bb.2, implicit killed $nzcv
    B %bb.1

  bb.1:
    liveins: $x1

    $w0 = MOVi32imm 4096
    STRWui killed $w0, killed $x1, 0

  bb.2:
    RET_ReallyLR