Skip to content

Commit 214afc7

Browse files
Lian WangLian Wang
authored andcommitted
[RISCV] Add patterns for vnsrl.wi and vnsra.wi instructions
Reviewed By: craig.topper Differential Revision: https://reviews.llvm.org/D121675
1 parent 7bc5273 commit 214afc7

File tree

6 files changed

+358
-285
lines changed

6 files changed

+358
-285
lines changed

llvm/lib/Target/RISCV/RISCVInstrInfoVVLPatterns.td

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -648,45 +648,46 @@ multiclass VPatReductionVL<SDNode vop, string instruction_name, bit is_float> {
648648
}
649649
}
650650

651-
multiclass VPatBinarySDNodeExt_V_WV<SDNode op, PatFrags extop, string instruction_name> {
651+
multiclass VPatBinarySDNodeExt_V_WV_WX<SDNode op, PatFrags extop, string instruction_name> {
652652
foreach vti = AllWidenableIntVectors in {
653653
def : Pat<
654654
(vti.Vti.Vector
655655
(riscv_trunc_vector_vl
656656
(op (vti.Wti.Vector vti.Wti.RegClass:$rs2),
657657
(vti.Wti.Vector (extop (vti.Vti.Vector vti.Vti.RegClass:$rs1)))),
658-
(riscv_vmset_vl X0),
659-
X0)),
658+
(riscv_vmset_vl VLOpFrag),
659+
VLOpFrag)),
660660
(!cast<Instruction>(instruction_name#"_WV_"#vti.Vti.LMul.MX)
661661
vti.Wti.RegClass:$rs2, vti.Vti.RegClass:$rs1,
662662
vti.Vti.AVL, vti.Vti.Log2SEW)>;
663-
}
664-
}
665-
666-
multiclass VPatBinarySDNodeExt_V_WX<SDNode op, PatFrags extop, string instruction_name> {
667-
foreach vti = AllWidenableIntVectors in {
668663
def : Pat<
669664
(vti.Vti.Vector
670665
(riscv_trunc_vector_vl
671666
(op (vti.Wti.Vector vti.Wti.RegClass:$rs2),
672667
(vti.Wti.Vector (extop (vti.Vti.Vector (SplatPat GPR:$rs1))))),
673-
(riscv_vmset_vl X0),
674-
X0)),
668+
(riscv_vmset_vl VLOpFrag),
669+
VLOpFrag)),
675670
(!cast<Instruction>(instruction_name#"_WX_"#vti.Vti.LMul.MX)
676671
vti.Wti.RegClass:$rs2, GPR:$rs1,
677672
vti.Vti.AVL, vti.Vti.Log2SEW)>;
678673
}
679674
}
680675

681-
682-
multiclass VPatBinarySDNode_V_WV<SDNode op, string instruction_name> {
683-
defm : VPatBinarySDNodeExt_V_WV<op, sext_oneuse, instruction_name>;
684-
defm : VPatBinarySDNodeExt_V_WV<op, zext_oneuse, instruction_name>;
685-
}
686-
687-
multiclass VPatBinarySDNode_V_WX<SDNode op, string instruction_name> {
688-
defm : VPatBinarySDNodeExt_V_WX<op, sext_oneuse, instruction_name>;
689-
defm : VPatBinarySDNodeExt_V_WX<op, zext_oneuse, instruction_name>;
676+
multiclass VPatBinarySDNode_V_WV_WX_WI<SDNode op, string instruction_name> {
677+
defm : VPatBinarySDNodeExt_V_WV_WX<op, sext_oneuse, instruction_name>;
678+
defm : VPatBinarySDNodeExt_V_WV_WX<op, zext_oneuse, instruction_name>;
679+
foreach vti = AllWidenableIntVectors in {
680+
def : Pat<
681+
(vti.Vti.Vector
682+
(riscv_trunc_vector_vl
683+
(op (vti.Wti.Vector vti.Wti.RegClass:$rs2),
684+
(vti.Wti.Vector (SplatPat_uimm5 uimm5:$rs1))),
685+
(riscv_vmset_vl VLOpFrag),
686+
VLOpFrag)),
687+
(!cast<Instruction>(instruction_name#"_WI_"#vti.Vti.LMul.MX)
688+
vti.Wti.RegClass:$rs2, uimm5:$rs1,
689+
vti.Vti.AVL, vti.Vti.Log2SEW)>;
690+
}
690691
}
691692

692693
multiclass VPatWidenReductionVL<SDNode vop, PatFrags extop, string instruction_name, bit is_float> {
@@ -796,10 +797,8 @@ foreach vti = AllIntegerVectors in {
796797
}
797798

798799
// 12.7. Vector Narrowing Integer Right Shift Instructions
799-
defm : VPatBinarySDNode_V_WV<srl, "PseudoVNSRL">;
800-
defm : VPatBinarySDNode_V_WX<srl, "PseudoVNSRL">;
801-
defm : VPatBinarySDNode_V_WV<sra, "PseudoVNSRA">;
802-
defm : VPatBinarySDNode_V_WX<sra, "PseudoVNSRA">;
800+
defm : VPatBinarySDNode_V_WV_WX_WI<srl, "PseudoVNSRL">;
801+
defm : VPatBinarySDNode_V_WV_WX_WI<sra, "PseudoVNSRA">;
803802

804803
foreach vtiTowti = AllWidenableIntVectors in {
805804
defvar vti = vtiTowti.Vti;

llvm/test/CodeGen/RISCV/rvv/constant-folding.ll

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,8 @@ define <2 x i16> @fixedlen(<2 x i32> %x) {
4848
define <vscale x 2 x i16> @scalable(<vscale x 2 x i32> %x) {
4949
; CHECK-LABEL: scalable:
5050
; CHECK: # %bb.0:
51-
; CHECK-NEXT: vsetvli a0, zero, e32, m1, ta, mu
52-
; CHECK-NEXT: vsrl.vi v8, v8, 16
53-
; CHECK-NEXT: vsetvli zero, zero, e16, mf2, ta, mu
54-
; CHECK-NEXT: vnsrl.wx v8, v8, zero
51+
; CHECK-NEXT: vsetvli a0, zero, e16, mf2, ta, mu
52+
; CHECK-NEXT: vnsrl.wi v8, v8, 16
5553
; CHECK-NEXT: lui a0, 1048568
5654
; CHECK-NEXT: vand.vx v8, v8, a0
5755
; CHECK-NEXT: ret

0 commit comments

Comments
 (0)