brintos

brintos / llvm-project-archived public Read only

0
0
Text · 6.1 KiB · ba43b63 Raw
208 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py2; RUN: llc --mtriple=loongarch64 -mattr=+d < %s | FileCheck %s3 4;; Test generation of the bstrins.d instruction.5;; There are 8 patterns that can be matched to bstrins.d. See performORCombine6;; for details.7 8;; Pattern 19;; R = or (and X, mask0), (and (shl Y, lsb), mask1)10;; =>11;; R = BSTRINS X, Y, msb, lsb12define i64 @pat1(i64 %a, i64 %b) nounwind {13; CHECK-LABEL: pat1:14; CHECK:       # %bb.0:15; CHECK-NEXT:    bstrins.d $a0, $a1, 39, 1616; CHECK-NEXT:    ret17  %and1 = and i64 %a, -1099511562241  ; 0xffffff000000ffff18  %shl = shl i64 %b, 1619  %and2 = and i64 %shl, 1099511562240 ; 0x000000ffffff000020  %or = or i64 %and1, %and221  ret i64 %or22}23 24define i64 @pat1_swap(i64 %a, i64 %b) nounwind {25; CHECK-LABEL: pat1_swap:26; CHECK:       # %bb.0:27; CHECK-NEXT:    bstrins.d $a0, $a1, 39, 1628; CHECK-NEXT:    ret29  %and1 = and i64 %a, -1099511562241  ; 0xffffff000000ffff30  %shl = shl i64 %b, 1631  %and2 = and i64 %shl, 1099511562240 ; 0x000000ffffff000032  %or = or i64 %and2, %and133  ret i64 %or34}35 36;; Pattern 237;; R = or (and X, mask0), (shl (and Y, mask1), lsb)38;; =>39;; R = BSTRINS X, Y, msb, lsb40define i64 @pat2(i64 %a, i64 %b) nounwind {41; CHECK-LABEL: pat2:42; CHECK:       # %bb.0:43; CHECK-NEXT:    bstrins.d $a0, $a1, 39, 1644; CHECK-NEXT:    ret45  %and1 = and i64 %a, -1099511562241 ; 0xffffff000000ffff46  %and2 = and i64 %b, 16777215       ; 0x0000000000ffffff47  %shl = shl i64 %and2, 1648  %or = or i64 %and1, %shl49  ret i64 %or50}51 52define i64 @pat2_swap(i64 %a, i64 %b) nounwind {53; CHECK-LABEL: pat2_swap:54; CHECK:       # %bb.0:55; CHECK-NEXT:    bstrins.d $a0, $a1, 39, 1656; CHECK-NEXT:    ret57  %and1 = and i64 %a, -1099511562241 ; 0xffffff000000ffff58  %and2 = and i64 %b, 16777215       ; 0x0000000000ffffff59  %shl = shl i64 %and2, 1660  %or = or i64 %shl, %and161  ret i64 %or62}63 64;; Pattern 365;; R = or (and X, mask0), (and Y, mask1)66;; =>67;; R = BSTRINS X, (srl (and Y, mask1), lsb), msb, lsb68define i64 @pat3(i64 %a, i64 %b) nounwind {69; CHECK-LABEL: pat3:70; CHECK:       # %bb.0:71; CHECK-NEXT:    andi $a1, $a1, 28872; CHECK-NEXT:    srli.d $a1, $a1, 473; CHECK-NEXT:    bstrins.d $a0, $a1, 11, 474; CHECK-NEXT:    ret75  %and1 = and i64 %a, -4081 ; 0xfffffffffffff00f76  %and2 = and i64 %b, 288   ; 0x000000000000012077  %or = or i64 %and1, %and278  ret i64 %or79}80 81define i64 @pat3_swap(i64 %a, i64 %b) nounwind {82; CHECK-LABEL: pat3_swap:83; CHECK:       # %bb.0:84; CHECK-NEXT:    andi $a1, $a1, 28885; CHECK-NEXT:    srli.d $a1, $a1, 486; CHECK-NEXT:    bstrins.d $a0, $a1, 11, 487; CHECK-NEXT:    ret88  %and1 = and i64 %a, -4081 ; 0xfffffffffffff00f89  %and2 = and i64 %b, 288   ; 0x000000000000012090  %or = or i64 %and2, %and191  ret i64 %or92}93 94;; Pattern 495;; R = or (and X, mask), (shl Y, shamt)96;; =>97;; R = BSTRINS X, Y, 63, shamt98define i64 @pat4(i64 %a, i64 %b) nounwind {99; CHECK-LABEL: pat4:100; CHECK:       # %bb.0:101; CHECK-NEXT:    bstrins.d $a0, $a1, 63, 8102; CHECK-NEXT:    ret103  %and = and i64 %a, 255104  %shl = shl i64 %b, 8105  %or = or i64 %and, %shl106  ret i64 %or107}108 109define i64 @pat4_swap(i64 %a, i64 %b) nounwind {110; CHECK-LABEL: pat4_swap:111; CHECK:       # %bb.0:112; CHECK-NEXT:    bstrins.d $a0, $a1, 63, 8113; CHECK-NEXT:    ret114  %and = and i64 %a, 255115  %shl = shl i64 %b, 8116  %or = or i64 %shl, %and117  ret i64 %or118}119 120;; Pattern 5121;; R = or (and X, mask0), const122;; =>123;; R = BSTRINS X, (const >> lsb), msb, lsb124define i64 @pat5(i64 %a) nounwind {125; CHECK-LABEL: pat5:126; CHECK:       # %bb.0:127; CHECK-NEXT:    lu12i.w $a1, 74565128; CHECK-NEXT:    ori $a1, $a1, 1656129; CHECK-NEXT:    bstrins.d $a0, $a1, 47, 16130; CHECK-NEXT:    ret131  %and = and i64 %a, 18446462598732906495 ; 0xffff00000000ffff132  %or = or i64 %and, 20015998304256       ; 0x0000123456780000133  ret i64 %or134}135 136;; Pattern 6: a = b | ((c & mask) << shamt)137;; In this testcase b is 0x123456000000789a, but in fact we do not require b138;; being a constant. As long as all positions in b to be overwritten by the139;; incoming bits are known to be zero, the pattern could be matched.140define i64 @pat6(i64 %c) nounwind {141; CHECK-LABEL: pat6:142; CHECK:       # %bb.0:143; CHECK-NEXT:    lu12i.w $a1, 7144; CHECK-NEXT:    ori $a1, $a1, 2202145; CHECK-NEXT:    lu32i.d $a1, 284160146; CHECK-NEXT:    lu52i.d $a1, $a1, 291147; CHECK-NEXT:    bstrins.d $a1, $a0, 39, 16148; CHECK-NEXT:    move $a0, $a1149; CHECK-NEXT:    ret150  %and = and i64 %c, 16777215            ; 0x0000000000ffffff151  %shl = shl i64 %and, 16152  %or = or i64 %shl, 1311767949471676570 ; 0x123456000000789a153  ret i64 %or154}155 156;; Pattern 7: a = b | ((c << shamt) & shifted_mask)157;; Similar to pattern 6.158define i64 @pat7(i64 %c) nounwind {159; CHECK-LABEL: pat7:160; CHECK:       # %bb.0:161; CHECK-NEXT:    lu12i.w $a1, 7162; CHECK-NEXT:    ori $a1, $a1, 2202163; CHECK-NEXT:    lu32i.d $a1, 284160164; CHECK-NEXT:    lu52i.d $a1, $a1, 291165; CHECK-NEXT:    bstrins.d $a1, $a0, 39, 16166; CHECK-NEXT:    move $a0, $a1167; CHECK-NEXT:    ret168  %shl = shl i64 %c, 16169  %and = and i64 %shl, 1099511562240     ; 0x000000ffffff0000170  %or = or i64 %and, 1311767949471676570 ; 0x123456000000789a171  ret i64 %or172}173 174;; Pattern 8: a = b | (c & shifted_mask)175;; Similar to pattern 7 but without shift to c.176define i64 @pat8(i64 %c) nounwind {177; CHECK-LABEL: pat8:178; CHECK:       # %bb.0:179; CHECK-NEXT:    srli.d $a1, $a0, 16180; CHECK-NEXT:    lu12i.w $a0, 7181; CHECK-NEXT:    ori $a0, $a0, 2202182; CHECK-NEXT:    lu32i.d $a0, 284160183; CHECK-NEXT:    lu52i.d $a0, $a0, 291184; CHECK-NEXT:    bstrins.d $a0, $a1, 39, 16185; CHECK-NEXT:    ret186  %and = and i64 %c, 1099511562240       ; 0x000000ffffff0000187  %or = or i64 %and, 1311767949471676570 ; 0x123456000000789a188  ret i64 %or189}190 191;; Test that bstrins.d is not generated because constant OR operand192;; doesn't fit into bits cleared by constant AND operand.193define i64 @no_bstrins_d(i64 %a) nounwind {194; CHECK-LABEL: no_bstrins_d:195; CHECK:       # %bb.0:196; CHECK-NEXT:    lu12i.w $a1, 354185197; CHECK-NEXT:    lu32i.d $a1, 4660198; CHECK-NEXT:    or $a0, $a0, $a1199; CHECK-NEXT:    lu12i.w $a1, 354191200; CHECK-NEXT:    ori $a1, $a1, 4095201; CHECK-NEXT:    lu32i.d $a1, -60876202; CHECK-NEXT:    and $a0, $a0, $a1203; CHECK-NEXT:    ret204  %and = and i64 %a, 18446462598732906495 ; 0xffff00000000ffff205  %or = or i64 %and, 20015998341120       ; 0x0000123456789000206  ret i64 %or207}208