Index: lib/Target/Mips/MipsFastISel.cpp =================================================================== --- lib/Target/Mips/MipsFastISel.cpp +++ lib/Target/Mips/MipsFastISel.cpp @@ -94,6 +94,7 @@ bool selectLoad(const Instruction *I); bool selectStore(const Instruction *I); bool selectBranch(const Instruction *I); + bool selectSelect(const Instruction *I); bool selectCmp(const Instruction *I); bool selectFPExt(const Instruction *I); bool selectFPTrunc(const Instruction *I); @@ -910,6 +911,59 @@ return true; } +bool MipsFastISel::selectSelect(const Instruction *I) { + assert(isa(I) && "Expected a select instruction."); + MVT VT; + if (!isTypeSupported(I->getType(), VT)) + return false; + + unsigned CondMovOpc; + const TargetRegisterClass *RC; + switch (VT.SimpleTy) { + default: + return false; + case MVT::i1: + case MVT::i8: + case MVT::i16: + case MVT::i32: + CondMovOpc = Mips::MOVN_I_I; + RC = &Mips::GPR32RegClass; + break; + case MVT::f32: + CondMovOpc = Mips::MOVN_I_S; + RC = &Mips::FGR32RegClass; + break; + case MVT::f64: + CondMovOpc = Mips::MOVN_I_D32; + RC = &Mips::AFGR64RegClass; + break; + } + + const SelectInst *SI = cast(I); + const Value *Cond = SI->getCondition(); + (void)Cond; + unsigned Src1Reg = getRegForValue(SI->getTrueValue()); + unsigned Src2Reg = getRegForValue(SI->getFalseValue()); + unsigned CondReg = getRegForValue(Cond); + + if (!Src1Reg || !Src2Reg || !CondReg) + return false; + + unsigned ResultReg = createResultReg(RC); + unsigned TempReg = createResultReg(RC); + + if (!ResultReg || !TempReg) + return false; + emitInst(TargetOpcode::COPY, TempReg).addReg(Src2Reg); + MachineInstrBuilder MI = emitInst(CondMovOpc, ResultReg) + .addReg(Src1Reg) + .addReg(CondReg) + .addReg(TempReg, RegState::Implicit); + MI->tieOperands(0, 3); + updateValueMap(I, ResultReg); + return true; +} + // Attempt to fast-select a floating-point truncate instruction. bool MipsFastISel::selectFPTrunc(const Instruction *I) { if (UnsupportedFPMode) @@ -1567,6 +1621,8 @@ case Instruction::ICmp: case Instruction::FCmp: return selectCmp(I); + case Instruction::Select: + return selectSelect(I); } return false; }