Skip to content

Commit 375bb38

Browse files
committed
[RISCV][GISel] Add i32 zext.h pattern for Zbkb.
This resolves a FIXME and reduces tests diffs from later patches remove i32 as a legal type.
1 parent 615e28e commit 375bb38

File tree

3 files changed

+13
-25
lines changed

3 files changed

+13
-25
lines changed

llvm/lib/Target/RISCV/RISCVGISel.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,10 @@ def : Pat<(i32 (sext_inreg GPR:$rs1, i16)), (SEXT_H GPR:$rs1)>;
249249
def : Pat<(i32 (and GPR:$rs, 0xFFFF)), (ZEXT_H_RV64 GPR:$rs)>;
250250
} // Predicates = [HasStdExtZbb, IsRV64]
251251

252+
let Predicates = [HasStdExtZbkb, NoStdExtZbb, IsRV64] in {
253+
def : Pat<(i32 (and GPR:$rs, 0xFFFF)), (PACKW GPR:$rs, (XLenVT X0))>;
254+
} // Predicates = [HasStdExtZbb, IsRV64]
255+
252256
let Predicates = [HasStdExtZbbOrZbkb, IsRV64] in {
253257
def : Pat<(i32 (and GPR:$rs1, (not GPR:$rs2))), (ANDN GPR:$rs1, GPR:$rs2)>;
254258
def : Pat<(i32 (or GPR:$rs1, (not GPR:$rs2))), (ORN GPR:$rs1, GPR:$rs2)>;

llvm/test/CodeGen/RISCV/GlobalISel/rv64zbb-zbkb.ll

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -471,19 +471,11 @@ define i16 @srli_i16(i16 %a) nounwind {
471471
; RV64I-NEXT: srliw a0, a0, 6
472472
; RV64I-NEXT: ret
473473
;
474-
; RV64ZBB-LABEL: srli_i16:
475-
; RV64ZBB: # %bb.0:
476-
; RV64ZBB-NEXT: zext.h a0, a0
477-
; RV64ZBB-NEXT: srliw a0, a0, 6
478-
; RV64ZBB-NEXT: ret
479-
;
480-
; RV64ZBKB-LABEL: srli_i16:
481-
; RV64ZBKB: # %bb.0:
482-
; RV64ZBKB-NEXT: lui a1, 16
483-
; RV64ZBKB-NEXT: addi a1, a1, -1
484-
; RV64ZBKB-NEXT: and a0, a0, a1
485-
; RV64ZBKB-NEXT: srliw a0, a0, 6
486-
; RV64ZBKB-NEXT: ret
474+
; RV64ZBB-ZBKB-LABEL: srli_i16:
475+
; RV64ZBB-ZBKB: # %bb.0:
476+
; RV64ZBB-ZBKB-NEXT: zext.h a0, a0
477+
; RV64ZBB-ZBKB-NEXT: srliw a0, a0, 6
478+
; RV64ZBB-ZBKB-NEXT: ret
487479
%1 = lshr i16 %a, 6
488480
ret i16 %1
489481
}

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

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,9 @@ define signext i32 @pack_i32(i32 signext %a, i32 signext %b) nounwind {
1818
;
1919
; RV64ZBKB-LABEL: pack_i32:
2020
; RV64ZBKB: # %bb.0:
21-
; RV64ZBKB-NEXT: lui a2, 16
22-
; RV64ZBKB-NEXT: addi a2, a2, -1
23-
; RV64ZBKB-NEXT: and a0, a0, a2
24-
; RV64ZBKB-NEXT: slli a1, a1, 16
21+
; RV64ZBKB-NEXT: zext.h a0, a0
22+
; RV64ZBKB-NEXT: slliw a1, a1, 16
2523
; RV64ZBKB-NEXT: or a0, a1, a0
26-
; RV64ZBKB-NEXT: sext.w a0, a0
2724
; RV64ZBKB-NEXT: ret
2825
%shl = and i32 %a, 65535
2926
%shl1 = shl i32 %b, 16
@@ -368,9 +365,7 @@ define signext i32 @pack_i32_allWUsers(i16 zeroext %0, i16 zeroext %1, i16 zeroe
368365
; RV64ZBKB-LABEL: pack_i32_allWUsers:
369366
; RV64ZBKB: # %bb.0:
370367
; RV64ZBKB-NEXT: add a0, a1, a0
371-
; RV64ZBKB-NEXT: lui a1, 16
372-
; RV64ZBKB-NEXT: addi a1, a1, -1
373-
; RV64ZBKB-NEXT: and a0, a0, a1
368+
; RV64ZBKB-NEXT: zext.h a0, a0
374369
; RV64ZBKB-NEXT: slli a0, a0, 16
375370
; RV64ZBKB-NEXT: or a0, a0, a2
376371
; RV64ZBKB-NEXT: sext.w a0, a0
@@ -404,7 +399,6 @@ define i64 @pack_i64_imm() {
404399
ret i64 1157442765409226768 ; 0x0101010101010101
405400
}
406401

407-
; FIXME: Use zext.h
408402
define i32 @zexth_i32(i32 %a) nounwind {
409403
; RV64I-LABEL: zexth_i32:
410404
; RV64I: # %bb.0:
@@ -415,9 +409,7 @@ define i32 @zexth_i32(i32 %a) nounwind {
415409
;
416410
; RV64ZBKB-LABEL: zexth_i32:
417411
; RV64ZBKB: # %bb.0:
418-
; RV64ZBKB-NEXT: lui a1, 16
419-
; RV64ZBKB-NEXT: addiw a1, a1, -1
420-
; RV64ZBKB-NEXT: and a0, a0, a1
412+
; RV64ZBKB-NEXT: zext.h a0, a0
421413
; RV64ZBKB-NEXT: ret
422414
%and = and i32 %a, 65535
423415
ret i32 %and

0 commit comments

Comments
 (0)