Skip to content

Commit 27f8f9e

Browse files
authored
[RISCV][CodeGen] Add CodeGen support of Zibi experimental extension (#146858)
This adds the CodeGen support of Zibi v0.1 experimental extension, which depends on #127463.
1 parent e03a7c1 commit 27f8f9e

File tree

5 files changed

+488
-0
lines changed

5 files changed

+488
-0
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22494,6 +22494,7 @@ RISCVTargetLowering::EmitInstrWithCustomInserter(MachineInstr &MI,
2249422494
"ReadCounterWide is only to be used on riscv32");
2249522495
return emitReadCounterWidePseudo(MI, BB);
2249622496
case RISCV::Select_GPR_Using_CC_GPR:
22497+
case RISCV::Select_GPR_Using_CC_Imm5_Zibi:
2249722498
case RISCV::Select_GPR_Using_CC_SImm5_CV:
2249822499
case RISCV::Select_GPRNoX0_Using_CC_SImm5NonZero_QC:
2249922500
case RISCV::Select_GPRNoX0_Using_CC_UImm5NonZero_QC:

llvm/lib/Target/RISCV/RISCVInstrInfo.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -955,13 +955,15 @@ RISCVCC::CondCode RISCVInstrInfo::getCondFromBranchOpc(unsigned Opc) {
955955
default:
956956
return RISCVCC::COND_INVALID;
957957
case RISCV::BEQ:
958+
case RISCV::BEQI:
958959
case RISCV::CV_BEQIMM:
959960
case RISCV::QC_BEQI:
960961
case RISCV::QC_E_BEQI:
961962
case RISCV::NDS_BBC:
962963
case RISCV::NDS_BEQC:
963964
return RISCVCC::COND_EQ;
964965
case RISCV::BNE:
966+
case RISCV::BNEI:
965967
case RISCV::QC_BNEI:
966968
case RISCV::QC_E_BNEI:
967969
case RISCV::CV_BNEIMM:
@@ -1041,6 +1043,16 @@ unsigned RISCVCC::getBrCond(RISCVCC::CondCode CC, unsigned SelectOpc) {
10411043
return RISCV::BGEU;
10421044
}
10431045
break;
1046+
case RISCV::Select_GPR_Using_CC_Imm5_Zibi:
1047+
switch (CC) {
1048+
default:
1049+
llvm_unreachable("Unexpected condition code!");
1050+
case RISCVCC::COND_EQ:
1051+
return RISCV::BEQI;
1052+
case RISCVCC::COND_NE:
1053+
return RISCV::BNEI;
1054+
}
1055+
break;
10441056
case RISCV::Select_GPR_Using_CC_SImm5_CV:
10451057
switch (CC) {
10461058
default:
@@ -1359,9 +1371,15 @@ bool RISCVInstrInfo::reverseBranchCondition(
13591371
case RISCV::BEQ:
13601372
Cond[0].setImm(RISCV::BNE);
13611373
break;
1374+
case RISCV::BEQI:
1375+
Cond[0].setImm(RISCV::BNEI);
1376+
break;
13621377
case RISCV::BNE:
13631378
Cond[0].setImm(RISCV::BEQ);
13641379
break;
1380+
case RISCV::BNEI:
1381+
Cond[0].setImm(RISCV::BEQI);
1382+
break;
13651383
case RISCV::BLT:
13661384
Cond[0].setImm(RISCV::BGE);
13671385
break;
@@ -1611,6 +1629,8 @@ bool RISCVInstrInfo::isBranchOffsetInRange(unsigned BranchOp,
16111629
case RISCV::BGE:
16121630
case RISCV::BLTU:
16131631
case RISCV::BGEU:
1632+
case RISCV::BEQI:
1633+
case RISCV::BNEI:
16141634
case RISCV::CV_BEQIMM:
16151635
case RISCV::CV_BNEIMM:
16161636
case RISCV::QC_BEQI:
@@ -2859,6 +2879,9 @@ bool RISCVInstrInfo::verifyInstruction(const MachineInstr &MI,
28592879
case RISCVOp::OPERAND_FOUR:
28602880
Ok = Imm == 4;
28612881
break;
2882+
case RISCVOp::OPERAND_IMM5_ZIBI:
2883+
Ok = (isUInt<5>(Imm) && Imm != 0) || Imm == -1;
2884+
break;
28622885
// clang-format off
28632886
CASE_OPERAND_SIMM(5)
28642887
CASE_OPERAND_SIMM(6)

llvm/lib/Target/RISCV/RISCVInstrInfoZibi.td

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,24 @@ let Predicates = [HasStdExtZibi] in {
4242
def BEQI : Branch_imm<0b010, "beqi">;
4343
def BNEI : Branch_imm<0b011, "bnei">;
4444
} // Predicates = [HasStdExtZibi]
45+
46+
multiclass BccImmPat<CondCode Cond, Branch_imm Inst> {
47+
def : Pat<(riscv_brcc (XLenVT GPR:$rs1), imm5_zibi:$cimm, Cond, bb:$imm12),
48+
(Inst GPR:$rs1, imm5_zibi:$cimm, bare_simm13_lsb0_bb:$imm12)>;
49+
}
50+
51+
defm CC_Imm5_Zibi : SelectCC_GPR_riirr<GPR, imm5_zibi>;
52+
53+
class SelectZibi<CondCode Cond>
54+
: Pat<(riscv_selectcc_frag:$cc (XLenVT GPR:$lhs), imm5_zibi:$cimm, Cond,
55+
(XLenVT GPR:$truev), GPR:$falsev),
56+
(Select_GPR_Using_CC_Imm5_Zibi GPR:$lhs, imm5_zibi:$cimm,
57+
(IntCCtoRISCVCC $cc), GPR:$truev, GPR:$falsev)>;
58+
59+
let Predicates = [HasStdExtZibi] in {
60+
def : SelectZibi<SETEQ>;
61+
def : SelectZibi<SETNE>;
62+
63+
defm : BccImmPat<SETEQ, BEQI>;
64+
defm : BccImmPat<SETNE, BNEI>;
65+
} // Predicates = [HasStdExtZibi]

llvm/lib/Target/RISCV/RISCVInstrPredicates.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ def isSelectPseudo
4949
MCReturnStatement<
5050
CheckOpcode<[
5151
Select_GPR_Using_CC_GPR,
52+
Select_GPR_Using_CC_Imm5_Zibi,
5253
Select_GPR_Using_CC_SImm5_CV,
5354
Select_GPRNoX0_Using_CC_SImm5NonZero_QC,
5455
Select_GPRNoX0_Using_CC_UImm5NonZero_QC,

0 commit comments

Comments
 (0)