Skip to content

Commit 21ded66

Browse files
committed
[RISCV][GISel] Add zexti8 ComplexPattern.
1 parent f85be26 commit 21ded66

File tree

3 files changed

+34
-21
lines changed

3 files changed

+34
-21
lines changed

llvm/lib/Target/RISCV/RISCVGISel.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ def gi_zexti32 : GIComplexOperandMatcher<s64, "selectZExtBits<32>">,
100100
GIComplexPatternEquiv<zexti32>;
101101
def gi_zexti16 : GIComplexOperandMatcher<s32, "selectZExtBits<16>">,
102102
GIComplexPatternEquiv<zexti16>;
103+
def gi_zexti8 : GIComplexOperandMatcher<s32, "selectZExtBits<8>">,
104+
GIComplexPatternEquiv<zexti8>;
103105

104106
// FIXME: Canonicalize (sub X, C) -> (add X, -C) earlier.
105107
def : Pat<(XLenVT (sub GPR:$rs1, simm12Plus1:$imm)),

llvm/test/CodeGen/RISCV/GlobalISel/rv32zbkb.ll

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,18 @@ define i32 @packh_i32(i32 %a, i32 %b) nounwind {
113113
}
114114

115115
define i32 @packh_i32_2(i32 %a, i32 %b) nounwind {
116-
; CHECK-LABEL: packh_i32_2:
117-
; CHECK: # %bb.0:
118-
; CHECK-NEXT: andi a0, a0, 255
119-
; CHECK-NEXT: andi a1, a1, 255
120-
; CHECK-NEXT: slli a1, a1, 8
121-
; CHECK-NEXT: or a0, a1, a0
122-
; CHECK-NEXT: ret
116+
; RV32I-LABEL: packh_i32_2:
117+
; RV32I: # %bb.0:
118+
; RV32I-NEXT: andi a0, a0, 255
119+
; RV32I-NEXT: andi a1, a1, 255
120+
; RV32I-NEXT: slli a1, a1, 8
121+
; RV32I-NEXT: or a0, a1, a0
122+
; RV32I-NEXT: ret
123+
;
124+
; RV32ZBKB-LABEL: packh_i32_2:
125+
; RV32ZBKB: # %bb.0:
126+
; RV32ZBKB-NEXT: packh a0, a0, a1
127+
; RV32ZBKB-NEXT: ret
123128
%and = and i32 %a, 255
124129
%and1 = and i32 %b, 255
125130
%shl = shl i32 %and1, 8
@@ -146,16 +151,25 @@ define i64 @packh_i64(i64 %a, i64 %b) nounwind {
146151
}
147152

148153
define i64 @packh_i64_2(i64 %a, i64 %b) nounwind {
149-
; CHECK-LABEL: packh_i64_2:
150-
; CHECK: # %bb.0:
151-
; CHECK-NEXT: andi a0, a0, 255
152-
; CHECK-NEXT: andi a1, a2, 255
153-
; CHECK-NEXT: slli a2, a1, 8
154-
; CHECK-NEXT: slli a3, zero, 8
155-
; CHECK-NEXT: srli a1, a1, 24
156-
; CHECK-NEXT: or a1, a3, a1
157-
; CHECK-NEXT: or a0, a2, a0
158-
; CHECK-NEXT: ret
154+
; RV32I-LABEL: packh_i64_2:
155+
; RV32I: # %bb.0:
156+
; RV32I-NEXT: andi a0, a0, 255
157+
; RV32I-NEXT: andi a1, a2, 255
158+
; RV32I-NEXT: slli a2, a1, 8
159+
; RV32I-NEXT: slli a3, zero, 8
160+
; RV32I-NEXT: srli a1, a1, 24
161+
; RV32I-NEXT: or a1, a3, a1
162+
; RV32I-NEXT: or a0, a2, a0
163+
; RV32I-NEXT: ret
164+
;
165+
; RV32ZBKB-LABEL: packh_i64_2:
166+
; RV32ZBKB: # %bb.0:
167+
; RV32ZBKB-NEXT: andi a1, a2, 255
168+
; RV32ZBKB-NEXT: slli a3, zero, 8
169+
; RV32ZBKB-NEXT: srli a1, a1, 24
170+
; RV32ZBKB-NEXT: or a1, a3, a1
171+
; RV32ZBKB-NEXT: packh a0, a0, a2
172+
; RV32ZBKB-NEXT: ret
159173
%and = and i64 %a, 255
160174
%and1 = and i64 %b, 255
161175
%shl = shl i64 %and1, 8

llvm/test/CodeGen/RISCV/GlobalISel/rv64zbkb.ll

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,7 @@ define i64 @packh_i64_2(i64 %a, i64 %b) nounwind {
230230
;
231231
; RV64ZBKB-LABEL: packh_i64_2:
232232
; RV64ZBKB: # %bb.0:
233-
; RV64ZBKB-NEXT: andi a0, a0, 255
234-
; RV64ZBKB-NEXT: andi a1, a1, 255
235-
; RV64ZBKB-NEXT: slli a1, a1, 8
236-
; RV64ZBKB-NEXT: or a0, a1, a0
233+
; RV64ZBKB-NEXT: packh a0, a0, a1
237234
; RV64ZBKB-NEXT: ret
238235
%and = and i64 %a, 255
239236
%and1 = and i64 %b, 255

0 commit comments

Comments
 (0)