Skip to content

Commit 80f510b

Browse files
[RISCV] Use lookup tables to find CVTFOpc
1 parent cdc3931 commit 80f510b

File tree

2 files changed

+18
-77
lines changed

2 files changed

+18
-77
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 15 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -17787,6 +17787,18 @@ static MachineBasicBlock *emitSelectPseudo(MachineInstr &MI,
1778717787
return TailMBB;
1778817788
}
1778917789

17790+
// Helper to find Masked Pseudo instruction from MC instruction, LMUL and SEW.
17791+
static const RISCV::RISCVMaskedPseudoInfo *
17792+
lookupMaskedIntrinsic(uint16_t MCOpcode, RISCVII::VLMUL LMul, unsigned SEW) {
17793+
const RISCVVInversePseudosTable::PseudoInfo *Inverse =
17794+
RISCVVInversePseudosTable::getBaseInfo(MCOpcode, LMul, SEW);
17795+
assert(Inverse && "Unexpected LMUL and SEW pair for instruction");
17796+
const RISCV::RISCVMaskedPseudoInfo *Masked =
17797+
RISCV::lookupMaskedIntrinsicByUnmasked(Inverse->Pseudo);
17798+
assert(Masked && "Could not find masked instruction for LMUL and SEW pair");
17799+
return Masked;
17800+
}
17801+
1779017802
static MachineBasicBlock *emitVFROUND_NOEXCEPT_MASK(MachineInstr &MI,
1779117803
MachineBasicBlock *BB,
1779217804
unsigned CVTXOpc) {
@@ -17824,80 +17836,9 @@ static MachineBasicBlock *emitVFROUND_NOEXCEPT_MASK(MachineInstr &MI,
1782417836
unsigned Log2SEW = MI.getOperand(RISCVII::getSEWOpNum(MI.getDesc())).getImm();
1782517837
// There is no E8 variant for VFCVT_F_X.
1782617838
assert(Log2SEW >= 4);
17827-
// Since MI (VFROUND) isn't SEW specific, we cannot use a macro to make
17828-
// handling of different (LMUL, SEW) pairs easier because we need to pull the
17829-
// SEW immediate from MI, and that information is not avaliable during macro
17830-
// expansion.
17831-
unsigned CVTFOpc;
17832-
if (Log2SEW == 4) {
17833-
switch (LMul) {
17834-
case RISCVII::LMUL_1:
17835-
CVTFOpc = RISCV::PseudoVFCVT_F_X_V_M1_E16_MASK;
17836-
break;
17837-
case RISCVII::LMUL_2:
17838-
CVTFOpc = RISCV::PseudoVFCVT_F_X_V_M2_E16_MASK;
17839-
break;
17840-
case RISCVII::LMUL_4:
17841-
CVTFOpc = RISCV::PseudoVFCVT_F_X_V_M4_E16_MASK;
17842-
break;
17843-
case RISCVII::LMUL_8:
17844-
CVTFOpc = RISCV::PseudoVFCVT_F_X_V_M8_E16_MASK;
17845-
break;
17846-
case RISCVII::LMUL_F2:
17847-
CVTFOpc = RISCV::PseudoVFCVT_F_X_V_MF2_E16_MASK;
17848-
break;
17849-
case RISCVII::LMUL_F4:
17850-
CVTFOpc = RISCV::PseudoVFCVT_F_X_V_MF4_E16_MASK;
17851-
break;
17852-
case RISCVII::LMUL_F8:
17853-
case RISCVII::LMUL_RESERVED:
17854-
llvm_unreachable("Unexpected LMUL and SEW combination value for MI.");
17855-
}
17856-
} else if (Log2SEW == 5) {
17857-
switch (LMul) {
17858-
case RISCVII::LMUL_1:
17859-
CVTFOpc = RISCV::PseudoVFCVT_F_X_V_M1_E32_MASK;
17860-
break;
17861-
case RISCVII::LMUL_2:
17862-
CVTFOpc = RISCV::PseudoVFCVT_F_X_V_M2_E32_MASK;
17863-
break;
17864-
case RISCVII::LMUL_4:
17865-
CVTFOpc = RISCV::PseudoVFCVT_F_X_V_M4_E32_MASK;
17866-
break;
17867-
case RISCVII::LMUL_8:
17868-
CVTFOpc = RISCV::PseudoVFCVT_F_X_V_M8_E32_MASK;
17869-
break;
17870-
case RISCVII::LMUL_F2:
17871-
CVTFOpc = RISCV::PseudoVFCVT_F_X_V_MF2_E32_MASK;
17872-
break;
17873-
case RISCVII::LMUL_F4:
17874-
case RISCVII::LMUL_F8:
17875-
case RISCVII::LMUL_RESERVED:
17876-
llvm_unreachable("Unexpected LMUL and SEW combination value for MI.");
17877-
}
17878-
} else if (Log2SEW == 6) {
17879-
switch (LMul) {
17880-
case RISCVII::LMUL_1:
17881-
CVTFOpc = RISCV::PseudoVFCVT_F_X_V_M1_E64_MASK;
17882-
break;
17883-
case RISCVII::LMUL_2:
17884-
CVTFOpc = RISCV::PseudoVFCVT_F_X_V_M2_E64_MASK;
17885-
break;
17886-
case RISCVII::LMUL_4:
17887-
CVTFOpc = RISCV::PseudoVFCVT_F_X_V_M4_E64_MASK;
17888-
break;
17889-
case RISCVII::LMUL_8:
17890-
CVTFOpc = RISCV::PseudoVFCVT_F_X_V_M8_E64_MASK;
17891-
break;
17892-
case RISCVII::LMUL_F2:
17893-
case RISCVII::LMUL_F4:
17894-
case RISCVII::LMUL_F8:
17895-
case RISCVII::LMUL_RESERVED:
17896-
llvm_unreachable("Unexpected LMUL and SEW combination value for MI.");
17897-
}
17898-
} else {
17899-
llvm_unreachable("Unexpected LMUL and SEW combination value for MI.");
17900-
}
17839+
unsigned CVTFOpc =
17840+
lookupMaskedIntrinsic(RISCV::VFCVT_F_X_V, LMul, 1 << Log2SEW)
17841+
->MaskedPseudo;
1790117842

1790217843
BuildMI(*BB, MI, DL, TII.get(CVTFOpc))
1790317844
.add(MI.getOperand(0))

llvm/lib/Target/RISCV/RISCVInstrInfoVPseudos.td

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3593,7 +3593,7 @@ multiclass VPseudoConversion<VReg RetClass,
35933593
int sew = 0,
35943594
int TargetConstraintType = 1> {
35953595
defvar suffix = !if(sew, "_" # MInfo.MX # "_E" # sew, "_" # MInfo.MX);
3596-
let VLMul = MInfo.value in {
3596+
let VLMul = MInfo.value, SEW=sew in {
35973597
def suffix : VPseudoUnaryNoMask<RetClass, Op1Class, Constraint, TargetConstraintType>;
35983598
def suffix # "_MASK" : VPseudoUnaryMask<RetClass, Op1Class,
35993599
Constraint, TargetConstraintType>,
@@ -3607,7 +3607,7 @@ multiclass VPseudoConversionRoundingMode<VReg RetClass,
36073607
string Constraint = "",
36083608
int sew = 0,
36093609
int TargetConstraintType = 1> {
3610-
let VLMul = MInfo.value in {
3610+
let VLMul = MInfo.value, SEW=sew in {
36113611
defvar suffix = !if(sew, "_" # MInfo.MX # "_E" # sew, "_" # MInfo.MX);
36123612
def suffix : VPseudoUnaryNoMaskRoundingMode<RetClass, Op1Class, Constraint, TargetConstraintType>;
36133613
def suffix # "_MASK" : VPseudoUnaryMaskRoundingMode<RetClass, Op1Class,
@@ -3624,7 +3624,7 @@ multiclass VPseudoConversionRM<VReg RetClass,
36243624
string Constraint = "",
36253625
int sew = 0,
36263626
int TargetConstraintType = 1> {
3627-
let VLMul = MInfo.value in {
3627+
let VLMul = MInfo.value, SEW=sew in {
36283628
defvar suffix = !if(sew, "_" # MInfo.MX # "_E" # sew, "_" # MInfo.MX);
36293629
def suffix : VPseudoUnaryNoMask_FRM<RetClass, Op1Class,
36303630
Constraint, TargetConstraintType>;

0 commit comments

Comments
 (0)