Skip to content

Commit 53c6f1d

Browse files
committed
[RISCV] Check feature bits in getBrCond
The function currently only checks to see if the we compare against an immediate before selecting the two branch immediate instructions that are a part of the XCVbi vendor extension. This works at the moment since there are no other extensions that have a branch immediate instruction but it would be better if we explicitly check to see if the XCVbi extension is enabled before we return the appropriate instruction. This is also done in preparation for the branch immediate instructions that are a part of the Xqcibi vendor extension from Qualcomm.
1 parent f4878cb commit 53c6f1d

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

llvm/lib/Target/RISCV/GISel/RISCVInstructionSelector.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,8 @@ bool RISCVInstructionSelector::select(MachineInstr &MI) {
789789
RISCVCC::CondCode CC;
790790
getOperandsForBranch(MI.getOperand(0).getReg(), CC, LHS, RHS, *MRI);
791791

792-
auto Bcc = MIB.buildInstr(RISCVCC::getBrCond(CC), {}, {LHS, RHS})
792+
auto Bcc = MIB.buildInstr(RISCVCC::getBrCond(CC, STI.getFeatureBits()), {},
793+
{LHS, RHS})
793794
.addMBB(MI.getOperand(1).getMBB());
794795
MI.eraseFromParent();
795796
return constrainSelectedInstRegOperands(*Bcc, TII, TRI, RBI);

llvm/lib/Target/RISCV/RISCVInstrInfo.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -953,14 +953,23 @@ static void parseCondBranch(MachineInstr &LastInst, MachineBasicBlock *&Target,
953953
Cond.push_back(LastInst.getOperand(1));
954954
}
955955

956-
unsigned RISCVCC::getBrCond(RISCVCC::CondCode CC, bool Imm) {
956+
unsigned RISCVCC::getBrCond(RISCVCC::CondCode CC,
957+
const FeatureBitset &FeatureBits, bool Imm) {
957958
switch (CC) {
958959
default:
959960
llvm_unreachable("Unknown condition code!");
960961
case RISCVCC::COND_EQ:
961-
return Imm ? RISCV::CV_BEQIMM : RISCV::BEQ;
962+
if (Imm && FeatureBits[RISCV::FeatureVendorXCVbi])
963+
return RISCV::CV_BEQIMM;
964+
else
965+
llvm_unreachable("Unknown branch immediate!");
966+
return RISCV::BEQ;
962967
case RISCVCC::COND_NE:
963-
return Imm ? RISCV::CV_BNEIMM : RISCV::BNE;
968+
if (Imm && FeatureBits[RISCV::FeatureVendorXCVbi])
969+
return RISCV::CV_BNEIMM;
970+
else
971+
llvm_unreachable("Unknown branch immediate!");
972+
return RISCV::BNE;
964973
case RISCVCC::COND_LT:
965974
return RISCV::BLT;
966975
case RISCVCC::COND_GE:
@@ -974,7 +983,7 @@ unsigned RISCVCC::getBrCond(RISCVCC::CondCode CC, bool Imm) {
974983

975984
const MCInstrDesc &RISCVInstrInfo::getBrCond(RISCVCC::CondCode CC,
976985
bool Imm) const {
977-
return get(RISCVCC::getBrCond(CC, Imm));
986+
return get(RISCVCC::getBrCond(CC, STI.getFeatureBits(), Imm));
978987
}
979988

980989
RISCVCC::CondCode RISCVCC::getOppositeBranchCondition(RISCVCC::CondCode CC) {

llvm/lib/Target/RISCV/RISCVInstrInfo.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ enum CondCode {
4545
};
4646

4747
CondCode getOppositeBranchCondition(CondCode);
48-
unsigned getBrCond(CondCode CC, bool Imm = false);
48+
unsigned getBrCond(CondCode CC, const FeatureBitset &FeatureBits,
49+
bool Imm = false);
4950

5051
} // end of namespace RISCVCC
5152

0 commit comments

Comments
 (0)