@@ -44,11 +44,17 @@ class RISCVInstructionSelector : public InstructionSelector {
44
44
const TargetRegisterClass *
45
45
getRegClassForTypeOnBank (LLT Ty, const RegisterBank &RB) const ;
46
46
47
+ // tblgen-erated 'select' implementation, used as the initial selector for
48
+ // the patterns that don't require complex C++.
47
49
bool selectImpl (MachineInstr &I, CodeGenCoverage &CoverageInfo) const ;
50
+
51
+ // Custom selection methods
48
52
bool selectCopy (MachineInstr &MI, MachineRegisterInfo &MRI) const ;
49
53
bool selectConstant (MachineInstr &MI, MachineIRBuilder &MIB,
50
54
MachineRegisterInfo &MRI) const ;
51
55
bool selectSExtInreg (MachineInstr &MI, MachineIRBuilder &MIB) const ;
56
+ bool selectSelect (MachineInstr &MI, MachineIRBuilder &MIB,
57
+ MachineRegisterInfo &MRI) const ;
52
58
53
59
bool earlySelectShift (unsigned Opc, MachineInstr &I, MachineIRBuilder &MIB,
54
60
const MachineRegisterInfo &MRI);
@@ -239,6 +245,8 @@ bool RISCVInstructionSelector::select(MachineInstr &MI) {
239
245
}
240
246
case TargetOpcode::G_SEXT_INREG:
241
247
return selectSExtInreg (MI, MIB);
248
+ case TargetOpcode::G_SELECT:
249
+ return selectSelect (MI, MIB, MRI);
242
250
default :
243
251
return false ;
244
252
}
@@ -376,6 +384,27 @@ bool RISCVInstructionSelector::selectSExtInreg(MachineInstr &MI,
376
384
return true ;
377
385
}
378
386
387
+ bool RISCVInstructionSelector::selectSelect (MachineInstr &MI,
388
+ MachineIRBuilder &MIB,
389
+ MachineRegisterInfo &MRI) const {
390
+ // TODO: Currently we check that the conditional code passed to G_SELECT is
391
+ // not equal to zero; however, in the future, we might want to try and check
392
+ // if the conditional code comes from a G_ICMP. If it does, we can directly
393
+ // use G_ICMP to get the first three input operands of the
394
+ // Select_GPR_Using_CC_GPR. This might be done here, or in the appropriate
395
+ // combiner.
396
+ assert (MI.getOpcode () == TargetOpcode::G_SELECT);
397
+ MachineInstr *Result = MIB.buildInstr (RISCV::Select_GPR_Using_CC_GPR)
398
+ .addDef (MI.getOperand (0 ).getReg ())
399
+ .addReg (MI.getOperand (1 ).getReg ())
400
+ .addReg (RISCV::X0)
401
+ .addImm (RISCVCC::COND_NE)
402
+ .addReg (MI.getOperand (2 ).getReg ())
403
+ .addReg (MI.getOperand (3 ).getReg ());
404
+ MI.eraseFromParent ();
405
+ return constrainSelectedInstRegOperands (*Result, TII, TRI, RBI);
406
+ }
407
+
379
408
namespace llvm {
380
409
InstructionSelector *
381
410
createRISCVInstructionSelector (const RISCVTargetMachine &TM,
0 commit comments