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 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205
|
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -passes=instsimplify -S | FileCheck %s
define i32 @test1(i32 %A) {
; CHECK-LABEL: @test1(
; CHECK-NEXT: ret i32 [[A:%.*]]
;
%B = or i32 %A, 0
ret i32 %B
}
define i32 @all_ones(i32 %A) {
; CHECK-LABEL: @all_ones(
; CHECK-NEXT: ret i32 -1
;
%B = or i32 %A, -1
ret i32 %B
}
define <3 x i8> @all_ones_vec_with_poison_elt(<3 x i8> %A) {
; CHECK-LABEL: @all_ones_vec_with_poison_elt(
; CHECK-NEXT: ret <3 x i8> <i8 -1, i8 -1, i8 -1>
;
%B = or <3 x i8> %A, <i8 -1, i8 poison, i8 -1>
ret <3 x i8> %B
}
define i1 @test3(i1 %A) {
; CHECK-LABEL: @test3(
; CHECK-NEXT: ret i1 [[A:%.*]]
;
%B = or i1 %A, false
ret i1 %B
}
define i1 @test4(i1 %A) {
; CHECK-LABEL: @test4(
; CHECK-NEXT: ret i1 true
;
%B = or i1 %A, true
ret i1 %B
}
define i1 @test5(i1 %A) {
; CHECK-LABEL: @test5(
; CHECK-NEXT: ret i1 [[A:%.*]]
;
%B = or i1 %A, %A
ret i1 %B
}
define i32 @test6(i32 %A) {
; CHECK-LABEL: @test6(
; CHECK-NEXT: ret i32 [[A:%.*]]
;
%B = or i32 %A, %A
ret i32 %B
}
; A | ~A == -1
define i32 @or_not(i32 %A) {
; CHECK-LABEL: @or_not(
; CHECK-NEXT: ret i32 -1
;
%NotA = xor i32 %A, -1
%B = or i32 %A, %NotA
ret i32 %B
}
define <2 x i4> @or_not_commute_vec_poison(<2 x i4> %A) {
; CHECK-LABEL: @or_not_commute_vec_poison(
; CHECK-NEXT: ret <2 x i4> <i4 -1, i4 -1>
;
%NotA = xor <2 x i4> %A, <i4 -1, i4 poison>
%B = or <2 x i4> %NotA, %A
ret <2 x i4> %B
}
define i8 @test8(i8 %A) {
; CHECK-LABEL: @test8(
; CHECK-NEXT: ret i8 -1
;
%B = or i8 %A, -2
%C = or i8 %B, 1
ret i8 %C
}
; Test that (A|c1)|(B|c2) == (A|B)|(c1|c2)
define i8 @test9(i8 %A, i8 %B) {
; CHECK-LABEL: @test9(
; CHECK-NEXT: ret i8 -1
;
%C = or i8 %A, 1
%D = or i8 %B, -2
%E = or i8 %C, %D
ret i8 %E
}
; (X & C1) | C2 --> (X | C2) & (C1|C2)
define i8 @test10(i8 %A) {
; CHECK-LABEL: @test10(
; CHECK-NEXT: ret i8 -2
;
%B = or i8 %A, 1
%C = and i8 %B, -2
%D = or i8 %C, -2
ret i8 %D
}
; The following two cases only get folded by InstCombine,
; see InstCombine/or-xor.ll.
; (X ^ C1) | C2 --> (X | C2) ^ (C1&~C2)
define i8 @test11(i8 %A) {
; CHECK-LABEL: @test11(
; CHECK-NEXT: [[B:%.*]] = or i8 [[A:%.*]], -2
; CHECK-NEXT: [[C:%.*]] = xor i8 [[B]], 13
; CHECK-NEXT: [[D:%.*]] = or i8 [[C]], 1
; CHECK-NEXT: [[E:%.*]] = xor i8 [[D]], 12
; CHECK-NEXT: ret i8 [[E]]
;
%B = or i8 %A, -2
%C = xor i8 %B, 13
%D = or i8 %C, 1
%E = xor i8 %D, 12
ret i8 %E
}
define i8 @test11v(<2 x i8> %A) {
; CHECK-LABEL: @test11v(
; CHECK-NEXT: [[B:%.*]] = or <2 x i8> [[A:%.*]], <i8 -2, i8 0>
; CHECK-NEXT: [[CV:%.*]] = xor <2 x i8> [[B]], <i8 13, i8 13>
; CHECK-NEXT: [[C:%.*]] = extractelement <2 x i8> [[CV]], i32 0
; CHECK-NEXT: [[D:%.*]] = or i8 [[C]], 1
; CHECK-NEXT: [[E:%.*]] = xor i8 [[D]], 12
; CHECK-NEXT: ret i8 [[E]]
;
%B = or <2 x i8> %A, <i8 -2, i8 0>
%CV = xor <2 x i8> %B, <i8 13, i8 13>
%C = extractelement <2 x i8> %CV, i32 0
%D = or i8 %C, 1
%E = xor i8 %D, 12
ret i8 %E
}
; Test the case where integer BitWidth <= 64 && BitWidth % 2 != 0.
; If we have: ((V + N) & C1) | (V & C2)
; .. and C2 = ~C1 and C2 is 0+1+ and (N & C2) == 0
; replace with V+N.
define i39 @test1_apint(i39 %V, i39 %M) {
; CHECK-LABEL: @test1_apint(
; CHECK-NEXT: [[N:%.*]] = and i39 [[M:%.*]], -274877906944
; CHECK-NEXT: [[A:%.*]] = add i39 [[V:%.*]], [[N]]
; CHECK-NEXT: ret i39 [[A]]
;
%C1 = xor i39 274877906943, -1 ;; C2 = 274877906943
%N = and i39 %M, 274877906944
%A = add i39 %V, %N
%B = and i39 %A, %C1
%D = and i39 %V, 274877906943
%R = or i39 %B, %D
ret i39 %R
}
define i7 @test2_apint(i7 %X) {
; CHECK-LABEL: @test2_apint(
; CHECK-NEXT: ret i7 [[X:%.*]]
;
%Y = or i7 %X, 0
ret i7 %Y
}
define i17 @test3_apint(i17 %X) {
; CHECK-LABEL: @test3_apint(
; CHECK-NEXT: ret i17 -1
;
%Y = or i17 %X, -1
ret i17 %Y
}
; Test the case where Integer BitWidth > 64 && BitWidth <= 1024.
; If we have: ((V + N) & C1) | (V & C2)
; .. and C2 = ~C1 and C2 is 0+1+ and (N & C2) == 0
; replace with V+N.
define i399 @test4_apint(i399 %V, i399 %M) {
; CHECK-LABEL: @test4_apint(
; CHECK-NEXT: [[N:%.*]] = and i399 [[M:%.*]], 18446742974197923840
; CHECK-NEXT: [[A:%.*]] = add i399 [[V:%.*]], [[N]]
; CHECK-NEXT: ret i399 [[A]]
;
%C1 = xor i399 274877906943, -1 ;; C2 = 274877906943
%N = and i399 %M, 18446742974197923840
%A = add i399 %V, %N
%B = and i399 %A, %C1
%D = and i399 %V, 274877906943
%R = or i399 %D, %B
ret i399 %R
}
define i777 @test5_apint(i777 %X) {
; CHECK-LABEL: @test5_apint(
; CHECK-NEXT: ret i777 [[X:%.*]]
;
%Y = or i777 %X, 0
ret i777 %Y
}
define i117 @test6_apint(i117 %X) {
; CHECK-LABEL: @test6_apint(
; CHECK-NEXT: ret i117 -1
;
%Y = or i117 %X, -1
ret i117 %Y
}
; Test the case where integer BitWidth <= 64 && BitWidth % 2 != 0.
; Vector version of test1_apint with the add commuted
; If we have: ((V + N) & C1) | (V & C2)
; .. and C2 = ~C1 and C2 is 0+1+ and (N & C2) == 0
; replace with V+N.
define <2 x i39> @test7_apint(<2 x i39> %V, <2 x i39> %M) {
; CHECK-LABEL: @test7_apint(
; CHECK-NEXT: [[N:%.*]] = and <2 x i39> [[M:%.*]], <i39 -274877906944, i39 -274877906944>
; CHECK-NEXT: [[A:%.*]] = add <2 x i39> [[N]], [[V:%.*]]
; CHECK-NEXT: ret <2 x i39> [[A]]
;
%C1 = xor <2 x i39> <i39 274877906943, i39 274877906943>, <i39 -1, i39 -1> ;; C2 = 274877906943
%N = and <2 x i39> %M, <i39 274877906944, i39 274877906944>
%A = add <2 x i39> %N, %V
%B = and <2 x i39> %A, %C1
%D = and <2 x i39> %V, <i39 274877906943, i39 274877906943>
%R = or <2 x i39> %B, %D
ret <2 x i39> %R
}
; Test the case where Integer BitWidth > 64 && BitWidth <= 1024.
; Vector version of test4_apint with the add and the or commuted
; If we have: ((V + N) & C1) | (V & C2)
; .. and C2 = ~C1 and C2 is 0+1+ and (N & C2) == 0
; replace with V+N.
define <2 x i399> @test8_apint(<2 x i399> %V, <2 x i399> %M) {
; CHECK-LABEL: @test8_apint(
; CHECK-NEXT: [[N:%.*]] = and <2 x i399> [[M:%.*]], <i399 18446742974197923840, i399 18446742974197923840>
; CHECK-NEXT: [[A:%.*]] = add <2 x i399> [[N]], [[V:%.*]]
; CHECK-NEXT: ret <2 x i399> [[A]]
;
%C1 = xor <2 x i399> <i399 274877906943, i399 274877906943>, <i399 -1, i399 -1> ;; C2 = 274877906943
%N = and <2 x i399> %M, <i399 18446742974197923840, i399 18446742974197923840>
%A = add <2 x i399> %N, %V
%B = and <2 x i399> %A, %C1
%D = and <2 x i399> %V, <i399 274877906943, i399 274877906943>
%R = or <2 x i399> %D, %B
ret <2 x i399> %R
}
; (A & B) | A = A
define i8 @or_and_common_op_commute0(i8 %a, i8 %b) {
; CHECK-LABEL: @or_and_common_op_commute0(
; CHECK-NEXT: ret i8 [[A:%.*]]
;
%and = and i8 %a, %b
%or = or i8 %and, %a
ret i8 %or
}
define <2 x i8> @or_and_common_op_commute1(<2 x i8> %a, <2 x i8> %b) {
; CHECK-LABEL: @or_and_common_op_commute1(
; CHECK-NEXT: ret <2 x i8> [[A:%.*]]
;
%and = and <2 x i8> %b, %a
%or = or <2 x i8> %and, %a
ret <2 x i8> %or
}
define i8 @or_and_common_op_commute2(i8 %a, i8 %b) {
; CHECK-LABEL: @or_and_common_op_commute2(
; CHECK-NEXT: ret i8 [[A:%.*]]
;
%and = and i8 %a, %b
%or = or i8 %a, %and
ret i8 %or
}
define <2 x i8> @or_and_common_op_commute3(<2 x i8> %a, <2 x i8> %b) {
; CHECK-LABEL: @or_and_common_op_commute3(
; CHECK-NEXT: ret <2 x i8> [[A:%.*]]
;
%and = and <2 x i8> %b, %a
%or = or <2 x i8> %a, %and
ret <2 x i8> %or
}
; A | ~(A & B) = -1
define i1 @or_with_not_op_commute1(i1 %a, i1 %b) {
; CHECK-LABEL: @or_with_not_op_commute1(
; CHECK-NEXT: ret i1 true
;
%ab = and i1 %a, %b
%not = xor i1 %ab, -1
%r = or i1 %a, %not
ret i1 %r
}
; A | ~(B & A) = -1
define i8 @or_with_not_op_commute2(i8 %a, i8 %b) {
; CHECK-LABEL: @or_with_not_op_commute2(
; CHECK-NEXT: ret i8 -1
;
%ab = and i8 %b, %a
%not = xor i8 %ab, -1
%r = or i8 %a, %not
ret i8 %r
}
; ~(A & B) | A = -1
define <3 x i17> @or_with_not_op_commute3(<3 x i17> %a, <3 x i17> %b) {
; CHECK-LABEL: @or_with_not_op_commute3(
; CHECK-NEXT: ret <3 x i17> <i17 -1, i17 -1, i17 -1>
;
%ab = and <3 x i17> %a, %b
%not = xor <3 x i17> %ab, <i17 -1, i17 -1, i17 -1>
%r = or <3 x i17> %not, %a
ret <3 x i17> %r
}
; ~(B & A) | A = -1
define <2 x i1> @or_with_not_op_commute4(<2 x i1> %a, <2 x i1> %b) {
; CHECK-LABEL: @or_with_not_op_commute4(
; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true>
;
%ab = and <2 x i1> %b, %a
%not = xor <2 x i1> %ab, <i1 -1, i1 poison>
%r = or <2 x i1> %not, %a
ret <2 x i1> %r
}
define i32 @poison(i32 %x) {
; CHECK-LABEL: @poison(
; CHECK-NEXT: ret i32 poison
;
%v = or i32 %x, poison
ret i32 %v
}
; (~A & B) | ~(A | B) --> ~A
define i4 @and_or_not_or_commute0(i4 %A, i4 %B) {
; CHECK-LABEL: @and_or_not_or_commute0(
; CHECK-NEXT: [[NOTA:%.*]] = xor i4 [[A:%.*]], -1
; CHECK-NEXT: ret i4 [[NOTA]]
;
%nota = xor i4 %A, -1
%and = and i4 %nota, %B
%or = or i4 %A, %B
%notab = xor i4 %or, -1
%r = or i4 %and, %notab
ret i4 %r
}
define i41 @and_or_not_or_commute1(i41 %A, i41 %B) {
; CHECK-LABEL: @and_or_not_or_commute1(
; CHECK-NEXT: [[NOTA:%.*]] = xor i41 [[A:%.*]], -1
; CHECK-NEXT: ret i41 [[NOTA]]
;
%nota = xor i41 %A, -1
%and = and i41 %B, %nota
%or = or i41 %A, %B
%notab = xor i41 %or, -1
%r = or i41 %and, %notab
ret i41 %r
}
define i8 @and_or_not_or_commute2(i8 %A, i8 %B) {
; CHECK-LABEL: @and_or_not_or_commute2(
; CHECK-NEXT: [[NOTA:%.*]] = xor i8 [[A:%.*]], -1
; CHECK-NEXT: ret i8 [[NOTA]]
;
%nota = xor i8 %A, -1
%and = and i8 %nota, %B
%or = or i8 %B, %A
%notab = xor i8 %or, -1
%r = or i8 %and, %notab
ret i8 %r
}
define <2 x i4> @and_or_not_or_commute3(<2 x i4> %A, <2 x i4> %B) {
; CHECK-LABEL: @and_or_not_or_commute3(
; CHECK-NEXT: [[NOTA:%.*]] = xor <2 x i4> [[A:%.*]], <i4 -1, i4 -1>
; CHECK-NEXT: ret <2 x i4> [[NOTA]]
;
%nota = xor <2 x i4> %A, <i4 -1, i4 -1>
%and = and <2 x i4> %B, %nota
%or = or <2 x i4> %B, %A
%notab = xor <2 x i4> %or, <i4 -1, i4 -1>
%r = or <2 x i4> %and, %notab
ret <2 x i4> %r
}
define i4 @and_or_not_or_commute4(i4 %A, i4 %B) {
; CHECK-LABEL: @and_or_not_or_commute4(
; CHECK-NEXT: [[NOTA:%.*]] = xor i4 [[A:%.*]], -1
; CHECK-NEXT: ret i4 [[NOTA]]
;
%nota = xor i4 %A, -1
%and = and i4 %nota, %B
%or = or i4 %A, %B
%notab = xor i4 %or, -1
%r = or i4 %notab, %and
ret i4 %r
}
define i41 @and_or_not_or_commute5(i41 %A, i41 %B) {
; CHECK-LABEL: @and_or_not_or_commute5(
; CHECK-NEXT: [[NOTA:%.*]] = xor i41 [[A:%.*]], -1
; CHECK-NEXT: ret i41 [[NOTA]]
;
%nota = xor i41 %A, -1
%and = and i41 %B, %nota
%or = or i41 %A, %B
%notab = xor i41 %or, -1
%r = or i41 %notab, %and
ret i41 %r
}
define i8 @and_or_not_or_commute6(i8 %A, i8 %B) {
; CHECK-LABEL: @and_or_not_or_commute6(
; CHECK-NEXT: [[NOTA:%.*]] = xor i8 [[A:%.*]], -1
; CHECK-NEXT: ret i8 [[NOTA]]
;
%nota = xor i8 %A, -1
%and = and i8 %nota, %B
%or = or i8 %B, %A
%notab = xor i8 %or, -1
%r = or i8 %notab, %and
ret i8 %r
}
define <2 x i4> @and_or_not_or_commute7(<2 x i4> %A, <2 x i4> %B) {
; CHECK-LABEL: @and_or_not_or_commute7(
; CHECK-NEXT: [[NOTA:%.*]] = xor <2 x i4> [[A:%.*]], <i4 -1, i4 -1>
; CHECK-NEXT: ret <2 x i4> [[NOTA]]
;
%nota = xor <2 x i4> %A, <i4 -1, i4 -1>
%and = and <2 x i4> %B, %nota
%or = or <2 x i4> %B, %A
%notab = xor <2 x i4> %or, <i4 -1, i4 -1>
%r = or <2 x i4> %notab, %and
ret <2 x i4> %r
}
; (~A & B) | ~(A | B) --> ~A with logical and
define i1 @and_or_not_or_logical(i1 %A, i1 %B) {
; CHECK-LABEL: @and_or_not_or_logical(
; CHECK-NEXT: [[V:%.*]] = xor i1 [[A:%.*]], true
; CHECK-NEXT: ret i1 [[V]]
;
%V = xor i1 %A, true
%X = select i1 %V, i1 %B, i1 false
%W = or i1 %B, %A
%Y = xor i1 %W, true
%Z = or i1 %X, %Y
ret i1 %Z
}
; (~B & A) | ~(A | B) --> ~A with logical and
define i1 @and_or_not_or_logical_rev(i1 %A, i1 %B) {
; CHECK-LABEL: @and_or_not_or_logical_rev(
; CHECK-NEXT: [[V:%.*]] = xor i1 [[A:%.*]], true
; CHECK-NEXT: ret i1 [[V]]
;
%V = xor i1 %A, true
%X = select i1 %B, i1 %V, i1 false
%W = or i1 %B, %A
%Y = xor i1 %W, true
%Z = or i1 %X, %Y
ret i1 %Z
}
; (~A & B) | ~(A | B) --> ~A with logical And and logical Or
define i1 @and_or_not_logical_or_logical_rev(i1 %A, i1 %B) {
; CHECK-LABEL: @and_or_not_logical_or_logical_rev(
; CHECK-NEXT: [[V:%.*]] = xor i1 [[A:%.*]], true
; CHECK-NEXT: ret i1 [[V]]
;
%V = xor i1 %A, true
%X = select i1 %B, i1 %V, i1 false
%W = select i1 %B, i1 true, i1 %A
%Y = xor i1 %W, true
%Z = or i1 %X, %Y
ret i1 %Z
}
; negative test - It is not safe to propagate an undef element from the 'not' op.
define <2 x i4> @and_or_not_or_commute7_undef_elt(<2 x i4> %A, <2 x i4> %B) {
; CHECK-LABEL: @and_or_not_or_commute7_undef_elt(
; CHECK-NEXT: [[NOTA:%.*]] = xor <2 x i4> [[A:%.*]], <i4 undef, i4 -1>
; CHECK-NEXT: [[AND:%.*]] = and <2 x i4> [[B:%.*]], [[NOTA]]
; CHECK-NEXT: [[OR:%.*]] = or <2 x i4> [[B]], [[A]]
; CHECK-NEXT: [[NOTAB:%.*]] = xor <2 x i4> [[OR]], <i4 -1, i4 -1>
; CHECK-NEXT: [[R:%.*]] = or <2 x i4> [[NOTAB]], [[AND]]
; CHECK-NEXT: ret <2 x i4> [[R]]
;
%nota = xor <2 x i4> %A, <i4 undef, i4 -1>
%and = and <2 x i4> %B, %nota
%or = or <2 x i4> %B, %A
%notab = xor <2 x i4> %or, <i4 -1, i4 -1>
%r = or <2 x i4> %notab, %and
ret <2 x i4> %r
}
; doing the same with poison is safe.
define <2 x i4> @and_or_not_or_commute7_poison_elt(<2 x i4> %A, <2 x i4> %B) {
; CHECK-LABEL: @and_or_not_or_commute7_poison_elt(
; CHECK-NEXT: [[NOTA:%.*]] = xor <2 x i4> [[A:%.*]], <i4 poison, i4 -1>
; CHECK-NEXT: ret <2 x i4> [[NOTA]]
;
%nota = xor <2 x i4> %A, <i4 poison, i4 -1>
%and = and <2 x i4> %B, %nota
%or = or <2 x i4> %B, %A
%notab = xor <2 x i4> %or, <i4 -1, i4 -1>
%r = or <2 x i4> %notab, %and
ret <2 x i4> %r
}
; (A | B) | (A ^ B) --> A | B
define i69 @or_or_xor(i69 %A, i69 %B) {
; CHECK-LABEL: @or_or_xor(
; CHECK-NEXT: [[I1:%.*]] = or i69 [[A:%.*]], [[B:%.*]]
; CHECK-NEXT: ret i69 [[I1]]
;
%i1 = or i69 %A, %B
%i2 = xor i69 %A, %B
%i3 = or i69 %i1, %i2
ret i69 %i3
}
; (B | A) | (A ^ B) --> B | A
define i8 @or_or_xor_inner_or_commuted(i8 %A, i8 %B) {
; CHECK-LABEL: @or_or_xor_inner_or_commuted(
; CHECK-NEXT: [[I1:%.*]] = or i8 [[B:%.*]], [[A:%.*]]
; CHECK-NEXT: ret i8 [[I1]]
;
%i1 = or i8 %B, %A
%i2 = xor i8 %A, %B
%i3 = or i8 %i1, %i2
ret i8 %i3
}
; (A ^ B) | (A | B) --> A | B
define <4 x i4> @or_or_xor_commuted(<4 x i4> %A, <4 x i4> %B) {
; CHECK-LABEL: @or_or_xor_commuted(
; CHECK-NEXT: [[I1:%.*]] = or <4 x i4> [[A:%.*]], [[B:%.*]]
; CHECK-NEXT: ret <4 x i4> [[I1]]
;
%i1 = or <4 x i4> %A, %B
%i2 = xor <4 x i4> %A, %B
%i3 = or <4 x i4> %i2, %i1
ret <4 x i4> %i3
}
; (A ^ B) | (B | A) --> B | A
define i4 @or_or_xor_inner_or_outer_or_commuted(i4 %A, i4 %B) {
; CHECK-LABEL: @or_or_xor_inner_or_outer_or_commuted(
; CHECK-NEXT: [[I1:%.*]] = or i4 [[B:%.*]], [[A:%.*]]
; CHECK-NEXT: ret i4 [[I1]]
;
%i1 = or i4 %B, %A
%i2 = xor i4 %A, %B
%i3 = or i4 %i2, %i1
ret i4 %i3
}
define i32 @shifted_all_ones(i32 %shamt) {
; CHECK-LABEL: @shifted_all_ones(
; CHECK-NEXT: ret i32 -1
;
%r = lshr i32 -1, %shamt
%s = sub i32 32, %shamt
%l = shl i32 -1, %s
%o = or i32 %r, %l
ret i32 %o
}
; Sub from less than bitwidth is ok (overlapping ones).
define i32 @shifted_all_ones_commute(i32 %shamt) {
; CHECK-LABEL: @shifted_all_ones_commute(
; CHECK-NEXT: ret i32 -1
;
%r = lshr i32 -1, %shamt
%s = sub i32 31, %shamt
%l = shl i32 -1, %s
%o = or i32 %l, %r
ret i32 %o
}
define <2 x i9> @shifted_all_ones_sub_on_lshr(<2 x i9> %shamt) {
; CHECK-LABEL: @shifted_all_ones_sub_on_lshr(
; CHECK-NEXT: ret <2 x i9> <i9 -1, i9 -1>
;
%l = shl <2 x i9> <i9 -1, i9 -1>, %shamt
%s = sub <2 x i9> <i9 5, i9 5>, %shamt
%r = lshr <2 x i9> <i9 -1, i9 -1>, %s
%o = or <2 x i9> %l, %r
ret <2 x i9> %o
}
define i8 @shifted_all_ones_sub_on_lshr_commute(i8 %shamt) {
; CHECK-LABEL: @shifted_all_ones_sub_on_lshr_commute(
; CHECK-NEXT: ret i8 -1
;
%l = shl i8 -1, %shamt
%s = sub i8 8, %shamt
%r = lshr i8 -1, %s
%o = or i8 %r, %l
ret i8 %o
}
; negative test - need -1 in general case
define i32 @shifted_not_all_ones(i32 %shamt) {
; CHECK-LABEL: @shifted_not_all_ones(
; CHECK-NEXT: [[R:%.*]] = lshr i32 -2, [[SHAMT:%.*]]
; CHECK-NEXT: [[S:%.*]] = sub i32 31, [[SHAMT]]
; CHECK-NEXT: [[L:%.*]] = shl i32 -1, [[S]]
; CHECK-NEXT: [[O:%.*]] = or i32 [[R]], [[L]]
; CHECK-NEXT: ret i32 [[O]]
;
%r = lshr i32 -2, %shamt
%s = sub i32 31, %shamt
%l = shl i32 -1, %s
%o = or i32 %r, %l
ret i32 %o
}
; negative test - opposite shift amount may be too big
define i32 @shifted_all_ones_greater_than_bitwidth(i32 %shamt) {
; CHECK-LABEL: @shifted_all_ones_greater_than_bitwidth(
; CHECK-NEXT: [[R:%.*]] = lshr i32 -1, [[SHAMT:%.*]]
; CHECK-NEXT: [[S:%.*]] = sub i32 33, [[SHAMT]]
; CHECK-NEXT: [[L:%.*]] = shl i32 -1, [[S]]
; CHECK-NEXT: [[O:%.*]] = or i32 [[R]], [[L]]
; CHECK-NEXT: ret i32 [[O]]
;
%r = lshr i32 -1, %shamt
%s = sub i32 33, %shamt
%l = shl i32 -1, %s
%o = or i32 %r, %l
ret i32 %o
}
; negative test - shift amount must be derived from same base
define i32 @shifted_all_ones_not_same_amt(i32 %shamt, i32 %other) {
; CHECK-LABEL: @shifted_all_ones_not_same_amt(
; CHECK-NEXT: [[R:%.*]] = lshr i32 -1, [[SHAMT:%.*]]
; CHECK-NEXT: [[S:%.*]] = sub i32 32, [[OTHER:%.*]]
; CHECK-NEXT: [[L:%.*]] = shl i32 -1, [[S]]
; CHECK-NEXT: [[O:%.*]] = or i32 [[R]], [[L]]
; CHECK-NEXT: ret i32 [[O]]
;
%r = lshr i32 -1, %shamt
%s = sub i32 32, %other
%l = shl i32 -1, %s
%o = or i32 %r, %l
ret i32 %o
}
; (A & B) | ~(A ^ B) --> ~(A ^ B)
define i4 @or_nxor_and_commute0(i4 %a, i4 %b) {
; CHECK-LABEL: @or_nxor_and_commute0(
; CHECK-NEXT: [[XOR:%.*]] = xor i4 [[A:%.*]], [[B:%.*]]
; CHECK-NEXT: [[NOT:%.*]] = xor i4 [[XOR]], -1
; CHECK-NEXT: ret i4 [[NOT]]
;
%and = and i4 %a, %b
%xor = xor i4 %a, %b
%not = xor i4 %xor, -1
%r = or i4 %and, %not
ret i4 %r
}
define <2 x i4> @or_nxor_and_commute1(<2 x i4> %a, <2 x i4> %b) {
; CHECK-LABEL: @or_nxor_and_commute1(
; CHECK-NEXT: [[XOR:%.*]] = xor <2 x i4> [[A:%.*]], [[B:%.*]]
; CHECK-NEXT: [[NOT:%.*]] = xor <2 x i4> [[XOR]], <i4 -1, i4 -1>
; CHECK-NEXT: ret <2 x i4> [[NOT]]
;
%and = and <2 x i4> %a, %b
%xor = xor <2 x i4> %a, %b
%not = xor <2 x i4> %xor, <i4 -1, i4 -1>
%r = or <2 x i4> %not, %and
ret <2 x i4> %r
}
define i74 @or_nxor_and_commute2(i74 %a, i74 %b) {
; CHECK-LABEL: @or_nxor_and_commute2(
; CHECK-NEXT: [[XOR:%.*]] = xor i74 [[A:%.*]], [[B:%.*]]
; CHECK-NEXT: [[NOT:%.*]] = xor i74 [[XOR]], -1
; CHECK-NEXT: ret i74 [[NOT]]
;
%and = and i74 %b, %a
%xor = xor i74 %a, %b
%not = xor i74 %xor, -1
%r = or i74 %and, %not
ret i74 %r
}
define <2 x i4> @or_nxor_and_commute3(<2 x i4> %a, <2 x i4> %b) {
; CHECK-LABEL: @or_nxor_and_commute3(
; CHECK-NEXT: [[XOR:%.*]] = xor <2 x i4> [[A:%.*]], [[B:%.*]]
; CHECK-NEXT: [[NOT:%.*]] = xor <2 x i4> [[XOR]], <i4 -1, i4 -1>
; CHECK-NEXT: ret <2 x i4> [[NOT]]
;
%and = and <2 x i4> %b, %a
%xor = xor <2 x i4> %a, %b
%not = xor <2 x i4> %xor, <i4 -1, i4 -1>
%r = or <2 x i4> %not, %and
ret <2 x i4> %r
}
; negative test - must have common operands
define i4 @or_nxor_and_wrong_val1(i4 %a, i4 %b, i4 %c) {
; CHECK-LABEL: @or_nxor_and_wrong_val1(
; CHECK-NEXT: [[AND:%.*]] = and i4 [[A:%.*]], [[C:%.*]]
; CHECK-NEXT: [[XOR:%.*]] = xor i4 [[A]], [[B:%.*]]
; CHECK-NEXT: [[NOT:%.*]] = xor i4 [[XOR]], -1
; CHECK-NEXT: [[R:%.*]] = or i4 [[AND]], [[NOT]]
; CHECK-NEXT: ret i4 [[R]]
;
%and = and i4 %a, %c
%xor = xor i4 %a, %b
%not = xor i4 %xor, -1
%r = or i4 %and, %not
ret i4 %r
}
; negative test - must have common operands
define i4 @or_nxor_and_wrong_val2(i4 %a, i4 %b, i4 %c) {
; CHECK-LABEL: @or_nxor_and_wrong_val2(
; CHECK-NEXT: [[AND:%.*]] = and i4 [[C:%.*]], [[B:%.*]]
; CHECK-NEXT: [[XOR:%.*]] = xor i4 [[A:%.*]], [[B]]
; CHECK-NEXT: [[NOT:%.*]] = xor i4 [[XOR]], -1
; CHECK-NEXT: [[R:%.*]] = or i4 [[AND]], [[NOT]]
; CHECK-NEXT: ret i4 [[R]]
;
%and = and i4 %c, %b
%xor = xor i4 %a, %b
%not = xor i4 %xor, -1
%r = or i4 %and, %not
ret i4 %r
}
; negative test - undef in 'not' is allowed
define <2 x i4> @or_nxor_and_undef_elt(<2 x i4> %a, <2 x i4> %b) {
; CHECK-LABEL: @or_nxor_and_undef_elt(
; CHECK-NEXT: [[AND:%.*]] = and <2 x i4> [[B:%.*]], [[A:%.*]]
; CHECK-NEXT: [[XOR:%.*]] = xor <2 x i4> [[A]], [[B]]
; CHECK-NEXT: [[NOT:%.*]] = xor <2 x i4> [[XOR]], <i4 -1, i4 undef>
; CHECK-NEXT: [[R:%.*]] = or <2 x i4> [[NOT]], [[AND]]
; CHECK-NEXT: ret <2 x i4> [[R]]
;
%and = and <2 x i4> %b, %a
%xor = xor <2 x i4> %a, %b
%not = xor <2 x i4> %xor, <i4 -1, i4 undef>
%r = or <2 x i4> %not, %and
ret <2 x i4> %r
}
; Same with poison is safe.
define <2 x i4> @or_nxor_and_poison_elt(<2 x i4> %a, <2 x i4> %b) {
; CHECK-LABEL: @or_nxor_and_poison_elt(
; CHECK-NEXT: [[XOR:%.*]] = xor <2 x i4> [[A:%.*]], [[B:%.*]]
; CHECK-NEXT: [[NOT:%.*]] = xor <2 x i4> [[XOR]], <i4 -1, i4 poison>
; CHECK-NEXT: ret <2 x i4> [[NOT]]
;
%and = and <2 x i4> %b, %a
%xor = xor <2 x i4> %a, %b
%not = xor <2 x i4> %xor, <i4 -1, i4 poison>
%r = or <2 x i4> %not, %and
ret <2 x i4> %r
}
; ~(A ^ B) | (A | B) --> -1
define i4 @or_nxor_or_commute0(i4 %a, i4 %b) {
; CHECK-LABEL: @or_nxor_or_commute0(
; CHECK-NEXT: ret i4 -1
;
%or = or i4 %a, %b
%xor = xor i4 %a, %b
%not = xor i4 %xor, -1
%r = or i4 %not, %or
ret i4 %r
}
define <2 x i4> @or_nxor_or_commute1(<2 x i4> %a, <2 x i4> %b) {
; CHECK-LABEL: @or_nxor_or_commute1(
; CHECK-NEXT: ret <2 x i4> <i4 -1, i4 -1>
;
%or = or <2 x i4> %a, %b
%xor = xor <2 x i4> %a, %b
%not = xor <2 x i4> %xor, <i4 -1, i4 -1>
%r = or <2 x i4> %or, %not
ret <2 x i4> %r
}
define i74 @or_nxor_or_commute2(i74 %a, i74 %b) {
; CHECK-LABEL: @or_nxor_or_commute2(
; CHECK-NEXT: ret i74 -1
;
%or = or i74 %b, %a
%xor = xor i74 %a, %b
%not = xor i74 %xor, -1
%r = or i74 %not, %or
ret i74 %r
}
define <2 x i4> @or_nxor_or_commute3(<2 x i4> %a, <2 x i4> %b) {
; CHECK-LABEL: @or_nxor_or_commute3(
; CHECK-NEXT: ret <2 x i4> <i4 -1, i4 -1>
;
%or = or <2 x i4> %b, %a
%xor = xor <2 x i4> %a, %b
%not = xor <2 x i4> %xor, <i4 -1, i4 -1>
%r = or <2 x i4> %or, %not
ret <2 x i4> %r
}
; negative test - must have common operands
define i4 @or_nxor_or_wrong_val1(i4 %a, i4 %b, i4 %c) {
; CHECK-LABEL: @or_nxor_or_wrong_val1(
; CHECK-NEXT: [[OR:%.*]] = or i4 [[A:%.*]], [[C:%.*]]
; CHECK-NEXT: [[XOR:%.*]] = xor i4 [[A]], [[B:%.*]]
; CHECK-NEXT: [[NOT:%.*]] = xor i4 [[XOR]], -1
; CHECK-NEXT: [[R:%.*]] = or i4 [[NOT]], [[OR]]
; CHECK-NEXT: ret i4 [[R]]
;
%or = or i4 %a, %c
%xor = xor i4 %a, %b
%not = xor i4 %xor, -1
%r = or i4 %not, %or
ret i4 %r
}
; negative test - must have common operands
define i4 @or_nxor_or_wrong_val2(i4 %a, i4 %b, i4 %c) {
; CHECK-LABEL: @or_nxor_or_wrong_val2(
; CHECK-NEXT: [[OR:%.*]] = or i4 [[C:%.*]], [[B:%.*]]
; CHECK-NEXT: [[XOR:%.*]] = xor i4 [[A:%.*]], [[B]]
; CHECK-NEXT: [[NOT:%.*]] = xor i4 [[XOR]], -1
; CHECK-NEXT: [[R:%.*]] = or i4 [[NOT]], [[OR]]
; CHECK-NEXT: ret i4 [[R]]
;
%or = or i4 %c, %b
%xor = xor i4 %a, %b
%not = xor i4 %xor, -1
%r = or i4 %not, %or
ret i4 %r
}
; negative test - poison in 'not' is allowed
define <2 x i4> @or_nxor_or_poison_elt(<2 x i4> %a, <2 x i4> %b) {
; CHECK-LABEL: @or_nxor_or_poison_elt(
; CHECK-NEXT: ret <2 x i4> <i4 -1, i4 -1>
;
%or = or <2 x i4> %b, %a
%xor = xor <2 x i4> %a, %b
%not = xor <2 x i4> %xor, <i4 -1, i4 poison>
%r = or <2 x i4> %or, %not
ret <2 x i4> %r
}
; (A ^ B) | (~A | B) --> -1
define i4 @or_xor_not_op_or(i4 %a, i4 %b){
; CHECK-LABEL: @or_xor_not_op_or(
; CHECK-NEXT: ret i4 -1
;
%xor = xor i4 %a, %b
%nota = xor i4 %a, -1
%or = or i4 %nota, %b
%r = or i4 %xor, %or
ret i4 %r
}
; (A ^ B) | (B | ~A) --> -1
define i71 @or_xor_not_op_or_commute1(i71 %a, i71 %b){
; CHECK-LABEL: @or_xor_not_op_or_commute1(
; CHECK-NEXT: ret i71 -1
;
%xor = xor i71 %a, %b
%nota = xor i71 %a, -1
%or = or i71 %b, %nota
%r = or i71 %xor, %or
ret i71 %r
}
; (B ^ A) | (~A | B) --> -1
define i32 @or_xor_not_op_or_commute2(i32 %a, i32 %b){
; CHECK-LABEL: @or_xor_not_op_or_commute2(
; CHECK-NEXT: ret i32 -1
;
%xor = xor i32 %b, %a
%nota = xor i32 %a, -1
%or = or i32 %nota, %b
%r = or i32 %xor, %or
ret i32 %r
}
; (B ^ A) | (B | ~A) --> -1
define i32 @or_xor_not_op_or_commute3(i32 %a, i32 %b){
; CHECK-LABEL: @or_xor_not_op_or_commute3(
; CHECK-NEXT: ret i32 -1
;
%xor = xor i32 %b, %a
%nota = xor i32 %a, -1
%or = or i32 %b, %nota
%r = or i32 %xor, %or
ret i32 %r
}
; (~A | B) | (A ^ B) --> -1
define i32 @or_xor_not_op_or_commute4(i32 %a, i32 %b){
; CHECK-LABEL: @or_xor_not_op_or_commute4(
; CHECK-NEXT: ret i32 -1
;
%xor = xor i32 %a, %b
%nota = xor i32 %a, -1
%or = or i32 %nota, %b
%r = or i32 %or, %xor
ret i32 %r
}
; (B | ~A) | (A ^ B) --> -1
define i32 @or_xor_not_op_or_commute5(i32 %a, i32 %b){
; CHECK-LABEL: @or_xor_not_op_or_commute5(
; CHECK-NEXT: ret i32 -1
;
%xor = xor i32 %a, %b
%nota = xor i32 %a, -1
%or = or i32 %b, %nota
%r = or i32 %or, %xor
ret i32 %r
}
; (~A | B) | (B ^ A) --> -1
define i32 @or_xor_not_op_or_commute6(i32 %a, i32 %b){
; CHECK-LABEL: @or_xor_not_op_or_commute6(
; CHECK-NEXT: ret i32 -1
;
%xor = xor i32 %b, %a
%nota = xor i32 %a, -1
%or = or i32 %nota, %b
%r = or i32 %or, %xor
ret i32 %r
}
; (B | ~A) | (B ^ A) --> -1
define i32 @or_xor_not_op_or_commute7(i32 %a, i32 %b){
; CHECK-LABEL: @or_xor_not_op_or_commute7(
; CHECK-NEXT: ret i32 -1
;
%xor = xor i32 %b, %a
%nota = xor i32 %a, -1
%or = or i32 %b, %nota
%r = or i32 %or, %xor
ret i32 %r
}
define <2 x i4> @or_xor_not_op_or_poison_elt(<2 x i4> %a, <2 x i4> %b) {
; CHECK-LABEL: @or_xor_not_op_or_poison_elt(
; CHECK-NEXT: ret <2 x i4> <i4 -1, i4 -1>
;
%xor = xor <2 x i4> %a, %b
%nota = xor <2 x i4> %a, <i4 -1, i4 poison>
%or = or <2 x i4> %nota, %b
%r = or <2 x i4> %xor, %or
ret <2 x i4> %r
}
; negative test
define i16 @or_xor_not_op_or_wrong_val(i16 %a, i16 %b, i16 %c) {
; CHECK-LABEL: @or_xor_not_op_or_wrong_val(
; CHECK-NEXT: [[XOR:%.*]] = xor i16 [[A:%.*]], [[C:%.*]]
; CHECK-NEXT: [[NOTA:%.*]] = xor i16 [[A]], -1
; CHECK-NEXT: [[OR:%.*]] = or i16 [[NOTA]], [[B:%.*]]
; CHECK-NEXT: [[R:%.*]] = or i16 [[XOR]], [[OR]]
; CHECK-NEXT: ret i16 [[R]]
;
%xor = xor i16 %a, %c
%nota = xor i16 %a, -1
%or = or i16 %nota, %b
%r = or i16 %xor, %or
ret i16 %r
}
; ~(x & y) | (x ^ y) --> ~(x & y)
define i4 @or_nand_xor(i4 %x, i4 %y) {
; CHECK-LABEL: @or_nand_xor(
; CHECK-NEXT: [[AND:%.*]] = and i4 [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: [[NAND:%.*]] = xor i4 [[AND]], -1
; CHECK-NEXT: ret i4 [[NAND]]
;
%and = and i4 %x, %y
%xor = xor i4 %x, %y
%nand = xor i4 %and, -1
%or = or i4 %xor, %nand
ret i4 %or
}
define <2 x i4> @or_nand_xor_commute1(<2 x i4> %x, <2 x i4> %y) {
; CHECK-LABEL: @or_nand_xor_commute1(
; CHECK-NEXT: [[AND:%.*]] = and <2 x i4> [[Y:%.*]], [[X:%.*]]
; CHECK-NEXT: [[NAND:%.*]] = xor <2 x i4> [[AND]], <i4 -1, i4 -1>
; CHECK-NEXT: ret <2 x i4> [[NAND]]
;
%and = and <2 x i4> %y, %x
%xor = xor <2 x i4> %x, %y
%nand = xor <2 x i4> %and, <i4 -1, i4 -1>
%or = or <2 x i4> %xor, %nand
ret <2 x i4> %or
}
define i71 @or_nand_xor_commute2(i71 %x, i71 %y) {
; CHECK-LABEL: @or_nand_xor_commute2(
; CHECK-NEXT: [[AND:%.*]] = and i71 [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: [[NAND:%.*]] = xor i71 [[AND]], -1
; CHECK-NEXT: ret i71 [[NAND]]
;
%and = and i71 %x, %y
%xor = xor i71 %x, %y
%nand = xor i71 %and, -1
%or = or i71 %nand, %xor
ret i71 %or
}
define i4 @or_nand_xor_commute3(i4 %x, i4 %y) {
; CHECK-LABEL: @or_nand_xor_commute3(
; CHECK-NEXT: [[AND:%.*]] = and i4 [[Y:%.*]], [[X:%.*]]
; CHECK-NEXT: [[NAND:%.*]] = xor i4 [[AND]], -1
; CHECK-NEXT: ret i4 [[NAND]]
;
%and = and i4 %y, %x
%xor = xor i4 %x, %y
%nand = xor i4 %and, -1
%or = or i4 %nand, %xor
ret i4 %or
}
; negative test wrong operand
define i4 @or_nand_xor_wrong_val(i4 %x, i4 %y, i4 %z) {
; CHECK-LABEL: @or_nand_xor_wrong_val(
; CHECK-NEXT: [[AND:%.*]] = and i4 [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: [[XOR:%.*]] = xor i4 [[X]], [[Z:%.*]]
; CHECK-NEXT: [[NAND:%.*]] = xor i4 [[AND]], -1
; CHECK-NEXT: [[OR:%.*]] = or i4 [[XOR]], [[NAND]]
; CHECK-NEXT: ret i4 [[OR]]
;
%and = and i4 %x, %y
%xor = xor i4 %x, %z
%nand = xor i4 %and, -1
%or = or i4 %xor, %nand
ret i4 %or
}
; negative test - undef element in 'not' is not allowed
define <2 x i4> @or_nand_xor_undef_elt(<2 x i4> %x, <2 x i4> %y) {
; CHECK-LABEL: @or_nand_xor_undef_elt(
; CHECK-NEXT: [[AND:%.*]] = and <2 x i4> [[Y:%.*]], [[X:%.*]]
; CHECK-NEXT: [[XOR:%.*]] = xor <2 x i4> [[X]], [[Y]]
; CHECK-NEXT: [[NAND:%.*]] = xor <2 x i4> [[AND]], <i4 undef, i4 -1>
; CHECK-NEXT: [[OR:%.*]] = or <2 x i4> [[XOR]], [[NAND]]
; CHECK-NEXT: ret <2 x i4> [[OR]]
;
%and = and <2 x i4> %y, %x
%xor = xor <2 x i4> %x, %y
%nand = xor <2 x i4> %and, <i4 undef, i4 -1>
%or = or <2 x i4> %xor, %nand
ret <2 x i4> %or
}
; Same with poison is safe.
define <2 x i4> @or_nand_xor_poison_elt(<2 x i4> %x, <2 x i4> %y) {
; CHECK-LABEL: @or_nand_xor_poison_elt(
; CHECK-NEXT: [[AND:%.*]] = and <2 x i4> [[Y:%.*]], [[X:%.*]]
; CHECK-NEXT: [[NAND:%.*]] = xor <2 x i4> [[AND]], <i4 poison, i4 -1>
; CHECK-NEXT: ret <2 x i4> [[NAND]]
;
%and = and <2 x i4> %y, %x
%xor = xor <2 x i4> %x, %y
%nand = xor <2 x i4> %and, <i4 poison, i4 -1>
%or = or <2 x i4> %xor, %nand
ret <2 x i4> %or
}
declare i32 @llvm.fshl.i32 (i32, i32, i32)
declare i32 @llvm.fshr.i32 (i32, i32, i32)
define i32 @or_shl_fshl(i32 %x, i32 %y, i32 %s) {
; CHECK-LABEL: @or_shl_fshl(
; CHECK-NEXT: [[FUN:%.*]] = call i32 @llvm.fshl.i32(i32 [[Y:%.*]], i32 [[X:%.*]], i32 [[S:%.*]])
; CHECK-NEXT: ret i32 [[FUN]]
;
%shy = shl i32 %y, %s
%fun = call i32 @llvm.fshl.i32(i32 %y, i32 %x, i32 %s)
%or = or i32 %fun, %shy
ret i32 %or
}
define i32 @or_shl_fshl_commute(i32 %x, i32 %y, i32 %s) {
; CHECK-LABEL: @or_shl_fshl_commute(
; CHECK-NEXT: [[FUN:%.*]] = call i32 @llvm.fshl.i32(i32 [[Y:%.*]], i32 [[X:%.*]], i32 [[S:%.*]])
; CHECK-NEXT: ret i32 [[FUN]]
;
%shy = shl i32 %y, %s
%fun = call i32 @llvm.fshl.i32(i32 %y, i32 %x, i32 %s)
%or = or i32 %shy, %fun
ret i32 %or
}
; negative test - fshl operands are not commutative
define i32 @or_shl_fshl_wrong_order(i32 %x, i32 %y, i32 %s) {
; CHECK-LABEL: @or_shl_fshl_wrong_order(
; CHECK-NEXT: [[SHY:%.*]] = shl i32 [[Y:%.*]], [[S:%.*]]
; CHECK-NEXT: [[FUN:%.*]] = call i32 @llvm.fshl.i32(i32 [[X:%.*]], i32 [[Y]], i32 [[S]])
; CHECK-NEXT: [[OR:%.*]] = or i32 [[FUN]], [[SHY]]
; CHECK-NEXT: ret i32 [[OR]]
;
%shy = shl i32 %y, %s
%fun = call i32 @llvm.fshl.i32(i32 %x, i32 %y, i32 %s)
%or = or i32 %fun, %shy
ret i32 %or
}
define i32 @or_lshr_fshr(i32 %x, i32 %y, i32 %s) {
; CHECK-LABEL: @or_lshr_fshr(
; CHECK-NEXT: [[FUN:%.*]] = call i32 @llvm.fshr.i32(i32 [[X:%.*]], i32 [[Y:%.*]], i32 [[S:%.*]])
; CHECK-NEXT: ret i32 [[FUN]]
;
%shy = lshr i32 %y, %s
%fun = call i32 @llvm.fshr.i32(i32 %x, i32 %y, i32 %s)
%or = or i32 %fun, %shy
ret i32 %or
}
define i32 @or_lshr_fshr_commute(i32 %x, i32 %y, i32 %s) {
; CHECK-LABEL: @or_lshr_fshr_commute(
; CHECK-NEXT: [[FUN:%.*]] = call i32 @llvm.fshr.i32(i32 [[X:%.*]], i32 [[Y:%.*]], i32 [[S:%.*]])
; CHECK-NEXT: ret i32 [[FUN]]
;
%shy = lshr i32 %y, %s
%fun = call i32 @llvm.fshr.i32(i32 %x, i32 %y, i32 %s)
%or = or i32 %shy, %fun
ret i32 %or
}
; negative test - fshr operands are not commutative
define i32 @or_lshr_fshr_wrong_order(i32 %x, i32 %y, i32 %s) {
; CHECK-LABEL: @or_lshr_fshr_wrong_order(
; CHECK-NEXT: [[SHY:%.*]] = lshr i32 [[Y:%.*]], [[S:%.*]]
; CHECK-NEXT: [[FUN:%.*]] = call i32 @llvm.fshr.i32(i32 [[Y]], i32 [[X:%.*]], i32 [[S]])
; CHECK-NEXT: [[OR:%.*]] = or i32 [[FUN]], [[SHY]]
; CHECK-NEXT: ret i32 [[OR]]
;
%shy = lshr i32 %y, %s
%fun = call i32 @llvm.fshr.i32(i32 %y, i32 %x, i32 %s)
%or = or i32 %fun, %shy
ret i32 %or
}
|