1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -mtriple=riscv32 -verify-machineinstrs < %s \
3 ; RUN: | FileCheck %s -check-prefixes=CHECK,RV32I
4 ; RUN: llc -mtriple=riscv32 -mattr=+experimental-zbp -verify-machineinstrs < %s \
5 ; RUN: | FileCheck %s -check-prefixes=CHECK,RV32ZBP-ZBKB
6 ; RUN: llc -mtriple=riscv32 -mattr=+zbkb -verify-machineinstrs < %s \
7 ; RUN: | FileCheck %s -check-prefixes=CHECK,RV32ZBP-ZBKB
9 define i32 @pack_i32(i32 %a, i32 %b) nounwind {
10 ; RV32I-LABEL: pack_i32:
12 ; RV32I-NEXT: slli a0, a0, 16
13 ; RV32I-NEXT: srli a0, a0, 16
14 ; RV32I-NEXT: slli a1, a1, 16
15 ; RV32I-NEXT: or a0, a1, a0
18 ; RV32ZBP-ZBKB-LABEL: pack_i32:
19 ; RV32ZBP-ZBKB: # %bb.0:
20 ; RV32ZBP-ZBKB-NEXT: pack a0, a0, a1
21 ; RV32ZBP-ZBKB-NEXT: ret
22 %shl = and i32 %a, 65535
23 %shl1 = shl i32 %b, 16
24 %or = or i32 %shl1, %shl
28 ; As we are not matching directly i64 code patterns on RV32 some i64 patterns
29 ; don't have yet any matching bit manipulation instructions on RV32.
30 ; This test is presented here in case future expansions of the Bitmanip
31 ; extensions introduce instructions suitable for this pattern.
33 define i64 @pack_i64(i64 %a, i64 %b) nounwind {
34 ; CHECK-LABEL: pack_i64:
36 ; CHECK-NEXT: mv a1, a2
38 %shl = and i64 %a, 4294967295
39 %shl1 = shl i64 %b, 32
40 %or = or i64 %shl1, %shl
44 ; As we are not matching directly i64 code patterns on RV32 some i64 patterns
45 ; don't have yet any matching bit manipulation instructions on RV32.
46 ; This test is presented here in case future expansions of the Bitmanip
47 ; extensions introduce instructions suitable for this pattern.
49 define i64 @packu_i64(i64 %a, i64 %b) nounwind {
50 ; CHECK-LABEL: packu_i64:
52 ; CHECK-NEXT: mv a0, a1
53 ; CHECK-NEXT: mv a1, a3
55 %shr = lshr i64 %a, 32
56 %shr1 = and i64 %b, -4294967296
57 %or = or i64 %shr1, %shr
61 define i32 @packh_i32(i32 %a, i32 %b) nounwind {
62 ; RV32I-LABEL: packh_i32:
64 ; RV32I-NEXT: andi a0, a0, 255
65 ; RV32I-NEXT: slli a1, a1, 24
66 ; RV32I-NEXT: srli a1, a1, 16
67 ; RV32I-NEXT: or a0, a1, a0
70 ; RV32ZBP-ZBKB-LABEL: packh_i32:
71 ; RV32ZBP-ZBKB: # %bb.0:
72 ; RV32ZBP-ZBKB-NEXT: packh a0, a0, a1
73 ; RV32ZBP-ZBKB-NEXT: ret
74 %and = and i32 %a, 255
76 %shl = and i32 %and1, 65280
77 %or = or i32 %shl, %and
81 define i32 @packh_i32_2(i32 %a, i32 %b) nounwind {
82 ; RV32I-LABEL: packh_i32_2:
84 ; RV32I-NEXT: andi a0, a0, 255
85 ; RV32I-NEXT: andi a1, a1, 255
86 ; RV32I-NEXT: slli a1, a1, 8
87 ; RV32I-NEXT: or a0, a1, a0
90 ; RV32ZBP-ZBKB-LABEL: packh_i32_2:
91 ; RV32ZBP-ZBKB: # %bb.0:
92 ; RV32ZBP-ZBKB-NEXT: packh a0, a0, a1
93 ; RV32ZBP-ZBKB-NEXT: ret
94 %and = and i32 %a, 255
95 %and1 = and i32 %b, 255
96 %shl = shl i32 %and1, 8
97 %or = or i32 %shl, %and
101 define i64 @packh_i64(i64 %a, i64 %b) nounwind {
102 ; RV32I-LABEL: packh_i64:
104 ; RV32I-NEXT: andi a0, a0, 255
105 ; RV32I-NEXT: slli a1, a2, 24
106 ; RV32I-NEXT: srli a1, a1, 16
107 ; RV32I-NEXT: or a0, a1, a0
108 ; RV32I-NEXT: li a1, 0
111 ; RV32ZBP-ZBKB-LABEL: packh_i64:
112 ; RV32ZBP-ZBKB: # %bb.0:
113 ; RV32ZBP-ZBKB-NEXT: packh a0, a0, a2
114 ; RV32ZBP-ZBKB-NEXT: li a1, 0
115 ; RV32ZBP-ZBKB-NEXT: ret
116 %and = and i64 %a, 255
117 %and1 = shl i64 %b, 8
118 %shl = and i64 %and1, 65280
119 %or = or i64 %shl, %and
123 define i64 @packh_i64_2(i64 %a, i64 %b) nounwind {
124 ; RV32I-LABEL: packh_i64_2:
126 ; RV32I-NEXT: andi a0, a0, 255
127 ; RV32I-NEXT: andi a1, a2, 255
128 ; RV32I-NEXT: slli a1, a1, 8
129 ; RV32I-NEXT: or a0, a1, a0
130 ; RV32I-NEXT: li a1, 0
133 ; RV32ZBP-ZBKB-LABEL: packh_i64_2:
134 ; RV32ZBP-ZBKB: # %bb.0:
135 ; RV32ZBP-ZBKB-NEXT: packh a0, a0, a2
136 ; RV32ZBP-ZBKB-NEXT: li a1, 0
137 ; RV32ZBP-ZBKB-NEXT: ret
138 %and = and i64 %a, 255
139 %and1 = and i64 %b, 255
140 %shl = shl i64 %and1, 8
141 %or = or i64 %shl, %and