Skip to content

Commit 5489969

Browse files
committed
[RISCV] Add IsRV32 to the isel pattern for ZIP_RV32/UNZIP_RV32. NFC
I think the i32 in the pattern prevents this from matching on RV64, but using IsRV32 is safer. Add tests for RV64 to make sure we don't print zip or unzip because we incorrectly picked ZIP_RV32/UNZIP_RV32.
1 parent 1df8efa commit 5489969

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

llvm/lib/Target/RISCV/RISCVInstrInfoZb.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -852,7 +852,9 @@ let Predicates = [HasStdExtZbpOrZbkb] in {
852852
// We treat brev8 as a separate instruction, so match it directly. We also
853853
// use this for brev8 when lowering bitreverse with Zbkb.
854854
def : Pat<(riscv_grev GPR:$rs1, 7), (BREV8 GPR:$rs1)>;
855+
}
855856

857+
let Predicates = [HasStdExtZbpOrZbkb, IsRV32] in {
856858
// We treat zip and unzip as separate instructions, so match it directly.
857859
def : Pat<(i32 (riscv_shfl GPR:$rs1, 15)), (ZIP_RV32 GPR:$rs1)>;
858860
def : Pat<(i32 (riscv_unshfl GPR:$rs1, 15)), (UNZIP_RV32 GPR:$rs1)>;

llvm/test/CodeGen/RISCV/rv64zbp-intrinsic.ll

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,15 @@ define signext i32 @shfli32(i32 signext %a) nounwind {
100100
ret i32 %tmp
101101
}
102102

103+
define signext i32 @zip_w(i32 signext %a) nounwind {
104+
; RV64ZBP-LABEL: zip_w:
105+
; RV64ZBP: # %bb.0:
106+
; RV64ZBP-NEXT: zip.w a0, a0
107+
; RV64ZBP-NEXT: ret
108+
%tmp = call i32 @llvm.riscv.shfl.i32(i32 %a, i32 15)
109+
ret i32 %tmp
110+
}
111+
103112
declare i32 @llvm.riscv.unshfl.i32(i32 %a, i32 %b)
104113

105114
define signext i32 @unshfl32(i32 signext %a, i32 signext %b) nounwind {
@@ -132,6 +141,15 @@ define signext i32 @unshfli32(i32 signext %a) nounwind {
132141
ret i32 %tmp
133142
}
134143

144+
define signext i32 @unzip_w(i32 signext %a) nounwind {
145+
; RV64ZBP-LABEL: unzip_w:
146+
; RV64ZBP: # %bb.0:
147+
; RV64ZBP-NEXT: unzip.w a0, a0
148+
; RV64ZBP-NEXT: ret
149+
%tmp = call i32 @llvm.riscv.unshfl.i32(i32 %a, i32 15)
150+
ret i32 %tmp
151+
}
152+
135153
declare i64 @llvm.riscv.grev.i64(i64 %a, i64 %b)
136154

137155
define i64 @grev64(i64 %a, i64 %b) nounwind {

0 commit comments

Comments
 (0)