Skip to content

Commit b8014b5

Browse files
authored
[RISCV][GISel] Simplify selectSelect. NFC (#70846)
Use GSelect and reduce number of temporaries.
1 parent 11529d5 commit b8014b5

File tree

1 file changed

+14
-17
lines changed

1 file changed

+14
-17
lines changed

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

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -776,27 +776,24 @@ static void getICMPOperandsForBranch(MachineInstr &MI, MachineIRBuilder &MIB,
776776
bool RISCVInstructionSelector::selectSelect(MachineInstr &MI,
777777
MachineIRBuilder &MIB,
778778
MachineRegisterInfo &MRI) const {
779-
assert(MI.getOpcode() == TargetOpcode::G_SELECT);
779+
auto &SelectMI = cast<GSelect>(MI);
780780

781781
// If MI is a G_SELECT(G_ICMP(tst, A, B), C, D) then we can use (A, B, tst)
782782
// as the (LHS, RHS, CC) of the Select_GPR_Using_CC_GPR.
783-
Register MIOp1Reg = MI.getOperand(1).getReg();
784-
bool Op1IsICMP = mi_match(MIOp1Reg, MRI, m_GICmp(m_Pred(), m_Reg(), m_Reg()));
785-
RISCVCC::CondCode CC;
786-
Register LHS, RHS;
787-
if (Op1IsICMP)
788-
getICMPOperandsForBranch(*MRI.getVRegDef(MIOp1Reg), MIB, MRI, CC, LHS, RHS);
789-
790-
Register Op1 = Op1IsICMP ? LHS : MI.getOperand(1).getReg();
791-
Register Op2 = Op1IsICMP ? RHS : RISCV::X0;
792-
unsigned Op3 = Op1IsICMP ? CC : RISCVCC::COND_NE;
783+
Register LHS = SelectMI.getCondReg();
784+
Register RHS = RISCV::X0;
785+
RISCVCC::CondCode CC = RISCVCC::COND_NE;
786+
787+
if (mi_match(LHS, MRI, m_GICmp(m_Pred(), m_Reg(), m_Reg())))
788+
getICMPOperandsForBranch(*MRI.getVRegDef(LHS), MIB, MRI, CC, LHS, RHS);
789+
793790
MachineInstr *Result = MIB.buildInstr(RISCV::Select_GPR_Using_CC_GPR)
794-
.addDef(MI.getOperand(0).getReg())
795-
.addReg(Op1)
796-
.addReg(Op2)
797-
.addImm(Op3)
798-
.addReg(MI.getOperand(2).getReg())
799-
.addReg(MI.getOperand(3).getReg());
791+
.addDef(SelectMI.getReg(0))
792+
.addReg(LHS)
793+
.addReg(RHS)
794+
.addImm(CC)
795+
.addReg(SelectMI.getTrueReg())
796+
.addReg(SelectMI.getFalseReg());
800797
MI.eraseFromParent();
801798
return constrainSelectedInstRegOperands(*Result, TII, TRI, RBI);
802799
}

0 commit comments

Comments
 (0)