[PATCH] D137970: [RISCV] Transform fixable instruction in place in RISCVSExtWRemoval. NFC
Craig Topper via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 14 11:06:25 PST 2022
craig.topper created this revision.
craig.topper added reviewers: reames, asb, luismarques.
Herald added subscribers: sunshaoce, VincentWu, StephenFan, vkmr, frasercrmck, evandro, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, shiva0217, kito-cheng, niosHD, sabuasal, simoncook, johnrusso, rbar, hiraditya, arichardson.
Herald added a project: All.
craig.topper requested review of this revision.
Herald added subscribers: pcwang-thead, eopXD, MaskRay.
Herald added a project: LLVM.
Instead of creating a new instruction and copying operands, we can
use setDesc to convert in place.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D137970
Files:
llvm/lib/Target/RISCV/RISCVSExtWRemoval.cpp
Index: llvm/lib/Target/RISCV/RISCVSExtWRemoval.cpp
===================================================================
--- llvm/lib/Target/RISCV/RISCVSExtWRemoval.cpp
+++ llvm/lib/Target/RISCV/RISCVSExtWRemoval.cpp
@@ -478,6 +478,7 @@
MachineRegisterInfo &MRI = MF.getRegInfo();
const RISCVSubtarget &ST = MF.getSubtarget<RISCVSubtarget>();
+ const RISCVInstrInfo &TII = *ST.getInstrInfo();
if (!ST.is64Bit())
return false;
@@ -517,22 +518,11 @@
Register DstReg = MI->getOperand(0).getReg();
if (!MRI.constrainRegClass(SrcReg, MRI.getRegClass(DstReg)))
continue;
- // Replace Fixable instructions with their W versions.
+ // Convert Fixable instructions to their W versions.
for (MachineInstr *Fixable : FixableDef) {
- MachineBasicBlock &MBB = *Fixable->getParent();
- const DebugLoc &DL = Fixable->getDebugLoc();
- unsigned Code = getWOp(Fixable->getOpcode());
- MachineInstrBuilder Replacement =
- BuildMI(MBB, Fixable, DL, ST.getInstrInfo()->get(Code));
- for (auto Op : Fixable->operands())
- Replacement.add(Op);
- for (auto *Op : Fixable->memoperands())
- Replacement.addMemOperand(Op);
-
LLVM_DEBUG(dbgs() << "Replacing " << *Fixable);
- LLVM_DEBUG(dbgs() << " with " << *Replacement);
-
- Fixable->eraseFromParent();
+ Fixable->setDesc(TII.get(getWOp(Fixable->getOpcode())));
+ LLVM_DEBUG(dbgs() << " with " << *Fixable);
++NumTransformedToWInstrs;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D137970.475221.patch
Type: text/x-patch
Size: 1509 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221114/3fee012c/attachment.bin>
More information about the llvm-commits
mailing list