Skip to content

Commit 6262d67

Browse files
authored
[RISCV] Check subtarget feature in getBrCond (#129859)
The function currently only checks to see if 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. It would be better if we explicitly check if the XCVbi extension is enabled before returning 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 0228b77 commit 6262d67

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,7 @@ 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(STI, CC), {}, {LHS, RHS})
793793
.addMBB(MI.getOperand(1).getMBB());
794794
MI.eraseFromParent();
795795
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(const RISCVSubtarget &STI, RISCVCC::CondCode CC,
957+
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)
963+
return RISCV::BEQ;
964+
if (STI.hasVendorXCVbi())
965+
return RISCV::CV_BEQIMM;
966+
llvm_unreachable("Unknown branch immediate!");
962967
case RISCVCC::COND_NE:
963-
return Imm ? RISCV::CV_BNEIMM : RISCV::BNE;
968+
if (!Imm)
969+
return RISCV::BNE;
970+
if (STI.hasVendorXCVbi())
971+
return RISCV::CV_BNEIMM;
972+
llvm_unreachable("Unknown branch immediate!");
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(STI, CC, Imm));
978987
}
979988

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

llvm/lib/Target/RISCV/RISCVInstrInfo.h

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

4747
CondCode getOppositeBranchCondition(CondCode);
48-
unsigned getBrCond(CondCode CC, bool Imm = false);
48+
unsigned getBrCond(const RISCVSubtarget &STI, CondCode CC, bool Imm = false);
4949

5050
} // end of namespace RISCVCC
5151

0 commit comments

Comments
 (0)