Skip to content

Commit

Permalink
[RISCV][GISel] Add i32 zext.h pattern for Zbkb.
Browse files Browse the repository at this point in the history
This resolves a FIXME and reduces tests diffs from later patches
remove i32 as a legal type.
  • Loading branch information
topperc committed Nov 11, 2024
1 parent 615e28e commit 375bb38
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 25 deletions.
4 changes: 4 additions & 0 deletions llvm/lib/Target/RISCV/RISCVGISel.td
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,10 @@ def : Pat<(i32 (sext_inreg GPR:$rs1, i16)), (SEXT_H GPR:$rs1)>;
def : Pat<(i32 (and GPR:$rs, 0xFFFF)), (ZEXT_H_RV64 GPR:$rs)>;
} // Predicates = [HasStdExtZbb, IsRV64]

let Predicates = [HasStdExtZbkb, NoStdExtZbb, IsRV64] in {
def : Pat<(i32 (and GPR:$rs, 0xFFFF)), (PACKW GPR:$rs, (XLenVT X0))>;
} // Predicates = [HasStdExtZbb, IsRV64]

let Predicates = [HasStdExtZbbOrZbkb, IsRV64] in {
def : Pat<(i32 (and GPR:$rs1, (not GPR:$rs2))), (ANDN GPR:$rs1, GPR:$rs2)>;
def : Pat<(i32 (or GPR:$rs1, (not GPR:$rs2))), (ORN GPR:$rs1, GPR:$rs2)>;
Expand Down
18 changes: 5 additions & 13 deletions llvm/test/CodeGen/RISCV/GlobalISel/rv64zbb-zbkb.ll
Original file line number Diff line number Diff line change
Expand Up @@ -471,19 +471,11 @@ define i16 @srli_i16(i16 %a) nounwind {
; RV64I-NEXT: srliw a0, a0, 6
; RV64I-NEXT: ret
;
; RV64ZBB-LABEL: srli_i16:
; RV64ZBB: # %bb.0:
; RV64ZBB-NEXT: zext.h a0, a0
; RV64ZBB-NEXT: srliw a0, a0, 6
; RV64ZBB-NEXT: ret
;
; RV64ZBKB-LABEL: srli_i16:
; RV64ZBKB: # %bb.0:
; RV64ZBKB-NEXT: lui a1, 16
; RV64ZBKB-NEXT: addi a1, a1, -1
; RV64ZBKB-NEXT: and a0, a0, a1
; RV64ZBKB-NEXT: srliw a0, a0, 6
; RV64ZBKB-NEXT: ret
; RV64ZBB-ZBKB-LABEL: srli_i16:
; RV64ZBB-ZBKB: # %bb.0:
; RV64ZBB-ZBKB-NEXT: zext.h a0, a0
; RV64ZBB-ZBKB-NEXT: srliw a0, a0, 6
; RV64ZBB-ZBKB-NEXT: ret
%1 = lshr i16 %a, 6
ret i16 %1
}
Expand Down
16 changes: 4 additions & 12 deletions llvm/test/CodeGen/RISCV/GlobalISel/rv64zbkb.ll
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,9 @@ define signext i32 @pack_i32(i32 signext %a, i32 signext %b) nounwind {
;
; RV64ZBKB-LABEL: pack_i32:
; RV64ZBKB: # %bb.0:
; RV64ZBKB-NEXT: lui a2, 16
; RV64ZBKB-NEXT: addi a2, a2, -1
; RV64ZBKB-NEXT: and a0, a0, a2
; RV64ZBKB-NEXT: slli a1, a1, 16
; RV64ZBKB-NEXT: zext.h a0, a0
; RV64ZBKB-NEXT: slliw a1, a1, 16
; RV64ZBKB-NEXT: or a0, a1, a0
; RV64ZBKB-NEXT: sext.w a0, a0
; RV64ZBKB-NEXT: ret
%shl = and i32 %a, 65535
%shl1 = shl i32 %b, 16
Expand Down Expand Up @@ -368,9 +365,7 @@ define signext i32 @pack_i32_allWUsers(i16 zeroext %0, i16 zeroext %1, i16 zeroe
; RV64ZBKB-LABEL: pack_i32_allWUsers:
; RV64ZBKB: # %bb.0:
; RV64ZBKB-NEXT: add a0, a1, a0
; RV64ZBKB-NEXT: lui a1, 16
; RV64ZBKB-NEXT: addi a1, a1, -1
; RV64ZBKB-NEXT: and a0, a0, a1
; RV64ZBKB-NEXT: zext.h a0, a0
; RV64ZBKB-NEXT: slli a0, a0, 16
; RV64ZBKB-NEXT: or a0, a0, a2
; RV64ZBKB-NEXT: sext.w a0, a0
Expand Down Expand Up @@ -404,7 +399,6 @@ define i64 @pack_i64_imm() {
ret i64 1157442765409226768 ; 0x0101010101010101
}

; FIXME: Use zext.h
define i32 @zexth_i32(i32 %a) nounwind {
; RV64I-LABEL: zexth_i32:
; RV64I: # %bb.0:
Expand All @@ -415,9 +409,7 @@ define i32 @zexth_i32(i32 %a) nounwind {
;
; RV64ZBKB-LABEL: zexth_i32:
; RV64ZBKB: # %bb.0:
; RV64ZBKB-NEXT: lui a1, 16
; RV64ZBKB-NEXT: addiw a1, a1, -1
; RV64ZBKB-NEXT: and a0, a0, a1
; RV64ZBKB-NEXT: zext.h a0, a0
; RV64ZBKB-NEXT: ret
%and = and i32 %a, 65535
ret i32 %and
Expand Down

0 comments on commit 375bb38

Please sign in to comment.