brintos

brintos / llvm-project-archived public Read only

0
0
Text · 29.0 KiB · a422f60 Raw
797 lines · plain
1# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py2# RUN: llc -mtriple=aarch64 -run-pass=aarch64-postlegalizer-lowering -verify-machineinstrs %s -o - | FileCheck %s --check-prefix=LOWER3# RUN: llc -mtriple=aarch64 -global-isel -start-before=aarch64-postlegalizer-lowering -stop-after=instruction-select -verify-machineinstrs %s -o - | FileCheck %s --check-prefix=SELECT4#5# Check that we swap the order of operands on comparisons when it is likely6# to introduce a folding opportunity.7#8# The condition code for the compare should be changed when appropriate.9#10# TODO: emitBinOp doesn't know about selectArithExtendedRegister, so some of11# these cases don't hit in selection yet.12 13...14---15name:            swap_sextinreg_lhs16legalized:       true17tracksRegLiveness: true18body:             |19  bb.0:20    liveins: $x0, $x121 22    ; LOWER-LABEL: name: swap_sextinreg_lhs23    ; LOWER: liveins: $x0, $x124    ; LOWER-NEXT: {{  $}}25    ; LOWER-NEXT: %reg:_(s64) = COPY $x026    ; LOWER-NEXT: %cmp_lhs:_(s64) = G_SEXT_INREG %reg, 827    ; LOWER-NEXT: %cmp_rhs:_(s64) = COPY $x128    ; LOWER-NEXT: %cmp:_(s32) = G_ICMP intpred(sle), %cmp_rhs(s64), %cmp_lhs29    ; LOWER-NEXT: $w0 = COPY %cmp(s32)30    ; LOWER-NEXT: RET_ReallyLR implicit $w031    ;32    ; SELECT-LABEL: name: swap_sextinreg_lhs33    ; SELECT: liveins: $x0, $x134    ; SELECT-NEXT: {{  $}}35    ; SELECT-NEXT: %reg:gpr64all = COPY $x036    ; SELECT-NEXT: [[COPY:%[0-9]+]]:gpr32all = COPY %reg.sub_3237    ; SELECT-NEXT: [[COPY1:%[0-9]+]]:gpr32 = COPY [[COPY]]38    ; SELECT-NEXT: %cmp_rhs:gpr64sp = COPY $x139    ; SELECT-NEXT: [[SUBSXrx:%[0-9]+]]:gpr64 = SUBSXrx %cmp_rhs, [[COPY1]], 32, implicit-def $nzcv40    ; SELECT-NEXT: %cmp:gpr32 = CSINCWr $wzr, $wzr, 12, implicit $nzcv41    ; SELECT-NEXT: $w0 = COPY %cmp42    ; SELECT-NEXT: RET_ReallyLR implicit $w043    %reg:_(s64) = COPY $x044    %cmp_lhs:_(s64) = G_SEXT_INREG %reg, 845    %cmp_rhs:_(s64) = COPY $x146    %cmp:_(s32) = G_ICMP intpred(sge), %cmp_lhs(s64), %cmp_rhs47    $w0 = COPY %cmp(s32)48    RET_ReallyLR implicit $w049 50...51---52name:            dont_swap_more_than_one_use53legalized:       true54tracksRegLiveness: true55body:             |56  bb.0:57    liveins: $x0, $x158 59    ; The LHS of the compare is used in an add, and a second compare. Don't60    ; swap, since we don't gain any folding opportunities here.61 62    ; LOWER-LABEL: name: dont_swap_more_than_one_use63    ; LOWER: liveins: $x0, $x164    ; LOWER-NEXT: {{  $}}65    ; LOWER-NEXT: %reg0:_(s64) = COPY $x066    ; LOWER-NEXT: %cmp_lhs:_(s64) = G_SEXT_INREG %reg0, 867    ; LOWER-NEXT: %reg1:_(s64) = COPY $x168    ; LOWER-NEXT: %cmp1:_(s32) = G_ICMP intpred(sge), %cmp_lhs(s64), %reg169    ; LOWER-NEXT: %add:_(s64) = G_ADD %cmp_lhs, %reg070    ; LOWER-NEXT: %cmp2:_(s32) = G_ICMP intpred(sge), %cmp_lhs(s64), %add71    ; LOWER-NEXT: $w0 = COPY %cmp2(s32)72    ; LOWER-NEXT: $w1 = COPY %cmp1(s32)73    ; LOWER-NEXT: RET_ReallyLR implicit $w0, implicit $w174    ;75    ; SELECT-LABEL: name: dont_swap_more_than_one_use76    ; SELECT: liveins: $x0, $x177    ; SELECT-NEXT: {{  $}}78    ; SELECT-NEXT: %reg0:gpr64 = COPY $x079    ; SELECT-NEXT: %cmp_lhs:gpr64 = SBFMXri %reg0, 0, 780    ; SELECT-NEXT: %reg1:gpr64 = COPY $x181    ; SELECT-NEXT: [[SUBSXrr:%[0-9]+]]:gpr64 = SUBSXrr %cmp_lhs, %reg1, implicit-def $nzcv82    ; SELECT-NEXT: %cmp1:gpr32 = CSINCWr $wzr, $wzr, 11, implicit $nzcv83    ; SELECT-NEXT: %add:gpr64 = ADDXrr %cmp_lhs, %reg084    ; SELECT-NEXT: [[SUBSXrr1:%[0-9]+]]:gpr64 = SUBSXrr %cmp_lhs, %add, implicit-def $nzcv85    ; SELECT-NEXT: %cmp2:gpr32 = CSINCWr $wzr, $wzr, 11, implicit $nzcv86    ; SELECT-NEXT: $w0 = COPY %cmp287    ; SELECT-NEXT: $w1 = COPY %cmp188    ; SELECT-NEXT: RET_ReallyLR implicit $w0, implicit $w189    %reg0:_(s64) = COPY $x090    %cmp_lhs:_(s64) = G_SEXT_INREG %reg0, 891    %reg1:_(s64) = COPY $x192    %cmp1:_(s32) = G_ICMP intpred(sge), %cmp_lhs(s64), %reg193 94    %add:_(s64) = G_ADD %cmp_lhs(s64), %reg095    %cmp2:_(s32) = G_ICMP intpred(sge), %cmp_lhs(s64), %add96 97    $w0 = COPY %cmp2(s32)98    $w1 = COPY %cmp1(s32)99    RET_ReallyLR implicit $w0, implicit $w1100 101...102---103name:            dont_swap_legal_arith_immed_on_rhs104legalized:       true105tracksRegLiveness: true106body:             |107  bb.0:108    liveins: $x0, $x1109    ; Arithmetic immediates can be folded into compares. If we have one, then110    ; don't bother changing anything.111 112    ; LOWER-LABEL: name: dont_swap_legal_arith_immed_on_rhs113    ; LOWER: liveins: $x0, $x1114    ; LOWER-NEXT: {{  $}}115    ; LOWER-NEXT: %reg:_(s64) = COPY $x0116    ; LOWER-NEXT: %cmp_lhs:_(s64) = G_SEXT_INREG %reg, 8117    ; LOWER-NEXT: %cmp_rhs:_(s64) = G_CONSTANT i64 12118    ; LOWER-NEXT: %cmp:_(s32) = G_ICMP intpred(sge), %cmp_lhs(s64), %cmp_rhs119    ; LOWER-NEXT: $w0 = COPY %cmp(s32)120    ; LOWER-NEXT: RET_ReallyLR implicit $w0121    ;122    ; SELECT-LABEL: name: dont_swap_legal_arith_immed_on_rhs123    ; SELECT: liveins: $x0, $x1124    ; SELECT-NEXT: {{  $}}125    ; SELECT-NEXT: %reg:gpr64 = COPY $x0126    ; SELECT-NEXT: %cmp_lhs:gpr64common = SBFMXri %reg, 0, 7127    ; SELECT-NEXT: [[SUBSXri:%[0-9]+]]:gpr64 = SUBSXri %cmp_lhs, 12, 0, implicit-def $nzcv128    ; SELECT-NEXT: %cmp:gpr32 = CSINCWr $wzr, $wzr, 11, implicit $nzcv129    ; SELECT-NEXT: $w0 = COPY %cmp130    ; SELECT-NEXT: RET_ReallyLR implicit $w0131    %reg:_(s64) = COPY $x0132    %cmp_lhs:_(s64) = G_SEXT_INREG %reg, 8133    %cmp_rhs:_(s64) = G_CONSTANT i64 12134    %cmp:_(s32) = G_ICMP intpred(sge), %cmp_lhs(s64), %cmp_rhs135    $w0 = COPY %cmp(s32)136    RET_ReallyLR implicit $w0137 138...139---140name:            swap_non_arith_immed_on_rhs141legalized:       true142tracksRegLiveness: true143body:             |144  bb.0:145    liveins: $x0, $x1146    ; If we have a non-arithmetic immediate on the rhs, then we can swap to get147    ; a guaranteed folding opportunity.148 149    ; LOWER-LABEL: name: swap_non_arith_immed_on_rhs150    ; LOWER: liveins: $x0, $x1151    ; LOWER-NEXT: {{  $}}152    ; LOWER-NEXT: %reg:_(s64) = COPY $x0153    ; LOWER-NEXT: %cmp_lhs:_(s64) = G_SEXT_INREG %reg, 8154    ; LOWER-NEXT: %cmp_rhs:_(s64) = G_CONSTANT i64 1234567155    ; LOWER-NEXT: %cmp:_(s32) = G_ICMP intpred(sle), %cmp_rhs(s64), %cmp_lhs156    ; LOWER-NEXT: $w0 = COPY %cmp(s32)157    ; LOWER-NEXT: RET_ReallyLR implicit $w0158    ;159    ; SELECT-LABEL: name: swap_non_arith_immed_on_rhs160    ; SELECT: liveins: $x0, $x1161    ; SELECT-NEXT: {{  $}}162    ; SELECT-NEXT: %reg:gpr64all = COPY $x0163    ; SELECT-NEXT: [[COPY:%[0-9]+]]:gpr32all = COPY %reg.sub_32164    ; SELECT-NEXT: [[COPY1:%[0-9]+]]:gpr32 = COPY [[COPY]]165    ; SELECT-NEXT: [[MOVi32imm:%[0-9]+]]:gpr32 = MOVi32imm 1234567166    ; SELECT-NEXT: %cmp_rhs:gpr64sp = SUBREG_TO_REG 0, [[MOVi32imm]], %subreg.sub_32167    ; SELECT-NEXT: [[SUBSXrx:%[0-9]+]]:gpr64 = SUBSXrx %cmp_rhs, [[COPY1]], 32, implicit-def $nzcv168    ; SELECT-NEXT: %cmp:gpr32 = CSINCWr $wzr, $wzr, 12, implicit $nzcv169    ; SELECT-NEXT: $w0 = COPY %cmp170    ; SELECT-NEXT: RET_ReallyLR implicit $w0171    %reg:_(s64) = COPY $x0172    %cmp_lhs:_(s64) = G_SEXT_INREG %reg, 8173    %cmp_rhs:_(s64) = G_CONSTANT i64 1234567174    %cmp:_(s32) = G_ICMP intpred(sge), %cmp_lhs(s64), %cmp_rhs175    $w0 = COPY %cmp(s32)176    RET_ReallyLR implicit $w0177 178...179---180name:            swap_and_lhs_0xFF181legalized:       true182tracksRegLiveness: true183body:             |184  bb.0:185    liveins: $x0, $x1186    ; LOWER-LABEL: name: swap_and_lhs_0xFF187    ; LOWER: liveins: $x0, $x1188    ; LOWER-NEXT: {{  $}}189    ; LOWER-NEXT: %cmp_rhs:_(s64) = COPY $x1190    ; LOWER-NEXT: %and_lhs:_(s64) = COPY $x0191    ; LOWER-NEXT: %cst:_(s64) = G_CONSTANT i64 255192    ; LOWER-NEXT: %cmp_lhs:_(s64) = G_AND %and_lhs, %cst193    ; LOWER-NEXT: %cmp:_(s32) = G_ICMP intpred(sle), %cmp_rhs(s64), %cmp_lhs194    ; LOWER-NEXT: $w0 = COPY %cmp(s32)195    ; LOWER-NEXT: RET_ReallyLR implicit $w0196    ;197    ; SELECT-LABEL: name: swap_and_lhs_0xFF198    ; SELECT: liveins: $x0, $x1199    ; SELECT-NEXT: {{  $}}200    ; SELECT-NEXT: %cmp_rhs:gpr64sp = COPY $x1201    ; SELECT-NEXT: %and_lhs:gpr64all = COPY $x0202    ; SELECT-NEXT: [[COPY:%[0-9]+]]:gpr32all = COPY %and_lhs.sub_32203    ; SELECT-NEXT: [[COPY1:%[0-9]+]]:gpr32 = COPY [[COPY]]204    ; SELECT-NEXT: [[SUBSXrx:%[0-9]+]]:gpr64 = SUBSXrx %cmp_rhs, [[COPY1]], 0, implicit-def $nzcv205    ; SELECT-NEXT: %cmp:gpr32 = CSINCWr $wzr, $wzr, 12, implicit $nzcv206    ; SELECT-NEXT: $w0 = COPY %cmp207    ; SELECT-NEXT: RET_ReallyLR implicit $w0208    %cmp_rhs:_(s64) = COPY $x1209 210    %and_lhs:_(s64) = COPY $x0211    %cst:_(s64) = G_CONSTANT i64 255212    %cmp_lhs:_(s64) = G_AND %and_lhs, %cst(s64)213 214    %cmp:_(s32) = G_ICMP intpred(sge), %cmp_lhs(s64), %cmp_rhs215    $w0 = COPY %cmp(s32)216    RET_ReallyLR implicit $w0217 218...219---220name:            swap_and_lhs_0xFFFF221legalized:       true222tracksRegLiveness: true223body:             |224  bb.0:225    liveins: $x0, $x1226    ; LOWER-LABEL: name: swap_and_lhs_0xFFFF227    ; LOWER: liveins: $x0, $x1228    ; LOWER-NEXT: {{  $}}229    ; LOWER-NEXT: %cmp_rhs:_(s64) = COPY $x1230    ; LOWER-NEXT: %cst:_(s64) = G_CONSTANT i64 65535231    ; LOWER-NEXT: %and_lhs:_(s64) = COPY $x0232    ; LOWER-NEXT: %cmp_lhs:_(s64) = G_AND %and_lhs, %cst233    ; LOWER-NEXT: %cmp:_(s32) = G_ICMP intpred(sle), %cmp_rhs(s64), %cmp_lhs234    ; LOWER-NEXT: $w0 = COPY %cmp(s32)235    ; LOWER-NEXT: RET_ReallyLR implicit $w0236    ;237    ; SELECT-LABEL: name: swap_and_lhs_0xFFFF238    ; SELECT: liveins: $x0, $x1239    ; SELECT-NEXT: {{  $}}240    ; SELECT-NEXT: %cmp_rhs:gpr64sp = COPY $x1241    ; SELECT-NEXT: %and_lhs:gpr64all = COPY $x0242    ; SELECT-NEXT: [[COPY:%[0-9]+]]:gpr32all = COPY %and_lhs.sub_32243    ; SELECT-NEXT: [[COPY1:%[0-9]+]]:gpr32 = COPY [[COPY]]244    ; SELECT-NEXT: [[SUBSXrx:%[0-9]+]]:gpr64 = SUBSXrx %cmp_rhs, [[COPY1]], 8, implicit-def $nzcv245    ; SELECT-NEXT: %cmp:gpr32 = CSINCWr $wzr, $wzr, 12, implicit $nzcv246    ; SELECT-NEXT: $w0 = COPY %cmp247    ; SELECT-NEXT: RET_ReallyLR implicit $w0248    %cmp_rhs:_(s64) = COPY $x1249 250    %cst:_(s64) = G_CONSTANT i64 65535251    %and_lhs:_(s64) = COPY $x0252    %cmp_lhs:_(s64) = G_AND %and_lhs, %cst(s64)253 254    %cmp:_(s32) = G_ICMP intpred(sge), %cmp_lhs(s64), %cmp_rhs255    $w0 = COPY %cmp(s32)256    RET_ReallyLR implicit $w0257 258...259---260name:            swap_and_lhs_0xFFFFFFFF261legalized:       true262tracksRegLiveness: true263body:             |264  bb.0:265    liveins: $x0, $x1266    ; LOWER-LABEL: name: swap_and_lhs_0xFFFFFFFF267    ; LOWER: liveins: $x0, $x1268    ; LOWER-NEXT: {{  $}}269    ; LOWER-NEXT: %cmp_rhs:_(s64) = COPY $x1270    ; LOWER-NEXT: %and_lhs:_(s64) = COPY $x0271    ; LOWER-NEXT: %cst:_(s64) = G_CONSTANT i64 4294967295272    ; LOWER-NEXT: %cmp_lhs:_(s64) = G_AND %and_lhs, %cst273    ; LOWER-NEXT: %cmp:_(s32) = G_ICMP intpred(sle), %cmp_rhs(s64), %cmp_lhs274    ; LOWER-NEXT: $w0 = COPY %cmp(s32)275    ; LOWER-NEXT: RET_ReallyLR implicit $w0276    ;277    ; SELECT-LABEL: name: swap_and_lhs_0xFFFFFFFF278    ; SELECT: liveins: $x0, $x1279    ; SELECT-NEXT: {{  $}}280    ; SELECT-NEXT: %cmp_rhs:gpr64sp = COPY $x1281    ; SELECT-NEXT: %and_lhs:gpr64all = COPY $x0282    ; SELECT-NEXT: [[COPY:%[0-9]+]]:gpr32all = COPY %and_lhs.sub_32283    ; SELECT-NEXT: [[COPY1:%[0-9]+]]:gpr32 = COPY [[COPY]]284    ; SELECT-NEXT: [[SUBSXrx:%[0-9]+]]:gpr64 = SUBSXrx %cmp_rhs, [[COPY1]], 16, implicit-def $nzcv285    ; SELECT-NEXT: %cmp:gpr32 = CSINCWr $wzr, $wzr, 12, implicit $nzcv286    ; SELECT-NEXT: $w0 = COPY %cmp287    ; SELECT-NEXT: RET_ReallyLR implicit $w0288    %cmp_rhs:_(s64) = COPY $x1289 290    %and_lhs:_(s64) = COPY $x0291    %cst:_(s64) = G_CONSTANT i64 4294967295292    %cmp_lhs:_(s64) = G_AND %and_lhs, %cst(s64)293 294    %cmp:_(s32) = G_ICMP intpred(sge), %cmp_lhs(s64), %cmp_rhs295    $w0 = COPY %cmp(s32)296    RET_ReallyLR implicit $w0297 298...299---300name:            dont_swap_and_lhs_wrong_mask301legalized:       true302tracksRegLiveness: true303body:             |304  bb.0:305    liveins: $x0, $x1306    ; 7 isn't an extend mask for G_AND, so there's no folding opportunities307    ; here.308    ; LOWER-LABEL: name: dont_swap_and_lhs_wrong_mask309    ; LOWER: liveins: $x0, $x1310    ; LOWER-NEXT: {{  $}}311    ; LOWER-NEXT: %cmp_rhs:_(s64) = COPY $x1312    ; LOWER-NEXT: %and_lhs:_(s64) = COPY $x0313    ; LOWER-NEXT: %not_an_extend_mask:_(s64) = G_CONSTANT i64 7314    ; LOWER-NEXT: %cmp_lhs:_(s64) = G_AND %and_lhs, %not_an_extend_mask315    ; LOWER-NEXT: %cmp:_(s32) = G_ICMP intpred(sge), %cmp_lhs(s64), %cmp_rhs316    ; LOWER-NEXT: $w0 = COPY %cmp(s32)317    ; LOWER-NEXT: RET_ReallyLR implicit $w0318    ;319    ; SELECT-LABEL: name: dont_swap_and_lhs_wrong_mask320    ; SELECT: liveins: $x0, $x1321    ; SELECT-NEXT: {{  $}}322    ; SELECT-NEXT: %cmp_rhs:gpr64 = COPY $x1323    ; SELECT-NEXT: %and_lhs:gpr64 = COPY $x0324    ; SELECT-NEXT: %cmp_lhs:gpr64common = ANDXri %and_lhs, 4098325    ; SELECT-NEXT: [[SUBSXrr:%[0-9]+]]:gpr64 = SUBSXrr %cmp_lhs, %cmp_rhs, implicit-def $nzcv326    ; SELECT-NEXT: %cmp:gpr32 = CSINCWr $wzr, $wzr, 11, implicit $nzcv327    ; SELECT-NEXT: $w0 = COPY %cmp328    ; SELECT-NEXT: RET_ReallyLR implicit $w0329    %cmp_rhs:_(s64) = COPY $x1330 331    %and_lhs:_(s64) = COPY $x0332    %not_an_extend_mask:_(s64) = G_CONSTANT i64 7333    %cmp_lhs:_(s64) = G_AND %and_lhs, %not_an_extend_mask(s64)334 335    %cmp:_(s32) = G_ICMP intpred(sge), %cmp_lhs(s64), %cmp_rhs336    $w0 = COPY %cmp(s32)337    RET_ReallyLR implicit $w0338 339...340---341name:            swap_shl_lhs342legalized:       true343tracksRegLiveness: true344body:             |345  bb.0:346    liveins: $x0, $x1347 348    ; LOWER-LABEL: name: swap_shl_lhs349    ; LOWER: liveins: $x0, $x1350    ; LOWER-NEXT: {{  $}}351    ; LOWER-NEXT: %cmp_rhs:_(s64) = COPY $x1352    ; LOWER-NEXT: %shl_lhs:_(s64) = COPY $x0353    ; LOWER-NEXT: %cst:_(s64) = G_CONSTANT i64 1354    ; LOWER-NEXT: %cmp_lhs:_(s64) = G_SHL %shl_lhs, %cst(s64)355    ; LOWER-NEXT: %cmp:_(s32) = G_ICMP intpred(sgt), %cmp_rhs(s64), %cmp_lhs356    ; LOWER-NEXT: $w0 = COPY %cmp(s32)357    ; LOWER-NEXT: RET_ReallyLR implicit $w0358    ;359    ; SELECT-LABEL: name: swap_shl_lhs360    ; SELECT: liveins: $x0, $x1361    ; SELECT-NEXT: {{  $}}362    ; SELECT-NEXT: %cmp_rhs:gpr64 = COPY $x1363    ; SELECT-NEXT: %shl_lhs:gpr64 = COPY $x0364    ; SELECT-NEXT: [[SUBSXrs:%[0-9]+]]:gpr64 = SUBSXrs %cmp_rhs, %shl_lhs, 1, implicit-def $nzcv365    ; SELECT-NEXT: %cmp:gpr32 = CSINCWr $wzr, $wzr, 13, implicit $nzcv366    ; SELECT-NEXT: $w0 = COPY %cmp367    ; SELECT-NEXT: RET_ReallyLR implicit $w0368    %cmp_rhs:_(s64) = COPY $x1369 370    %shl_lhs:_(s64) = COPY $x0371    %cst:_(s64) = G_CONSTANT i64 1372    %cmp_lhs:_(s64) = G_SHL %shl_lhs, %cst(s64)373 374    %cmp:_(s32) = G_ICMP intpred(slt), %cmp_lhs(s64), %cmp_rhs375    $w0 = COPY %cmp(s32)376    RET_ReallyLR implicit $w0377 378...379---380name:            swap_ashr_lhs381legalized:       true382tracksRegLiveness: true383body:             |384  bb.0:385    liveins: $x0, $x1386 387    ; LOWER-LABEL: name: swap_ashr_lhs388    ; LOWER: liveins: $x0, $x1389    ; LOWER-NEXT: {{  $}}390    ; LOWER-NEXT: %cmp_rhs:_(s64) = COPY $x1391    ; LOWER-NEXT: %ashr_lhs:_(s64) = COPY $x0392    ; LOWER-NEXT: %cst:_(s64) = G_CONSTANT i64 1393    ; LOWER-NEXT: %cmp_lhs:_(s64) = G_ASHR %ashr_lhs, %cst(s64)394    ; LOWER-NEXT: %cmp:_(s32) = G_ICMP intpred(sgt), %cmp_rhs(s64), %cmp_lhs395    ; LOWER-NEXT: $w0 = COPY %cmp(s32)396    ; LOWER-NEXT: RET_ReallyLR implicit $w0397    ;398    ; SELECT-LABEL: name: swap_ashr_lhs399    ; SELECT: liveins: $x0, $x1400    ; SELECT-NEXT: {{  $}}401    ; SELECT-NEXT: %cmp_rhs:gpr64 = COPY $x1402    ; SELECT-NEXT: %ashr_lhs:gpr64 = COPY $x0403    ; SELECT-NEXT: [[SUBSXrs:%[0-9]+]]:gpr64 = SUBSXrs %cmp_rhs, %ashr_lhs, 129, implicit-def $nzcv404    ; SELECT-NEXT: %cmp:gpr32 = CSINCWr $wzr, $wzr, 13, implicit $nzcv405    ; SELECT-NEXT: $w0 = COPY %cmp406    ; SELECT-NEXT: RET_ReallyLR implicit $w0407    %cmp_rhs:_(s64) = COPY $x1408 409    %ashr_lhs:_(s64) = COPY $x0410    %cst:_(s64) = G_CONSTANT i64 1411    %cmp_lhs:_(s64) = G_ASHR %ashr_lhs, %cst(s64)412 413    %cmp:_(s32) = G_ICMP intpred(slt), %cmp_lhs(s64), %cmp_rhs414    $w0 = COPY %cmp(s32)415    RET_ReallyLR implicit $w0416 417...418---419name:            swap_lshr_lhs420legalized:       true421tracksRegLiveness: true422body:             |423  bb.0:424    liveins: $x0, $x1425 426    ; LOWER-LABEL: name: swap_lshr_lhs427    ; LOWER: liveins: $x0, $x1428    ; LOWER-NEXT: {{  $}}429    ; LOWER-NEXT: %cmp_rhs:_(s64) = COPY $x1430    ; LOWER-NEXT: %lshr_lhs:_(s64) = COPY $x0431    ; LOWER-NEXT: %cst:_(s64) = G_CONSTANT i64 1432    ; LOWER-NEXT: %cmp_lhs:_(s64) = G_LSHR %lshr_lhs, %cst(s64)433    ; LOWER-NEXT: %cmp:_(s32) = G_ICMP intpred(sgt), %cmp_rhs(s64), %cmp_lhs434    ; LOWER-NEXT: $w0 = COPY %cmp(s32)435    ; LOWER-NEXT: RET_ReallyLR implicit $w0436    ;437    ; SELECT-LABEL: name: swap_lshr_lhs438    ; SELECT: liveins: $x0, $x1439    ; SELECT-NEXT: {{  $}}440    ; SELECT-NEXT: %cmp_rhs:gpr64 = COPY $x1441    ; SELECT-NEXT: %lshr_lhs:gpr64 = COPY $x0442    ; SELECT-NEXT: [[SUBSXrs:%[0-9]+]]:gpr64 = SUBSXrs %cmp_rhs, %lshr_lhs, 65, implicit-def $nzcv443    ; SELECT-NEXT: %cmp:gpr32 = CSINCWr $wzr, $wzr, 13, implicit $nzcv444    ; SELECT-NEXT: $w0 = COPY %cmp445    ; SELECT-NEXT: RET_ReallyLR implicit $w0446    %cmp_rhs:_(s64) = COPY $x1447 448    %lshr_lhs:_(s64) = COPY $x0449    %cst:_(s64) = G_CONSTANT i64 1450    %cmp_lhs:_(s64) = G_LSHR %lshr_lhs, %cst(s64)451 452    %cmp:_(s32) = G_ICMP intpred(slt), %cmp_lhs(s64), %cmp_rhs453    $w0 = COPY %cmp(s32)454    RET_ReallyLR implicit $w0455 456...457---458name:            dont_swap_shift_s64_cst_too_large459legalized:       true460tracksRegLiveness: true461body:             |462  bb.0:463    liveins: $x0, $x1464 465    ; Constant for the shift must be <= 63.466 467    ; LOWER-LABEL: name: dont_swap_shift_s64_cst_too_large468    ; LOWER: liveins: $x0, $x1469    ; LOWER-NEXT: {{  $}}470    ; LOWER-NEXT: %cmp_rhs:_(s64) = COPY $x1471    ; LOWER-NEXT: %shl_lhs:_(s64) = COPY $x0472    ; LOWER-NEXT: %too_large:_(s64) = G_CONSTANT i64 64473    ; LOWER-NEXT: %cmp_lhs:_(s64) = G_SHL %shl_lhs, %too_large(s64)474    ; LOWER-NEXT: %cmp:_(s32) = G_ICMP intpred(slt), %cmp_lhs(s64), %cmp_rhs475    ; LOWER-NEXT: $w0 = COPY %cmp(s32)476    ; LOWER-NEXT: RET_ReallyLR implicit $w0477    ;478    ; SELECT-LABEL: name: dont_swap_shift_s64_cst_too_large479    ; SELECT: liveins: $x0, $x1480    ; SELECT-NEXT: {{  $}}481    ; SELECT-NEXT: %cmp_rhs:gpr64 = COPY $x1482    ; SELECT-NEXT: %shl_lhs:gpr64 = COPY $x0483    ; SELECT-NEXT: [[MOVi32imm:%[0-9]+]]:gpr32 = MOVi32imm 64484    ; SELECT-NEXT: %too_large:gpr64 = SUBREG_TO_REG 0, [[MOVi32imm]], %subreg.sub_32485    ; SELECT-NEXT: %cmp_lhs:gpr64 = LSLVXr %shl_lhs, %too_large486    ; SELECT-NEXT: [[SUBSXrr:%[0-9]+]]:gpr64 = SUBSXrr %cmp_lhs, %cmp_rhs, implicit-def $nzcv487    ; SELECT-NEXT: %cmp:gpr32 = CSINCWr $wzr, $wzr, 10, implicit $nzcv488    ; SELECT-NEXT: $w0 = COPY %cmp489    ; SELECT-NEXT: RET_ReallyLR implicit $w0490    %cmp_rhs:_(s64) = COPY $x1491 492    %shl_lhs:_(s64) = COPY $x0493    %too_large:_(s64) = G_CONSTANT i64 64494    %cmp_lhs:_(s64) = G_SHL %shl_lhs, %too_large(s64)495 496    %cmp:_(s32) = G_ICMP intpred(slt), %cmp_lhs(s64), %cmp_rhs497    $w0 = COPY %cmp(s32)498    RET_ReallyLR implicit $w0499 500 501...502---503name:            dont_swap_shift_s32_cst_too_large504legalized:       true505tracksRegLiveness: true506body:             |507  bb.0:508    liveins: $w0, $w1509 510    ; Constant for the shift must be <= 32.511 512    ; LOWER-LABEL: name: dont_swap_shift_s32_cst_too_large513    ; LOWER: liveins: $w0, $w1514    ; LOWER-NEXT: {{  $}}515    ; LOWER-NEXT: %cmp_rhs:_(s32) = COPY $w1516    ; LOWER-NEXT: %shl_lhs:_(s32) = COPY $w0517    ; LOWER-NEXT: %cst:_(s32) = G_CONSTANT i32 32518    ; LOWER-NEXT: %cmp_lhs:_(s32) = G_SHL %shl_lhs, %cst(s32)519    ; LOWER-NEXT: %cmp:_(s32) = G_ICMP intpred(slt), %cmp_lhs(s32), %cmp_rhs520    ; LOWER-NEXT: $w0 = COPY %cmp(s32)521    ; LOWER-NEXT: RET_ReallyLR implicit $w0522    ;523    ; SELECT-LABEL: name: dont_swap_shift_s32_cst_too_large524    ; SELECT: liveins: $w0, $w1525    ; SELECT-NEXT: {{  $}}526    ; SELECT-NEXT: %cmp_rhs:gpr32 = COPY $w1527    ; SELECT-NEXT: %shl_lhs:gpr32 = COPY $w0528    ; SELECT-NEXT: %cst:gpr32 = MOVi32imm 32529    ; SELECT-NEXT: %cmp_lhs:gpr32 = LSLVWr %shl_lhs, %cst530    ; SELECT-NEXT: [[SUBSWrr:%[0-9]+]]:gpr32 = SUBSWrr %cmp_lhs, %cmp_rhs, implicit-def $nzcv531    ; SELECT-NEXT: %cmp:gpr32 = CSINCWr $wzr, $wzr, 10, implicit $nzcv532    ; SELECT-NEXT: $w0 = COPY %cmp533    ; SELECT-NEXT: RET_ReallyLR implicit $w0534    %cmp_rhs:_(s32) = COPY $w1535 536    %shl_lhs:_(s32) = COPY $w0537    %cst:_(s32) = G_CONSTANT i32 32538    %cmp_lhs:_(s32) = G_SHL %shl_lhs, %cst(s32)539 540    %cmp:_(s32) = G_ICMP intpred(slt), %cmp_lhs(s32), %cmp_rhs541    $w0 = COPY %cmp(s32)542    RET_ReallyLR implicit $w0543 544...545---546name:            dont_swap_cmn_lhs_no_folding_opportunities547legalized:       true548tracksRegLiveness: true549body:             |550  bb.0.entry:551    liveins: $x0, $x1552 553    ; No reason to swap a CMN on the LHS when it won't introduce a constant554    ; folding opportunity. We can recognise CMNs on the LHS and RHS, so there's555    ; nothing to gain here.556 557    ; LOWER-LABEL: name: dont_swap_cmn_lhs_no_folding_opportunities558    ; LOWER: liveins: $x0, $x1559    ; LOWER-NEXT: {{  $}}560    ; LOWER-NEXT: %cmp_rhs:_(s64) = COPY $x1561    ; LOWER-NEXT: %sub_rhs:_(s64) = COPY $x0562    ; LOWER-NEXT: %zero:_(s64) = G_CONSTANT i64 0563    ; LOWER-NEXT: %cmp_lhs:_(s64) = G_SUB %zero, %sub_rhs564    ; LOWER-NEXT: %cmp:_(s32) = G_ICMP intpred(ne), %cmp_lhs(s64), %cmp_rhs565    ; LOWER-NEXT: $w0 = COPY %cmp(s32)566    ; LOWER-NEXT: RET_ReallyLR implicit $w0567    ;568    ; SELECT-LABEL: name: dont_swap_cmn_lhs_no_folding_opportunities569    ; SELECT: liveins: $x0, $x1570    ; SELECT-NEXT: {{  $}}571    ; SELECT-NEXT: %cmp_rhs:gpr64 = COPY $x1572    ; SELECT-NEXT: %sub_rhs:gpr64 = COPY $x0573    ; SELECT-NEXT: [[ADDSXrr:%[0-9]+]]:gpr64 = ADDSXrr %sub_rhs, %cmp_rhs, implicit-def $nzcv574    ; SELECT-NEXT: %cmp:gpr32 = CSINCWr $wzr, $wzr, 0, implicit $nzcv575    ; SELECT-NEXT: $w0 = COPY %cmp576    ; SELECT-NEXT: RET_ReallyLR implicit $w0577    %cmp_rhs:_(s64) = COPY $x1578 579    %sub_rhs:_(s64) = COPY $x0580    %zero:_(s64) = G_CONSTANT i64 0581    %cmp_lhs:_(s64) = G_SUB %zero, %sub_rhs582 583    %cmp:_(s32) = G_ICMP intpred(ne), %cmp_lhs(s64), %cmp_rhs584    $w0 = COPY %cmp(s32)585    RET_ReallyLR implicit $w0586 587...588---589name:            swap_cmn_lhs590legalized:       true591tracksRegLiveness: true592body:             |593  bb.0.entry:594    liveins: $x0, $x1595 596    ; Swap when we can see a constant folding opportunity through the sub on597    ; the LHS.598 599 600    ; LOWER-LABEL: name: swap_cmn_lhs601    ; LOWER: liveins: $x0, $x1602    ; LOWER-NEXT: {{  $}}603    ; LOWER-NEXT: %cmp_rhs:_(s64) = COPY $x1604    ; LOWER-NEXT: %shl_lhs:_(s64) = COPY $x0605    ; LOWER-NEXT: %zero:_(s64) = G_CONSTANT i64 0606    ; LOWER-NEXT: %cst:_(s64) = G_CONSTANT i64 63607    ; LOWER-NEXT: %sub_rhs:_(s64) = G_SHL %shl_lhs, %cst(s64)608    ; LOWER-NEXT: %cmp_lhs:_(s64) = G_SUB %zero, %sub_rhs609    ; LOWER-NEXT: %cmp:_(s32) = G_ICMP intpred(ne), %cmp_rhs(s64), %cmp_lhs610    ; LOWER-NEXT: $w0 = COPY %cmp(s32)611    ; LOWER-NEXT: RET_ReallyLR implicit $w0612    ;613    ; SELECT-LABEL: name: swap_cmn_lhs614    ; SELECT: liveins: $x0, $x1615    ; SELECT-NEXT: {{  $}}616    ; SELECT-NEXT: %cmp_rhs:gpr64 = COPY $x1617    ; SELECT-NEXT: %shl_lhs:gpr64 = COPY $x0618    ; SELECT-NEXT: [[ADDSXrs:%[0-9]+]]:gpr64 = ADDSXrs %cmp_rhs, %shl_lhs, 63, implicit-def $nzcv619    ; SELECT-NEXT: %cmp:gpr32 = CSINCWr $wzr, $wzr, 0, implicit $nzcv620    ; SELECT-NEXT: $w0 = COPY %cmp621    ; SELECT-NEXT: RET_ReallyLR implicit $w0622    %cmp_rhs:_(s64) = COPY $x1623 624    %shl_lhs:_(s64) = COPY $x0625    %zero:_(s64) = G_CONSTANT i64 0626    %cst:_(s64) = G_CONSTANT i64 63627    %sub_rhs:_(s64) = G_SHL %shl_lhs, %cst(s64)628    %cmp_lhs:_(s64) = G_SUB %zero, %sub_rhs629 630    %cmp:_(s32) = G_ICMP intpred(ne), %cmp_lhs(s64), %cmp_rhs631    $w0 = COPY %cmp(s32)632    RET_ReallyLR implicit $w0633 634...635---636name:            dont_swap_cmn_lhs_when_rhs_more_profitable637legalized:       true638tracksRegLiveness: true639body:             |640  bb.0.entry:641    liveins: $x0, $x1642 643    ; Don't swap when the RHS's subtract offers a better constant folding644    ; opportunity than the LHS's subtract.645    ; In this case, the RHS has a supported extend, plus a shift with a constant646    ; <= 4.647 648    ; LOWER-LABEL: name: dont_swap_cmn_lhs_when_rhs_more_profitable649    ; LOWER: liveins: $x0, $x1650    ; LOWER-NEXT: {{  $}}651    ; LOWER-NEXT: %zero:_(s64) = G_CONSTANT i64 0652    ; LOWER-NEXT: %reg0:_(s64) = COPY $x0653    ; LOWER-NEXT: %shl_cst:_(s64) = G_CONSTANT i64 63654    ; LOWER-NEXT: %shl:_(s64) = G_SHL %reg0, %shl_cst(s64)655    ; LOWER-NEXT: %cmp_lhs:_(s64) = G_SUB %zero, %shl656    ; LOWER-NEXT: %reg1:_(s64) = COPY $x1657    ; LOWER-NEXT: %sext_in_reg:_(s64) = G_SEXT_INREG %reg1, 1658    ; LOWER-NEXT: %ashr_cst:_(s64) = G_CONSTANT i64 3659    ; LOWER-NEXT: %ashr:_(s64) = G_ASHR %sext_in_reg, %ashr_cst(s64)660    ; LOWER-NEXT: %cmp_rhs:_(s64) = G_SUB %zero, %ashr661    ; LOWER-NEXT: %cmp:_(s32) = G_ICMP intpred(eq), %cmp_lhs(s64), %cmp_rhs662    ; LOWER-NEXT: $w0 = COPY %cmp(s32)663    ; LOWER-NEXT: RET_ReallyLR implicit $w0664    ;665    ; SELECT-LABEL: name: dont_swap_cmn_lhs_when_rhs_more_profitable666    ; SELECT: liveins: $x0, $x1667    ; SELECT-NEXT: {{  $}}668    ; SELECT-NEXT: %zero:gpr64 = COPY $xzr669    ; SELECT-NEXT: %reg0:gpr64 = COPY $x0670    ; SELECT-NEXT: %cmp_lhs:gpr64 = SUBSXrs %zero, %reg0, 63, implicit-def dead $nzcv671    ; SELECT-NEXT: %reg1:gpr64 = COPY $x1672    ; SELECT-NEXT: %sext_in_reg:gpr64 = SBFMXri %reg1, 0, 0673    ; SELECT-NEXT: [[ADDSXrs:%[0-9]+]]:gpr64 = ADDSXrs %cmp_lhs, %sext_in_reg, 131, implicit-def $nzcv674    ; SELECT-NEXT: %cmp:gpr32 = CSINCWr $wzr, $wzr, 1, implicit $nzcv675    ; SELECT-NEXT: $w0 = COPY %cmp676    ; SELECT-NEXT: RET_ReallyLR implicit $w0677    %zero:_(s64) = G_CONSTANT i64 0678 679    %reg0:_(s64) = COPY $x0680    %shl_cst:_(s64) = G_CONSTANT i64 63681    %shl:_(s64) = G_SHL %reg0, %shl_cst(s64)682    %cmp_lhs:_(s64) = G_SUB %zero, %shl683 684    %reg1:_(s64) = COPY $x1685    %sext_in_reg:_(s64) = G_SEXT_INREG %reg1, 1686    %ashr_cst:_(s64) = G_CONSTANT i64 3687    %ashr:_(s64) = G_ASHR %sext_in_reg, %ashr_cst(s64)688    %cmp_rhs:_(s64) = G_SUB %zero, %ashr689 690    %cmp:_(s32) = G_ICMP intpred(eq), %cmp_lhs(s64), %cmp_rhs691    $w0 = COPY %cmp(s32)692    RET_ReallyLR implicit $w0693 694...695---696name:            dont_swap_rhs_with_supported_extend697legalized:       true698tracksRegLiveness: true699body:             |700  bb.0:701    liveins: $x0, $x1702    ; The RHS offers more constant folding opportunities than the LHS.703 704    ; LOWER-LABEL: name: dont_swap_rhs_with_supported_extend705    ; LOWER: liveins: $x0, $x1706    ; LOWER-NEXT: {{  $}}707    ; LOWER-NEXT: %reg0:_(s64) = COPY $x0708    ; LOWER-NEXT: %lhs_cst:_(s64) = G_CONSTANT i64 1709    ; LOWER-NEXT: %cmp_lhs:_(s64) = G_SHL %reg0, %lhs_cst(s64)710    ; LOWER-NEXT: %reg1:_(s64) = COPY $x1711    ; LOWER-NEXT: %and_mask:_(s64) = G_CONSTANT i64 255712    ; LOWER-NEXT: %and:_(s64) = G_AND %reg1, %and_mask713    ; LOWER-NEXT: %rhs_cst:_(s64) = G_CONSTANT i64 1714    ; LOWER-NEXT: %cmp_rhs:_(s64) = G_ASHR %and, %rhs_cst(s64)715    ; LOWER-NEXT: %cmp:_(s32) = G_ICMP intpred(slt), %cmp_lhs(s64), %cmp_rhs716    ; LOWER-NEXT: $w0 = COPY %cmp(s32)717    ; LOWER-NEXT: RET_ReallyLR implicit $w0718    ;719    ; SELECT-LABEL: name: dont_swap_rhs_with_supported_extend720    ; SELECT: liveins: $x0, $x1721    ; SELECT-NEXT: {{  $}}722    ; SELECT-NEXT: %reg0:gpr64 = COPY $x0723    ; SELECT-NEXT: %cmp_lhs:gpr64 = UBFMXri %reg0, 63, 62724    ; SELECT-NEXT: %reg1:gpr64 = COPY $x1725    ; SELECT-NEXT: %and:gpr64common = ANDXri %reg1, 4103726    ; SELECT-NEXT: [[SUBSXrs:%[0-9]+]]:gpr64 = SUBSXrs %cmp_lhs, %and, 129, implicit-def $nzcv727    ; SELECT-NEXT: %cmp:gpr32 = CSINCWr $wzr, $wzr, 10, implicit $nzcv728    ; SELECT-NEXT: $w0 = COPY %cmp729    ; SELECT-NEXT: RET_ReallyLR implicit $w0730    %reg0:_(s64) = COPY $x0731    %lhs_cst:_(s64) = G_CONSTANT i64 1732    %cmp_lhs:_(s64) = G_SHL %reg0, %lhs_cst(s64)733 734    %reg1:_(s64) = COPY $x1735    %and_mask:_(s64) = G_CONSTANT i64 255736    %and:_(s64) = G_AND %reg1, %and_mask(s64)737    %rhs_cst:_(s64) = G_CONSTANT i64 1738    %cmp_rhs:_(s64) = G_ASHR %and, %rhs_cst(s64)739 740    %cmp:_(s32) = G_ICMP intpred(slt), %cmp_lhs(s64), %cmp_rhs741    $w0 = COPY %cmp(s32)742    RET_ReallyLR implicit $w0743 744 745...746---747name:            swap_rhs_with_supported_extend748legalized:       true749tracksRegLiveness: true750body:             |751  bb.0:752    liveins: $x0, $x1753 754    ; In this case, both the LHS and RHS are fed by a supported extend. However,755    ; the LHS' shift has a constant <= 4. This makes it more profitable, so756    ; we should swap the operands.757 758    ; LOWER-LABEL: name: swap_rhs_with_supported_extend759    ; LOWER: liveins: $x0, $x1760    ; LOWER-NEXT: {{  $}}761    ; LOWER-NEXT: %reg0:_(s64) = COPY $x0762    ; LOWER-NEXT: %and_mask:_(s64) = G_CONSTANT i64 255763    ; LOWER-NEXT: %and:_(s64) = G_AND %reg0, %and_mask764    ; LOWER-NEXT: %lhs_cst:_(s64) = G_CONSTANT i64 1765    ; LOWER-NEXT: %cmp_lhs:_(s64) = G_SHL %and, %lhs_cst(s64)766    ; LOWER-NEXT: %rhs_cst:_(s64) = G_CONSTANT i64 5767    ; LOWER-NEXT: %cmp_rhs:_(s64) = G_ASHR %and, %rhs_cst(s64)768    ; LOWER-NEXT: %cmp:_(s32) = G_ICMP intpred(slt), %cmp_rhs(s64), %cmp_lhs769    ; LOWER-NEXT: $w0 = COPY %cmp(s32)770    ; LOWER-NEXT: RET_ReallyLR implicit $w0771    ;772    ; SELECT-LABEL: name: swap_rhs_with_supported_extend773    ; SELECT: liveins: $x0, $x1774    ; SELECT-NEXT: {{  $}}775    ; SELECT-NEXT: %reg0:gpr64 = COPY $x0776    ; SELECT-NEXT: %and:gpr64common = ANDXri %reg0, 4103777    ; SELECT-NEXT: [[COPY:%[0-9]+]]:gpr32all = COPY %reg0.sub_32778    ; SELECT-NEXT: [[COPY1:%[0-9]+]]:gpr32 = COPY [[COPY]]779    ; SELECT-NEXT: %cmp_rhs:gpr64common = SBFMXri %and, 5, 63780    ; SELECT-NEXT: [[SUBSXrx:%[0-9]+]]:gpr64 = SUBSXrx %cmp_rhs, [[COPY1]], 1, implicit-def $nzcv781    ; SELECT-NEXT: %cmp:gpr32 = CSINCWr $wzr, $wzr, 10, implicit $nzcv782    ; SELECT-NEXT: $w0 = COPY %cmp783    ; SELECT-NEXT: RET_ReallyLR implicit $w0784    %reg0:_(s64) = COPY $x0785    %and_mask:_(s64) = G_CONSTANT i64 255786    %and:_(s64) = G_AND %reg0, %and_mask(s64)787 788    %lhs_cst:_(s64) = G_CONSTANT i64 1789    %cmp_lhs:_(s64) = G_SHL %and, %lhs_cst(s64)790 791    %rhs_cst:_(s64) = G_CONSTANT i64 5792    %cmp_rhs:_(s64) = G_ASHR %and, %rhs_cst(s64)793 794    %cmp:_(s32) = G_ICMP intpred(sgt), %cmp_lhs(s64), %cmp_rhs795    $w0 = COPY %cmp(s32)796    RET_ReallyLR implicit $w0797