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