select_const.ll 19.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 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
; RUN: llc < %s -mtriple=arm-eabi-unknown-unknown | FileCheck %s --check-prefix=ARM
; RUN: llc < %s -mtriple=thumbv6t2-eabi-unknown-unknown | FileCheck %s --check-prefix=THUMB2
; RUN: llc < %s -mtriple=thumb-eabi-unknown-unknown | FileCheck %s --check-prefix=THUMB

; Select of constants: control flow / conditional moves can always be replaced by logic+math (but may not be worth it?).
; Test the zeroext/signext variants of each pattern to see if that makes a difference.

; select Cond, 0, 1 --> zext (!Cond)

define i32 @select_0_or_1(i1 %cond) {
; ARM-LABEL: select_0_or_1:
; ARM:       @ %bb.0:
; ARM-NEXT:    mov r1, #1
; ARM-NEXT:    bic r0, r1, r0
; ARM-NEXT:    mov pc, lr
;
; THUMB2-LABEL: select_0_or_1:
; THUMB2:       @ %bb.0:
; THUMB2-NEXT:    movs r1, #1
; THUMB2-NEXT:    bic.w r0, r1, r0
; THUMB2-NEXT:    bx lr
;
; THUMB-LABEL: select_0_or_1:
; THUMB:       @ %bb.0:
; THUMB-NEXT:    movs r1, #1
; THUMB-NEXT:    bics r1, r0
; THUMB-NEXT:    movs r0, r1
; THUMB-NEXT:    bx lr
  %sel = select i1 %cond, i32 0, i32 1
  ret i32 %sel
}

define i32 @select_0_or_1_zeroext(i1 zeroext %cond) {
; ARM-LABEL: select_0_or_1_zeroext:
; ARM:       @ %bb.0:
; ARM-NEXT:    eor r0, r0, #1
; ARM-NEXT:    mov pc, lr
;
; THUMB2-LABEL: select_0_or_1_zeroext:
; THUMB2:       @ %bb.0:
; THUMB2-NEXT:    eor r0, r0, #1
; THUMB2-NEXT:    bx lr
;
; THUMB-LABEL: select_0_or_1_zeroext:
; THUMB:       @ %bb.0:
; THUMB-NEXT:    movs r1, #1
; THUMB-NEXT:    eors r0, r1
; THUMB-NEXT:    bx lr
  %sel = select i1 %cond, i32 0, i32 1
  ret i32 %sel
}

define i32 @select_0_or_1_signext(i1 signext %cond) {
; ARM-LABEL: select_0_or_1_signext:
; ARM:       @ %bb.0:
; ARM-NEXT:    mov r1, #1
; ARM-NEXT:    bic r0, r1, r0
; ARM-NEXT:    mov pc, lr
;
; THUMB2-LABEL: select_0_or_1_signext:
; THUMB2:       @ %bb.0:
; THUMB2-NEXT:    movs r1, #1
; THUMB2-NEXT:    bic.w r0, r1, r0
; THUMB2-NEXT:    bx lr
;
; THUMB-LABEL: select_0_or_1_signext:
; THUMB:       @ %bb.0:
; THUMB-NEXT:    movs r1, #1
; THUMB-NEXT:    bics r1, r0
; THUMB-NEXT:    movs r0, r1
; THUMB-NEXT:    bx lr
  %sel = select i1 %cond, i32 0, i32 1
  ret i32 %sel
}

; select Cond, 1, 0 --> zext (Cond)

define i32 @select_1_or_0(i1 %cond) {
; ARM-LABEL: select_1_or_0:
; ARM:       @ %bb.0:
; ARM-NEXT:    and r0, r0, #1
; ARM-NEXT:    mov pc, lr
;
; THUMB2-LABEL: select_1_or_0:
; THUMB2:       @ %bb.0:
; THUMB2-NEXT:    and r0, r0, #1
; THUMB2-NEXT:    bx lr
;
; THUMB-LABEL: select_1_or_0:
; THUMB:       @ %bb.0:
; THUMB-NEXT:    movs r1, #1
; THUMB-NEXT:    ands r0, r1
; THUMB-NEXT:    bx lr
  %sel = select i1 %cond, i32 1, i32 0
  ret i32 %sel
}

define i32 @select_1_or_0_zeroext(i1 zeroext %cond) {
; ARM-LABEL: select_1_or_0_zeroext:
; ARM:       @ %bb.0:
; ARM-NEXT:    mov pc, lr
;
; THUMB2-LABEL: select_1_or_0_zeroext:
; THUMB2:       @ %bb.0:
; THUMB2-NEXT:    bx lr
;
; THUMB-LABEL: select_1_or_0_zeroext:
; THUMB:       @ %bb.0:
; THUMB-NEXT:    bx lr
  %sel = select i1 %cond, i32 1, i32 0
  ret i32 %sel
}

define i32 @select_1_or_0_signext(i1 signext %cond) {
; ARM-LABEL: select_1_or_0_signext:
; ARM:       @ %bb.0:
; ARM-NEXT:    and r0, r0, #1
; ARM-NEXT:    mov pc, lr
;
; THUMB2-LABEL: select_1_or_0_signext:
; THUMB2:       @ %bb.0:
; THUMB2-NEXT:    and r0, r0, #1
; THUMB2-NEXT:    bx lr
;
; THUMB-LABEL: select_1_or_0_signext:
; THUMB:       @ %bb.0:
; THUMB-NEXT:    movs r1, #1
; THUMB-NEXT:    ands r0, r1
; THUMB-NEXT:    bx lr
  %sel = select i1 %cond, i32 1, i32 0
  ret i32 %sel
}

; select Cond, 0, -1 --> sext (!Cond)

define i32 @select_0_or_neg1(i1 %cond) {
; ARM-LABEL: select_0_or_neg1:
; ARM:       @ %bb.0:
; ARM-NEXT:    mov r1, #1
; ARM-NEXT:    bic r0, r1, r0
; ARM-NEXT:    rsb r0, r0, #0
; ARM-NEXT:    mov pc, lr
;
; THUMB2-LABEL: select_0_or_neg1:
; THUMB2:       @ %bb.0:
; THUMB2-NEXT:    movs r1, #1
; THUMB2-NEXT:    bic.w r0, r1, r0
; THUMB2-NEXT:    rsbs r0, r0, #0
; THUMB2-NEXT:    bx lr
;
; THUMB-LABEL: select_0_or_neg1:
; THUMB:       @ %bb.0:
; THUMB-NEXT:    movs r1, #1
; THUMB-NEXT:    bics r1, r0
; THUMB-NEXT:    rsbs r0, r1, #0
; THUMB-NEXT:    bx lr
  %sel = select i1 %cond, i32 0, i32 -1
  ret i32 %sel
}

define i32 @select_0_or_neg1_zeroext(i1 zeroext %cond) {
; ARM-LABEL: select_0_or_neg1_zeroext:
; ARM:       @ %bb.0:
; ARM-NEXT:    eor r0, r0, #1
; ARM-NEXT:    rsb r0, r0, #0
; ARM-NEXT:    mov pc, lr
;
; THUMB2-LABEL: select_0_or_neg1_zeroext:
; THUMB2:       @ %bb.0:
; THUMB2-NEXT:    eor r0, r0, #1
; THUMB2-NEXT:    rsbs r0, r0, #0
; THUMB2-NEXT:    bx lr
;
; THUMB-LABEL: select_0_or_neg1_zeroext:
; THUMB:       @ %bb.0:
; THUMB-NEXT:    movs r1, #1
; THUMB-NEXT:    eors r1, r0
; THUMB-NEXT:    rsbs r0, r1, #0
; THUMB-NEXT:    bx lr
  %sel = select i1 %cond, i32 0, i32 -1
  ret i32 %sel
}

define i32 @select_0_or_neg1_signext(i1 signext %cond) {
; ARM-LABEL: select_0_or_neg1_signext:
; ARM:       @ %bb.0:
; ARM-NEXT:    mvn r0, r0
; ARM-NEXT:    mov pc, lr
;
; THUMB2-LABEL: select_0_or_neg1_signext:
; THUMB2:       @ %bb.0:
; THUMB2-NEXT:    mvns r0, r0
; THUMB2-NEXT:    bx lr
;
; THUMB-LABEL: select_0_or_neg1_signext:
; THUMB:       @ %bb.0:
; THUMB-NEXT:    mvns r0, r0
; THUMB-NEXT:    bx lr
  %sel = select i1 %cond, i32 0, i32 -1
  ret i32 %sel
}

define i32 @select_0_or_neg1_alt(i1 %cond) {
; ARM-LABEL: select_0_or_neg1_alt:
; ARM:       @ %bb.0:
; ARM-NEXT:    and r0, r0, #1
; ARM-NEXT:    sub r0, r0, #1
; ARM-NEXT:    mov pc, lr
;
; THUMB2-LABEL: select_0_or_neg1_alt:
; THUMB2:       @ %bb.0:
; THUMB2-NEXT:    and r0, r0, #1
; THUMB2-NEXT:    subs r0, #1
; THUMB2-NEXT:    bx lr
;
; THUMB-LABEL: select_0_or_neg1_alt:
; THUMB:       @ %bb.0:
; THUMB-NEXT:    movs r1, #1
; THUMB-NEXT:    ands r1, r0
; THUMB-NEXT:    subs r0, r1, #1
; THUMB-NEXT:    bx lr
  %z = zext i1 %cond to i32
  %add = add i32 %z, -1
  ret i32 %add
}

define i32 @select_0_or_neg1_alt_zeroext(i1 zeroext %cond) {
; ARM-LABEL: select_0_or_neg1_alt_zeroext:
; ARM:       @ %bb.0:
; ARM-NEXT:    sub r0, r0, #1
; ARM-NEXT:    mov pc, lr
;
; THUMB2-LABEL: select_0_or_neg1_alt_zeroext:
; THUMB2:       @ %bb.0:
; THUMB2-NEXT:    subs r0, #1
; THUMB2-NEXT:    bx lr
;
; THUMB-LABEL: select_0_or_neg1_alt_zeroext:
; THUMB:       @ %bb.0:
; THUMB-NEXT:    subs r0, r0, #1
; THUMB-NEXT:    bx lr
  %z = zext i1 %cond to i32
  %add = add i32 %z, -1
  ret i32 %add
}

define i32 @select_0_or_neg1_alt_signext(i1 signext %cond) {
; ARM-LABEL: select_0_or_neg1_alt_signext:
; ARM:       @ %bb.0:
; ARM-NEXT:    mvn r0, r0
; ARM-NEXT:    mov pc, lr
;
; THUMB2-LABEL: select_0_or_neg1_alt_signext:
; THUMB2:       @ %bb.0:
; THUMB2-NEXT:    mvns r0, r0
; THUMB2-NEXT:    bx lr
;
; THUMB-LABEL: select_0_or_neg1_alt_signext:
; THUMB:       @ %bb.0:
; THUMB-NEXT:    mvns r0, r0
; THUMB-NEXT:    bx lr
  %z = zext i1 %cond to i32
  %add = add i32 %z, -1
  ret i32 %add
}

; select Cond, -1, 0 --> sext (Cond)

define i32 @select_neg1_or_0(i1 %cond) {
; ARM-LABEL: select_neg1_or_0:
; ARM:       @ %bb.0:
; ARM-NEXT:    and r0, r0, #1
; ARM-NEXT:    rsb r0, r0, #0
; ARM-NEXT:    mov pc, lr
;
; THUMB2-LABEL: select_neg1_or_0:
; THUMB2:       @ %bb.0:
; THUMB2-NEXT:    and r0, r0, #1
; THUMB2-NEXT:    rsbs r0, r0, #0
; THUMB2-NEXT:    bx lr
;
; THUMB-LABEL: select_neg1_or_0:
; THUMB:       @ %bb.0:
; THUMB-NEXT:    movs r1, #1
; THUMB-NEXT:    ands r1, r0
; THUMB-NEXT:    rsbs r0, r1, #0
; THUMB-NEXT:    bx lr
  %sel = select i1 %cond, i32 -1, i32 0
  ret i32 %sel
}

define i32 @select_neg1_or_0_zeroext(i1 zeroext %cond) {
; ARM-LABEL: select_neg1_or_0_zeroext:
; ARM:       @ %bb.0:
; ARM-NEXT:    rsb r0, r0, #0
; ARM-NEXT:    mov pc, lr
;
; THUMB2-LABEL: select_neg1_or_0_zeroext:
; THUMB2:       @ %bb.0:
; THUMB2-NEXT:    rsbs r0, r0, #0
; THUMB2-NEXT:    bx lr
;
; THUMB-LABEL: select_neg1_or_0_zeroext:
; THUMB:       @ %bb.0:
; THUMB-NEXT:    rsbs r0, r0, #0
; THUMB-NEXT:    bx lr
  %sel = select i1 %cond, i32 -1, i32 0
  ret i32 %sel
}

define i32 @select_neg1_or_0_signext(i1 signext %cond) {
; ARM-LABEL: select_neg1_or_0_signext:
; ARM:       @ %bb.0:
; ARM-NEXT:    mov pc, lr
;
; THUMB2-LABEL: select_neg1_or_0_signext:
; THUMB2:       @ %bb.0:
; THUMB2-NEXT:    bx lr
;
; THUMB-LABEL: select_neg1_or_0_signext:
; THUMB:       @ %bb.0:
; THUMB-NEXT:    bx lr
  %sel = select i1 %cond, i32 -1, i32 0
  ret i32 %sel
}

; select Cond, C+1, C --> add (zext Cond), C

define i32 @select_Cplus1_C(i1 %cond) {
; ARM-LABEL: select_Cplus1_C:
; ARM:       @ %bb.0:
; ARM-NEXT:    mov r1, #41
; ARM-NEXT:    tst r0, #1
; ARM-NEXT:    movne r1, #42
; ARM-NEXT:    mov r0, r1
; ARM-NEXT:    mov pc, lr
;
; THUMB2-LABEL: select_Cplus1_C:
; THUMB2:       @ %bb.0:
; THUMB2-NEXT:    lsls r0, r0, #31
; THUMB2-NEXT:    mov.w r0, #41
; THUMB2-NEXT:    it ne
; THUMB2-NEXT:    movne r0, #42
; THUMB2-NEXT:    bx lr
;
; THUMB-LABEL: select_Cplus1_C:
; THUMB:       @ %bb.0:
; THUMB-NEXT:    lsls r0, r0, #31
; THUMB-NEXT:    bne .LBB15_2
; THUMB-NEXT:  @ %bb.1:
; THUMB-NEXT:    movs r0, #41
; THUMB-NEXT:    bx lr
; THUMB-NEXT:  .LBB15_2:
; THUMB-NEXT:    movs r0, #42
; THUMB-NEXT:    bx lr
  %sel = select i1 %cond, i32 42, i32 41
  ret i32 %sel
}

define i32 @select_Cplus1_C_zeroext(i1 zeroext %cond) {
; ARM-LABEL: select_Cplus1_C_zeroext:
; ARM:       @ %bb.0:
; ARM-NEXT:    mov r1, #41
; ARM-NEXT:    cmp r0, #0
; ARM-NEXT:    movne r1, #42
; ARM-NEXT:    mov r0, r1
; ARM-NEXT:    mov pc, lr
;
; THUMB2-LABEL: select_Cplus1_C_zeroext:
; THUMB2:       @ %bb.0:
; THUMB2-NEXT:    movs r1, #41
; THUMB2-NEXT:    cmp r0, #0
; THUMB2-NEXT:    it ne
; THUMB2-NEXT:    movne r1, #42
; THUMB2-NEXT:    mov r0, r1
; THUMB2-NEXT:    bx lr
;
; THUMB-LABEL: select_Cplus1_C_zeroext:
; THUMB:       @ %bb.0:
; THUMB-NEXT:    cmp r0, #0
; THUMB-NEXT:    bne .LBB16_2
; THUMB-NEXT:  @ %bb.1:
; THUMB-NEXT:    movs r0, #41
; THUMB-NEXT:    bx lr
; THUMB-NEXT:  .LBB16_2:
; THUMB-NEXT:    movs r0, #42
; THUMB-NEXT:    bx lr
  %sel = select i1 %cond, i32 42, i32 41
  ret i32 %sel
}

define i32 @select_Cplus1_C_signext(i1 signext %cond) {
; ARM-LABEL: select_Cplus1_C_signext:
; ARM:       @ %bb.0:
; ARM-NEXT:    mov r1, #41
; ARM-NEXT:    tst r0, #1
; ARM-NEXT:    movne r1, #42
; ARM-NEXT:    mov r0, r1
; ARM-NEXT:    mov pc, lr
;
; THUMB2-LABEL: select_Cplus1_C_signext:
; THUMB2:       @ %bb.0:
; THUMB2-NEXT:    lsls r0, r0, #31
; THUMB2-NEXT:    mov.w r0, #41
; THUMB2-NEXT:    it ne
; THUMB2-NEXT:    movne r0, #42
; THUMB2-NEXT:    bx lr
;
; THUMB-LABEL: select_Cplus1_C_signext:
; THUMB:       @ %bb.0:
; THUMB-NEXT:    lsls r0, r0, #31
; THUMB-NEXT:    bne .LBB17_2
; THUMB-NEXT:  @ %bb.1:
; THUMB-NEXT:    movs r0, #41
; THUMB-NEXT:    bx lr
; THUMB-NEXT:  .LBB17_2:
; THUMB-NEXT:    movs r0, #42
; THUMB-NEXT:    bx lr
  %sel = select i1 %cond, i32 42, i32 41
  ret i32 %sel
}

; select Cond, C, C+1 --> add (sext Cond), C

define i32 @select_C_Cplus1(i1 %cond) {
; ARM-LABEL: select_C_Cplus1:
; ARM:       @ %bb.0:
; ARM-NEXT:    mov r1, #42
; ARM-NEXT:    tst r0, #1
; ARM-NEXT:    movne r1, #41
; ARM-NEXT:    mov r0, r1
; ARM-NEXT:    mov pc, lr
;
; THUMB2-LABEL: select_C_Cplus1:
; THUMB2:       @ %bb.0:
; THUMB2-NEXT:    lsls r0, r0, #31
; THUMB2-NEXT:    mov.w r0, #42
; THUMB2-NEXT:    it ne
; THUMB2-NEXT:    movne r0, #41
; THUMB2-NEXT:    bx lr
;
; THUMB-LABEL: select_C_Cplus1:
; THUMB:       @ %bb.0:
; THUMB-NEXT:    lsls r0, r0, #31
; THUMB-NEXT:    bne .LBB18_2
; THUMB-NEXT:  @ %bb.1:
; THUMB-NEXT:    movs r0, #42
; THUMB-NEXT:    bx lr
; THUMB-NEXT:  .LBB18_2:
; THUMB-NEXT:    movs r0, #41
; THUMB-NEXT:    bx lr
  %sel = select i1 %cond, i32 41, i32 42
  ret i32 %sel
}

define i32 @select_C_Cplus1_zeroext(i1 zeroext %cond) {
; ARM-LABEL: select_C_Cplus1_zeroext:
; ARM:       @ %bb.0:
; ARM-NEXT:    mov r1, #42
; ARM-NEXT:    cmp r0, #0
; ARM-NEXT:    movne r1, #41
; ARM-NEXT:    mov r0, r1
; ARM-NEXT:    mov pc, lr
;
; THUMB2-LABEL: select_C_Cplus1_zeroext:
; THUMB2:       @ %bb.0:
; THUMB2-NEXT:    movs r1, #42
; THUMB2-NEXT:    cmp r0, #0
; THUMB2-NEXT:    it ne
; THUMB2-NEXT:    movne r1, #41
; THUMB2-NEXT:    mov r0, r1
; THUMB2-NEXT:    bx lr
;
; THUMB-LABEL: select_C_Cplus1_zeroext:
; THUMB:       @ %bb.0:
; THUMB-NEXT:    cmp r0, #0
; THUMB-NEXT:    bne .LBB19_2
; THUMB-NEXT:  @ %bb.1:
; THUMB-NEXT:    movs r0, #42
; THUMB-NEXT:    bx lr
; THUMB-NEXT:  .LBB19_2:
; THUMB-NEXT:    movs r0, #41
; THUMB-NEXT:    bx lr
  %sel = select i1 %cond, i32 41, i32 42
  ret i32 %sel
}

define i32 @select_C_Cplus1_signext(i1 signext %cond) {
; ARM-LABEL: select_C_Cplus1_signext:
; ARM:       @ %bb.0:
; ARM-NEXT:    mov r1, #42
; ARM-NEXT:    tst r0, #1
; ARM-NEXT:    movne r1, #41
; ARM-NEXT:    mov r0, r1
; ARM-NEXT:    mov pc, lr
;
; THUMB2-LABEL: select_C_Cplus1_signext:
; THUMB2:       @ %bb.0:
; THUMB2-NEXT:    lsls r0, r0, #31
; THUMB2-NEXT:    mov.w r0, #42
; THUMB2-NEXT:    it ne
; THUMB2-NEXT:    movne r0, #41
; THUMB2-NEXT:    bx lr
;
; THUMB-LABEL: select_C_Cplus1_signext:
; THUMB:       @ %bb.0:
; THUMB-NEXT:    lsls r0, r0, #31
; THUMB-NEXT:    bne .LBB20_2
; THUMB-NEXT:  @ %bb.1:
; THUMB-NEXT:    movs r0, #42
; THUMB-NEXT:    bx lr
; THUMB-NEXT:  .LBB20_2:
; THUMB-NEXT:    movs r0, #41
; THUMB-NEXT:    bx lr
  %sel = select i1 %cond, i32 41, i32 42
  ret i32 %sel
}

; In general, select of 2 constants could be:
; select Cond, C1, C2 --> add (mul (zext Cond), C1-C2), C2 --> add (and (sext Cond), C1-C2), C2

define i32 @select_C1_C2(i1 %cond) {
; ARM-LABEL: select_C1_C2:
; ARM:       @ %bb.0:
; ARM-NEXT:    mov r1, #165
; ARM-NEXT:    tst r0, #1
; ARM-NEXT:    orr r1, r1, #256
; ARM-NEXT:    moveq r1, #42
; ARM-NEXT:    mov r0, r1
; ARM-NEXT:    mov pc, lr
;
; THUMB2-LABEL: select_C1_C2:
; THUMB2:       @ %bb.0:
; THUMB2-NEXT:    lsls r0, r0, #31
; THUMB2-NEXT:    mov.w r0, #42
; THUMB2-NEXT:    it ne
; THUMB2-NEXT:    movwne r0, #421
; THUMB2-NEXT:    bx lr
;
; THUMB-LABEL: select_C1_C2:
; THUMB:       @ %bb.0:
; THUMB-NEXT:    lsls r0, r0, #31
; THUMB-NEXT:    bne .LBB21_2
; THUMB-NEXT:  @ %bb.1:
; THUMB-NEXT:    movs r0, #42
; THUMB-NEXT:    bx lr
; THUMB-NEXT:  .LBB21_2:
; THUMB-NEXT:    movs r0, #255
; THUMB-NEXT:    adds r0, #166
; THUMB-NEXT:    bx lr
  %sel = select i1 %cond, i32 421, i32 42
  ret i32 %sel
}

define i32 @select_C1_C2_zeroext(i1 zeroext %cond) {
; ARM-LABEL: select_C1_C2_zeroext:
; ARM:       @ %bb.0:
; ARM-NEXT:    mov r1, #165
; ARM-NEXT:    cmp r0, #0
; ARM-NEXT:    orr r1, r1, #256
; ARM-NEXT:    moveq r1, #42
; ARM-NEXT:    mov r0, r1
; ARM-NEXT:    mov pc, lr
;
; THUMB2-LABEL: select_C1_C2_zeroext:
; THUMB2:       @ %bb.0:
; THUMB2-NEXT:    movs r1, #42
; THUMB2-NEXT:    cmp r0, #0
; THUMB2-NEXT:    it ne
; THUMB2-NEXT:    movwne r1, #421
; THUMB2-NEXT:    mov r0, r1
; THUMB2-NEXT:    bx lr
;
; THUMB-LABEL: select_C1_C2_zeroext:
; THUMB:       @ %bb.0:
; THUMB-NEXT:    cmp r0, #0
; THUMB-NEXT:    bne .LBB22_2
; THUMB-NEXT:  @ %bb.1:
; THUMB-NEXT:    movs r0, #42
; THUMB-NEXT:    bx lr
; THUMB-NEXT:  .LBB22_2:
; THUMB-NEXT:    movs r0, #255
; THUMB-NEXT:    adds r0, #166
; THUMB-NEXT:    bx lr
  %sel = select i1 %cond, i32 421, i32 42
  ret i32 %sel
}

define i32 @select_C1_C2_signext(i1 signext %cond) {
; ARM-LABEL: select_C1_C2_signext:
; ARM:       @ %bb.0:
; ARM-NEXT:    mov r1, #165
; ARM-NEXT:    tst r0, #1
; ARM-NEXT:    orr r1, r1, #256
; ARM-NEXT:    moveq r1, #42
; ARM-NEXT:    mov r0, r1
; ARM-NEXT:    mov pc, lr
;
; THUMB2-LABEL: select_C1_C2_signext:
; THUMB2:       @ %bb.0:
; THUMB2-NEXT:    lsls r0, r0, #31
; THUMB2-NEXT:    mov.w r0, #42
; THUMB2-NEXT:    it ne
; THUMB2-NEXT:    movwne r0, #421
; THUMB2-NEXT:    bx lr
;
; THUMB-LABEL: select_C1_C2_signext:
; THUMB:       @ %bb.0:
; THUMB-NEXT:    lsls r0, r0, #31
; THUMB-NEXT:    bne .LBB23_2
; THUMB-NEXT:  @ %bb.1:
; THUMB-NEXT:    movs r0, #42
; THUMB-NEXT:    bx lr
; THUMB-NEXT:  .LBB23_2:
; THUMB-NEXT:    movs r0, #255
; THUMB-NEXT:    adds r0, #166
; THUMB-NEXT:    bx lr
  %sel = select i1 %cond, i32 421, i32 42
  ret i32 %sel
}

; 4295032833 = 0x100010001.
; This becomes an opaque constant via ConstantHoisting, so we don't fold it into the select.

define i64 @opaque_constant1(i1 %cond, i64 %x) {
; ARM-LABEL: opaque_constant1:
; ARM:       @ %bb.0:
; ARM-NEXT:    .save {r4, lr}
; ARM-NEXT:    push {r4, lr}
; ARM-NEXT:    mov lr, #1
; ARM-NEXT:    ands r12, r0, #1
; ARM-NEXT:    mov r0, #23
; ARM-NEXT:    orr lr, lr, #65536
; ARM-NEXT:    mvnne r0, #3
; ARM-NEXT:    and r4, r0, lr
; ARM-NEXT:    movne r12, #1
; ARM-NEXT:    subs r0, r4, #1
; ARM-NEXT:    eor r2, r2, lr
; ARM-NEXT:    eor r3, r3, #1
; ARM-NEXT:    sbc r1, r12, #0
; ARM-NEXT:    orrs r2, r2, r3
; ARM-NEXT:    movne r0, r4
; ARM-NEXT:    movne r1, r12
; ARM-NEXT:    pop {r4, lr}
; ARM-NEXT:    mov pc, lr
;
; THUMB2-LABEL: opaque_constant1:
; THUMB2:       @ %bb.0:
; THUMB2-NEXT:    .save {r7, lr}
; THUMB2-NEXT:    push {r7, lr}
; THUMB2-NEXT:    ands r12, r0, #1
; THUMB2-NEXT:    mov.w lr, #1
; THUMB2-NEXT:    itt ne
; THUMB2-NEXT:    movne.w lr, #65536
; THUMB2-NEXT:    movne.w r12, #1
; THUMB2-NEXT:    subs.w r0, lr, #1
; THUMB2-NEXT:    sbc r1, r12, #0
; THUMB2-NEXT:    eor r3, r3, #1
; THUMB2-NEXT:    eor r2, r2, #65537
; THUMB2-NEXT:    orrs r2, r3
; THUMB2-NEXT:    itt ne
; THUMB2-NEXT:    movne r0, lr
; THUMB2-NEXT:    movne r1, r12
; THUMB2-NEXT:    pop {r7, pc}
;
; THUMB-LABEL: opaque_constant1:
; THUMB:       @ %bb.0:
; THUMB-NEXT:    .save {r4, r5, r6, r7, lr}
; THUMB-NEXT:    push {r4, r5, r6, r7, lr}
; THUMB-NEXT:    movs r7, #1
; THUMB-NEXT:    ands r0, r7
; THUMB-NEXT:    subs r1, r0, #1
; THUMB-NEXT:    push {r0}
; THUMB-NEXT:    pop {r4}
; THUMB-NEXT:    sbcs r4, r1
; THUMB-NEXT:    cmp r0, #0
; THUMB-NEXT:    bne .LBB24_2
; THUMB-NEXT:  @ %bb.1:
; THUMB-NEXT:    movs r5, #23
; THUMB-NEXT:    b .LBB24_3
; THUMB-NEXT:  .LBB24_2:
; THUMB-NEXT:    movs r0, #3
; THUMB-NEXT:    mvns r5, r0
; THUMB-NEXT:  .LBB24_3:
; THUMB-NEXT:    ldr r0, .LCPI24_0
; THUMB-NEXT:    ands r5, r0
; THUMB-NEXT:    movs r6, #0
; THUMB-NEXT:    subs r0, r5, #1
; THUMB-NEXT:    push {r4}
; THUMB-NEXT:    pop {r1}
; THUMB-NEXT:    sbcs r1, r6
; THUMB-NEXT:    eors r3, r7
; THUMB-NEXT:    ldr r6, .LCPI24_0
; THUMB-NEXT:    eors r2, r6
; THUMB-NEXT:    orrs r2, r3
; THUMB-NEXT:    beq .LBB24_5
; THUMB-NEXT:  @ %bb.4:
; THUMB-NEXT:    movs r1, r4
; THUMB-NEXT:  .LBB24_5:
; THUMB-NEXT:    cmp r2, #0
; THUMB-NEXT:    beq .LBB24_7
; THUMB-NEXT:  @ %bb.6:
; THUMB-NEXT:    movs r0, r5
; THUMB-NEXT:  .LBB24_7:
; THUMB-NEXT:    pop {r4, r5, r6, r7}
; THUMB-NEXT:    pop {r2}
; THUMB-NEXT:    bx r2
; THUMB-NEXT:    .p2align 2
; THUMB-NEXT:  @ %bb.8:
; THUMB-NEXT:  .LCPI24_0:
; THUMB-NEXT:    .long 65537 @ 0x10001
  %sel = select i1 %cond, i64 -4, i64 23
  %bo = and i64 %sel, 4295032833  ; 0x100010001
  %cmp = icmp eq i64 %x, 4295032833
  %sext = sext i1 %cmp to i64
  %add = add i64 %bo, %sext
  ret i64 %add
}

; 65537 == 0x10001.
; This becomes an opaque constant via ConstantHoisting, so we don't fold it into the select.

define i64 @opaque_constant2(i1 %cond, i64 %x) {
; ARM-LABEL: opaque_constant2:
; ARM:       @ %bb.0:
; ARM-NEXT:    mov r1, #1
; ARM-NEXT:    tst r0, #1
; ARM-NEXT:    orr r1, r1, #65536
; ARM-NEXT:    moveq r1, #23
; ARM-NEXT:    bic r0, r1, #22
; ARM-NEXT:    mov r1, #0
; ARM-NEXT:    mov pc, lr
;
; THUMB2-LABEL: opaque_constant2:
; THUMB2:       @ %bb.0:
; THUMB2-NEXT:    lsls r0, r0, #31
; THUMB2-NEXT:    mov.w r1, #0
; THUMB2-NEXT:    mov.w r0, #1
; THUMB2-NEXT:    it ne
; THUMB2-NEXT:    movne.w r0, #65537
; THUMB2-NEXT:    bx lr
;
; THUMB-LABEL: opaque_constant2:
; THUMB:       @ %bb.0:
; THUMB-NEXT:    lsls r0, r0, #31
; THUMB-NEXT:    bne .LBB25_2
; THUMB-NEXT:  @ %bb.1:
; THUMB-NEXT:    movs r0, #23
; THUMB-NEXT:    b .LBB25_3
; THUMB-NEXT:  .LBB25_2:
; THUMB-NEXT:    ldr r0, .LCPI25_0
; THUMB-NEXT:  .LBB25_3:
; THUMB-NEXT:    movs r1, #22
; THUMB-NEXT:    bics r0, r1
; THUMB-NEXT:    movs r1, #0
; THUMB-NEXT:    bx lr
; THUMB-NEXT:    .p2align 2
; THUMB-NEXT:  @ %bb.4:
; THUMB-NEXT:  .LCPI25_0:
; THUMB-NEXT:    .long 65537 @ 0x10001
  %sel = select i1 %cond, i64 65537, i64 23
  %bo = and i64 %sel, 65537
  ret i64 %bo
}