Skip to content

Commit 60be17a

Browse files
committed
[RISCV] Add VFCVT pseudos with no mask
When emitting a vfcvt with a rounding mode, we end up generating an unnecessary vmset because the only rounding mode pseudos have a mask operand. This patch adds a pseudo without a mask, and marks the masked variant with the MaskedPseudo class so the doPeepholeMergeVMV optimisation knows to remove the redundant vmset. Reviewed By: reames Differential Revision: https://reviews.llvm.org/D154266
1 parent a9e5773 commit 60be17a

File tree

9 files changed

+355
-504
lines changed

9 files changed

+355
-504
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13795,29 +13795,29 @@ static MachineBasicBlock *emitSelectPseudo(MachineInstr &MI,
1379513795
return TailMBB;
1379613796
}
1379713797

13798-
static MachineBasicBlock *
13799-
emitVFCVT_RM_MASK(MachineInstr &MI, MachineBasicBlock *BB, unsigned Opcode) {
13798+
static MachineBasicBlock *emitVFCVT_RM(MachineInstr &MI, MachineBasicBlock *BB,
13799+
unsigned Opcode) {
1380013800
DebugLoc DL = MI.getDebugLoc();
1380113801

1380213802
const TargetInstrInfo &TII = *BB->getParent()->getSubtarget().getInstrInfo();
1380313803

1380413804
MachineRegisterInfo &MRI = BB->getParent()->getRegInfo();
1380513805
Register SavedFRM = MRI.createVirtualRegister(&RISCV::GPRRegClass);
1380613806

13807+
assert(MI.getNumOperands() == 8 || MI.getNumOperands() == 7);
13808+
unsigned FRMIdx = MI.getNumOperands() == 8 ? 4 : 3;
13809+
1380713810
// Update FRM and save the old value.
1380813811
BuildMI(*BB, MI, DL, TII.get(RISCV::SwapFRMImm), SavedFRM)
13809-
.addImm(MI.getOperand(4).getImm());
13812+
.addImm(MI.getOperand(FRMIdx).getImm());
1381013813

1381113814
// Emit an VFCVT without the FRM operand.
13812-
assert(MI.getNumOperands() == 8);
13813-
auto MIB = BuildMI(*BB, MI, DL, TII.get(Opcode))
13814-
.add(MI.getOperand(0))
13815-
.add(MI.getOperand(1))
13816-
.add(MI.getOperand(2))
13817-
.add(MI.getOperand(3))
13818-
.add(MI.getOperand(5))
13819-
.add(MI.getOperand(6))
13820-
.add(MI.getOperand(7));
13815+
auto MIB = BuildMI(*BB, MI, DL, TII.get(Opcode));
13816+
13817+
for (unsigned I = 0; I < MI.getNumOperands(); I++)
13818+
if (I != FRMIdx)
13819+
MIB = MIB.add(MI.getOperand(I));
13820+
1382113821
if (MI.getFlag(MachineInstr::MIFlag::NoFPExcept))
1382213822
MIB->setFlag(MachineInstr::MIFlag::NoFPExcept);
1382313823

@@ -14067,8 +14067,10 @@ RISCVTargetLowering::EmitInstrWithCustomInserter(MachineInstr &MI,
1406714067
Subtarget);
1406814068

1406914069
#define PseudoVFCVT_RM_LMUL_CASE(RMOpc, Opc, LMUL) \
14070+
case RISCV::RMOpc##_##LMUL: \
14071+
return emitVFCVT_RM(MI, BB, RISCV::Opc##_##LMUL); \
1407014072
case RISCV::RMOpc##_##LMUL##_MASK: \
14071-
return emitVFCVT_RM_MASK(MI, BB, RISCV::Opc##_##LMUL##_MASK);
14073+
return emitVFCVT_RM(MI, BB, RISCV::Opc##_##LMUL##_MASK);
1407214074

1407314075
#define PseudoVFCVT_RM_CASE(RMOpc, Opc) \
1407414076
PseudoVFCVT_RM_LMUL_CASE(RMOpc, Opc, M1) \

llvm/lib/Target/RISCV/RISCVInstrInfoVPseudos.td

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1054,6 +1054,20 @@ class VPseudoUnaryMask_NoExcept<VReg RetClass, VReg OpClass, string Constraint =
10541054
let usesCustomInserter = 1;
10551055
}
10561056

1057+
class VPseudoUnaryNoMask_FRM<VReg RetClass, VReg OpClass, string Constraint = ""> :
1058+
Pseudo<(outs RetClass:$rd),
1059+
(ins RetClass:$merge, OpClass:$rs2, ixlenimm:$frm, AVL:$vl,
1060+
ixlenimm:$sew, ixlenimm:$policy), []> {
1061+
let mayLoad = 0;
1062+
let mayStore = 0;
1063+
let hasSideEffects = 0;
1064+
let Constraints = !interleave([Constraint, "$rd = $merge"], ",");
1065+
let HasVLOp = 1;
1066+
let HasSEWOp = 1;
1067+
let HasVecPolicyOp = 1;
1068+
let usesCustomInserter = 1;
1069+
}
1070+
10571071
class VPseudoUnaryMask_FRM<VReg RetClass, VReg OpClass, string Constraint = ""> :
10581072
Pseudo<(outs GetVRegNoV0<RetClass>.R:$rd),
10591073
(ins GetVRegNoV0<RetClass>.R:$merge, OpClass:$rs2,
@@ -3515,8 +3529,13 @@ multiclass VPseudoConversionRM<VReg RetClass,
35153529
LMULInfo MInfo,
35163530
string Constraint = ""> {
35173531
let VLMul = MInfo.value in {
3518-
def "_" # MInfo.MX # "_MASK" : VPseudoUnaryMask_FRM<RetClass, Op1Class,
3532+
def "_" # MInfo.MX : VPseudoUnaryNoMask_FRM<RetClass, Op1Class,
35193533
Constraint>;
3534+
def "_" # MInfo.MX # "_MASK" : VPseudoUnaryMask_FRM<RetClass, Op1Class,
3535+
Constraint>,
3536+
RISCVMaskedPseudo</*MaskOpIdx*/ 2,
3537+
/*HasTU*/ false,
3538+
/*IsCombined*/true>;
35203539
}
35213540
}
35223541

0 commit comments

Comments
 (0)