Skip to content

Commit a755e80

Browse files
committed
[RISCV] Add codegen for the experimental zicond extension
This directly matches the codegen for xventanacondops with vt.maskcn => czero.nez and vt.maskc => czero.eqz. An additional difference is that zicond is available on RV32 in addition to RV64 (xventanacondops is RV64 only). Differential Revision: https://reviews.llvm.org/D147147
1 parent 1190a1d commit a755e80

File tree

5 files changed

+1784
-225
lines changed

5 files changed

+1784
-225
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ RISCVTargetLowering::RISCVTargetLowering(const TargetMachine &TM,
324324
if (Subtarget.is64Bit())
325325
setOperationAction(ISD::ABS, MVT::i32, Custom);
326326

327-
if (!Subtarget.hasVendorXVentanaCondOps() &&
327+
if (!Subtarget.hasStdExtZicond() && !Subtarget.hasVendorXVentanaCondOps() &&
328328
!Subtarget.hasVendorXTHeadCondMov())
329329
setOperationAction(ISD::SELECT, XLenVT, Custom);
330330

llvm/lib/Target/RISCV/RISCVInstrInfoZicond.td

+36
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,39 @@ def CZERO_EQZ : ALU_rr<0b0000111, 0b101, "czero.eqz">,
2323
def CZERO_NEZ : ALU_rr<0b0000111, 0b111, "czero.nez">,
2424
Sched<[WriteIALU, ReadIALU, ReadIALU]>;
2525
} // Predicates = [HasStdExtZicond]
26+
27+
//===----------------------------------------------------------------------===//
28+
// Pseudo-instructions and codegen patterns
29+
//===----------------------------------------------------------------------===//
30+
31+
let Predicates = [HasStdExtZicond] in {
32+
// Directly use CZERO_EQZ/CZERO_NEZ in case of any of the operands being 0.
33+
def : Pat<(select GPR:$rc, GPR:$rs1, 0),
34+
(CZERO_EQZ GPR:$rs1, GPR:$rc)>;
35+
def : Pat<(select GPR:$rc, 0, GPR:$rs1),
36+
(CZERO_NEZ GPR:$rs1, GPR:$rc)>;
37+
38+
def : Pat<(select (riscv_setne GPR:$rc), GPR:$rs1, 0),
39+
(CZERO_EQZ GPR:$rs1, GPR:$rc)>;
40+
def : Pat<(select (riscv_seteq GPR:$rc), GPR:$rs1, 0),
41+
(CZERO_NEZ GPR:$rs1, GPR:$rc)>;
42+
def : Pat<(select (riscv_setne GPR:$rc), 0, GPR:$rs1),
43+
(CZERO_NEZ GPR:$rs1, GPR:$rc)>;
44+
def : Pat<(select (riscv_seteq GPR:$rc), 0, GPR:$rs1),
45+
(CZERO_EQZ GPR:$rs1, GPR:$rc)>;
46+
47+
// Conditional AND operation patterns.
48+
def : Pat<(select GPR:$rc, (and GPR:$rs1, GPR:$rs2), GPR:$rs1),
49+
(OR (AND $rs1, $rs2), (CZERO_NEZ $rs1, $rc))>;
50+
def : Pat<(select GPR:$rc, GPR:$rs1, (and GPR:$rs1, GPR:$rs2)),
51+
(OR (AND $rs1, $rs2), (CZERO_EQZ $rs1, $rc))>;
52+
53+
// Basic select pattern that selects between 2 registers.
54+
def : Pat<(select GPR:$rc, GPR:$rs1, GPR:$rs2),
55+
(OR (CZERO_EQZ $rs1, $rc), (CZERO_NEZ $rs2, $rc))>;
56+
57+
def : Pat<(select (riscv_setne GPR:$rc), GPR:$rs1, GPR:$rs2),
58+
(OR (CZERO_EQZ GPR:$rs1, GPR:$rc), (CZERO_NEZ GPR:$rs2, GPR:$rc))>;
59+
def : Pat<(select (riscv_seteq GPR:$rc), GPR:$rs2, GPR:$rs1),
60+
(OR (CZERO_EQZ GPR:$rs1, GPR:$rc), (CZERO_NEZ GPR:$rs2, GPR:$rc))>;
61+
} // Predicates = [HasStdExtZicond]

0 commit comments

Comments
 (0)