Skip to content

[RISCV] Use RISCVTargetInstrInfo::copyPhysReg in RISCVMakeCompressible. NFC #141296

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 27, 2025

Conversation

topperc
Copy link
Collaborator

@topperc topperc commented May 23, 2025

No description provided.

@llvmbot
Copy link
Member

llvmbot commented May 23, 2025

@llvm/pr-subscribers-backend-risc-v

Author: Craig Topper (topperc)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/141296.diff

1 Files Affected:

  • (modified) llvm/lib/Target/RISCV/RISCVMakeCompressible.cpp (+1-42)
diff --git a/llvm/lib/Target/RISCV/RISCVMakeCompressible.cpp b/llvm/lib/Target/RISCV/RISCVMakeCompressible.cpp
index 3621b7dc73312..65b4263476073 100644
--- a/llvm/lib/Target/RISCV/RISCVMakeCompressible.cpp
+++ b/llvm/lib/Target/RISCV/RISCVMakeCompressible.cpp
@@ -413,7 +413,6 @@ bool RISCVMakeCompressibleOpt::runOnMachineFunction(MachineFunction &Fn) {
 
   const RISCVSubtarget &STI = Fn.getSubtarget<RISCVSubtarget>();
   const RISCVInstrInfo &TII = *STI.getInstrInfo();
-  const RISCVRegisterInfo &TRI = *STI.getRegisterInfo();
 
   // This optimization only makes sense if compressed instructions are emitted.
   if (!STI.hasStdExtCOrZca())
@@ -442,49 +441,9 @@ bool RISCVMakeCompressibleOpt::runOnMachineFunction(MachineFunction &Fn) {
         BuildMI(MBB, MI, MI.getDebugLoc(), TII.get(RISCV::ADDI), NewReg)
             .addReg(RegImm.Reg)
             .addImm(RegImm.Imm);
-      } else if (RISCV::GPRF16RegClass.contains(RegImm.Reg)) {
-        assert(RegImm.Imm == 0);
-        BuildMI(MBB, MI, MI.getDebugLoc(), TII.get(RISCV::PseudoMV_FPR16INX),
-                NewReg)
-            .addReg(RegImm.Reg);
-      } else if (RISCV::GPRF32RegClass.contains(RegImm.Reg)) {
-        assert(RegImm.Imm == 0);
-        BuildMI(MBB, MI, MI.getDebugLoc(), TII.get(RISCV::PseudoMV_FPR32INX),
-                NewReg)
-            .addReg(RegImm.Reg);
-      } else if (RISCV::GPRPairRegClass.contains(RegImm.Reg)) {
-        assert(RegImm.Imm == 0);
-        MCRegister EvenReg = TRI.getSubReg(RegImm.Reg, RISCV::sub_gpr_even);
-        MCRegister OddReg;
-        // We need to special case odd reg for X0_PAIR.
-        if (RegImm.Reg == RISCV::X0_Pair)
-          OddReg = RISCV::X0;
-        else
-          OddReg = TRI.getSubReg(RegImm.Reg, RISCV::sub_gpr_odd);
-        assert(NewReg != RISCV::X0_Pair && "Cannot write to X0_Pair");
-        BuildMI(MBB, MI, MI.getDebugLoc(), TII.get(RISCV::ADDI),
-                TRI.getSubReg(NewReg, RISCV::sub_gpr_even))
-            .addReg(EvenReg)
-            .addImm(0);
-        BuildMI(MBB, MI, MI.getDebugLoc(), TII.get(RISCV::ADDI),
-                TRI.getSubReg(NewReg, RISCV::sub_gpr_odd))
-            .addReg(OddReg)
-            .addImm(0);
       } else {
-        assert((RISCV::FPR32RegClass.contains(RegImm.Reg) ||
-                RISCV::FPR64RegClass.contains(RegImm.Reg)) &&
-               "Expected FP register class");
-        // If we are looking at replacing an FPR register we don't expect to
-        // have any offset. The only compressible FP instructions with an offset
-        // are loads and stores, for which the offset applies to the GPR operand
-        // not the FPR operand.
         assert(RegImm.Imm == 0);
-        unsigned Opcode = RISCV::FPR32RegClass.contains(RegImm.Reg)
-                              ? RISCV::FSGNJ_S
-                              : RISCV::FSGNJ_D;
-        BuildMI(MBB, MI, MI.getDebugLoc(), TII.get(Opcode), NewReg)
-            .addReg(RegImm.Reg)
-            .addReg(RegImm.Reg);
+        TII.copyPhysReg(MBB, MI, MI.getDebugLoc(), NewReg, RegImm.Reg, /*KillSrc*/false);
       }
 
       // Update the set of instructions to use the compressed register and

Copy link

github-actions bot commented May 23, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

@topperc topperc merged commit 7eb4eef into llvm:main May 27, 2025
6 of 9 checks passed
@topperc topperc deleted the pr/copyphysreg branch May 27, 2025 15:03
sivan-shani pushed a commit to sivan-shani/llvm-project that referenced this pull request Jun 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants