Skip to content

Commit 7eb4eef

Browse files
authored
[RISCV] Use RISCVTargetInstrInfo::copyPhysReg in RISCVMakeCompressible. NFC (#141296)
1 parent 062353d commit 7eb4eef

File tree

1 file changed

+2
-42
lines changed

1 file changed

+2
-42
lines changed

llvm/lib/Target/RISCV/RISCVMakeCompressible.cpp

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,6 @@ bool RISCVMakeCompressibleOpt::runOnMachineFunction(MachineFunction &Fn) {
413413

414414
const RISCVSubtarget &STI = Fn.getSubtarget<RISCVSubtarget>();
415415
const RISCVInstrInfo &TII = *STI.getInstrInfo();
416-
const RISCVRegisterInfo &TRI = *STI.getRegisterInfo();
417416

418417
// This optimization only makes sense if compressed instructions are emitted.
419418
if (!STI.hasStdExtCOrZca())
@@ -442,49 +441,10 @@ bool RISCVMakeCompressibleOpt::runOnMachineFunction(MachineFunction &Fn) {
442441
BuildMI(MBB, MI, MI.getDebugLoc(), TII.get(RISCV::ADDI), NewReg)
443442
.addReg(RegImm.Reg)
444443
.addImm(RegImm.Imm);
445-
} else if (RISCV::GPRF16RegClass.contains(RegImm.Reg)) {
446-
assert(RegImm.Imm == 0);
447-
BuildMI(MBB, MI, MI.getDebugLoc(), TII.get(RISCV::PseudoMV_FPR16INX),
448-
NewReg)
449-
.addReg(RegImm.Reg);
450-
} else if (RISCV::GPRF32RegClass.contains(RegImm.Reg)) {
451-
assert(RegImm.Imm == 0);
452-
BuildMI(MBB, MI, MI.getDebugLoc(), TII.get(RISCV::PseudoMV_FPR32INX),
453-
NewReg)
454-
.addReg(RegImm.Reg);
455-
} else if (RISCV::GPRPairRegClass.contains(RegImm.Reg)) {
456-
assert(RegImm.Imm == 0);
457-
MCRegister EvenReg = TRI.getSubReg(RegImm.Reg, RISCV::sub_gpr_even);
458-
MCRegister OddReg;
459-
// We need to special case odd reg for X0_PAIR.
460-
if (RegImm.Reg == RISCV::X0_Pair)
461-
OddReg = RISCV::X0;
462-
else
463-
OddReg = TRI.getSubReg(RegImm.Reg, RISCV::sub_gpr_odd);
464-
assert(NewReg != RISCV::X0_Pair && "Cannot write to X0_Pair");
465-
BuildMI(MBB, MI, MI.getDebugLoc(), TII.get(RISCV::ADDI),
466-
TRI.getSubReg(NewReg, RISCV::sub_gpr_even))
467-
.addReg(EvenReg)
468-
.addImm(0);
469-
BuildMI(MBB, MI, MI.getDebugLoc(), TII.get(RISCV::ADDI),
470-
TRI.getSubReg(NewReg, RISCV::sub_gpr_odd))
471-
.addReg(OddReg)
472-
.addImm(0);
473444
} else {
474-
assert((RISCV::FPR32RegClass.contains(RegImm.Reg) ||
475-
RISCV::FPR64RegClass.contains(RegImm.Reg)) &&
476-
"Expected FP register class");
477-
// If we are looking at replacing an FPR register we don't expect to
478-
// have any offset. The only compressible FP instructions with an offset
479-
// are loads and stores, for which the offset applies to the GPR operand
480-
// not the FPR operand.
481445
assert(RegImm.Imm == 0);
482-
unsigned Opcode = RISCV::FPR32RegClass.contains(RegImm.Reg)
483-
? RISCV::FSGNJ_S
484-
: RISCV::FSGNJ_D;
485-
BuildMI(MBB, MI, MI.getDebugLoc(), TII.get(Opcode), NewReg)
486-
.addReg(RegImm.Reg)
487-
.addReg(RegImm.Reg);
446+
TII.copyPhysReg(MBB, MI, MI.getDebugLoc(), NewReg, RegImm.Reg,
447+
/*KillSrc*/ false);
488448
}
489449

490450
// Update the set of instructions to use the compressed register and

0 commit comments

Comments
 (0)