From 459b962a77c02d6f9fe298d01a0bef4ddf5e93e4 Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Fri, 9 Aug 2024 11:47:06 -0700 Subject: [PATCH] [RISCV] Move PseudoVSET(I)VLI expansion to use PseudoInstExpansion. (#102496) Instead of expanding in RISCVExpandPseudoInsts, expand during MachineInstr to MCInst lowering. We weren't doing anything in expansion other than copying operands. --- .../Target/RISCV/RISCVExpandPseudoInsts.cpp | 35 ------------------- .../Target/RISCV/RISCVInstrInfoVPseudos.td | 3 ++ 2 files changed, 3 insertions(+), 35 deletions(-) diff --git a/llvm/lib/Target/RISCV/RISCVExpandPseudoInsts.cpp b/llvm/lib/Target/RISCV/RISCVExpandPseudoInsts.cpp index d93709ac03420e9..9b9e870fb61d9c9 100644 --- a/llvm/lib/Target/RISCV/RISCVExpandPseudoInsts.cpp +++ b/llvm/lib/Target/RISCV/RISCVExpandPseudoInsts.cpp @@ -46,7 +46,6 @@ class RISCVExpandPseudo : public MachineFunctionPass { MachineBasicBlock::iterator &NextMBBI); bool expandCCOp(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, MachineBasicBlock::iterator &NextMBBI); - bool expandVSetVL(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI); bool expandVMSET_VMCLR(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, unsigned Opcode); bool expandRV32ZdinxStore(MachineBasicBlock &MBB, @@ -139,10 +138,6 @@ bool RISCVExpandPseudo::expandMI(MachineBasicBlock &MBB, case RISCV::PseudoCCORN: case RISCV::PseudoCCXNOR: return expandCCOp(MBB, MBBI, NextMBBI); - case RISCV::PseudoVSETVLI: - case RISCV::PseudoVSETVLIX0: - case RISCV::PseudoVSETIVLI: - return expandVSetVL(MBB, MBBI); case RISCV::PseudoVMCLR_M_B1: case RISCV::PseudoVMCLR_M_B2: case RISCV::PseudoVMCLR_M_B4: @@ -258,36 +253,6 @@ bool RISCVExpandPseudo::expandCCOp(MachineBasicBlock &MBB, return true; } -bool RISCVExpandPseudo::expandVSetVL(MachineBasicBlock &MBB, - MachineBasicBlock::iterator MBBI) { - assert(MBBI->getNumExplicitOperands() == 3 && MBBI->getNumOperands() >= 5 && - "Unexpected instruction format"); - - DebugLoc DL = MBBI->getDebugLoc(); - - assert((MBBI->getOpcode() == RISCV::PseudoVSETVLI || - MBBI->getOpcode() == RISCV::PseudoVSETVLIX0 || - MBBI->getOpcode() == RISCV::PseudoVSETIVLI) && - "Unexpected pseudo instruction"); - unsigned Opcode; - if (MBBI->getOpcode() == RISCV::PseudoVSETIVLI) - Opcode = RISCV::VSETIVLI; - else - Opcode = RISCV::VSETVLI; - const MCInstrDesc &Desc = TII->get(Opcode); - assert(Desc.getNumOperands() == 3 && "Unexpected instruction format"); - - Register DstReg = MBBI->getOperand(0).getReg(); - bool DstIsDead = MBBI->getOperand(0).isDead(); - BuildMI(MBB, MBBI, DL, Desc) - .addReg(DstReg, RegState::Define | getDeadRegState(DstIsDead)) - .add(MBBI->getOperand(1)) // VL - .add(MBBI->getOperand(2)); // VType - - MBBI->eraseFromParent(); // The pseudo instruction is gone now. - return true; -} - bool RISCVExpandPseudo::expandVMSET_VMCLR(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, unsigned Opcode) { diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfoVPseudos.td b/llvm/lib/Target/RISCV/RISCVInstrInfoVPseudos.td index c49066b06b83734..ab4d5a7e180df00 100644 --- a/llvm/lib/Target/RISCV/RISCVInstrInfoVPseudos.td +++ b/llvm/lib/Target/RISCV/RISCVInstrInfoVPseudos.td @@ -6136,10 +6136,13 @@ let hasSideEffects = 0, mayLoad = 0, mayStore = 0, Defs = [VL, VTYPE] in { // be accidentally be made X0 by MachineIR optimizations. To satisfy the // verifier, we also need a GPRX0 instruction for the special encodings. def PseudoVSETVLI : Pseudo<(outs GPR:$rd), (ins GPRNoX0:$rs1, VTypeIOp11:$vtypei), []>, + PseudoInstExpansion<(VSETVLI GPR:$rd, GPR:$rs1, VTypeIOp11:$vtypei)>, Sched<[WriteVSETVLI, ReadVSETVLI]>; def PseudoVSETVLIX0 : Pseudo<(outs GPR:$rd), (ins GPRX0:$rs1, VTypeIOp11:$vtypei), []>, + PseudoInstExpansion<(VSETVLI GPR:$rd, GPR:$rs1, VTypeIOp11:$vtypei)>, Sched<[WriteVSETVLI, ReadVSETVLI]>; def PseudoVSETIVLI : Pseudo<(outs GPR:$rd), (ins uimm5:$rs1, VTypeIOp10:$vtypei), []>, + PseudoInstExpansion<(VSETIVLI GPR:$rd, uimm5:$rs1, VTypeIOp10:$vtypei)>, Sched<[WriteVSETIVLI]>; }