[PATCH] D138043: [RISCV] Remove SExtWRemovalCands set from RISCVSExtWRemoval.
Craig Topper via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 21 19:27:22 PST 2022
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf99514ac3a6f: [RISCV] Remove SExtWRemovalCands set from RISCVSExtWRemoval. (authored by craig.topper).
Changed prior to commit:
https://reviews.llvm.org/D138043?vs=475507&id=477049#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D138043/new/
https://reviews.llvm.org/D138043
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
@@ -497,10 +497,8 @@
if (!ST.is64Bit())
return false;
- SmallPtrSet<MachineInstr *, 4> SExtWRemovalCands;
+ bool MadeChange = false;
- // Replacing instructions invalidates the MI iterator
- // we collect the candidates, then iterate over them separately.
for (MachineBasicBlock &MBB : MF) {
for (auto I = MBB.begin(), IE = MBB.end(); I != IE;) {
MachineInstr *MI = &*I++;
@@ -514,41 +512,36 @@
if (!SrcReg.isVirtual())
continue;
- SExtWRemovalCands.insert(MI);
- }
- }
+ SmallPtrSet<MachineInstr *, 4> FixableDef;
+ MachineInstr &SrcMI = *MRI.getVRegDef(SrcReg);
- bool MadeChange = false;
- for (auto *MI : SExtWRemovalCands) {
- SmallPtrSet<MachineInstr *, 4> FixableDef;
- Register SrcReg = MI->getOperand(1).getReg();
- MachineInstr &SrcMI = *MRI.getVRegDef(SrcReg);
-
- // If all definitions reaching MI sign-extend their output,
- // then sext.w is redundant
- if (!isSignExtendedW(SrcMI, MRI, FixableDef))
- continue;
+ // If all definitions reaching MI sign-extend their output,
+ // then sext.w is redundant
+ if (!isSignExtendedW(SrcMI, MRI, FixableDef))
+ continue;
- Register DstReg = MI->getOperand(0).getReg();
- if (!MRI.constrainRegClass(SrcReg, MRI.getRegClass(DstReg)))
- continue;
- // Convert Fixable instructions to their W versions.
- for (MachineInstr *Fixable : FixableDef) {
- LLVM_DEBUG(dbgs() << "Replacing " << *Fixable);
- Fixable->setDesc(TII.get(getWOp(Fixable->getOpcode())));
- Fixable->clearFlag(MachineInstr::MIFlag::NoSWrap);
- Fixable->clearFlag(MachineInstr::MIFlag::NoUWrap);
- Fixable->clearFlag(MachineInstr::MIFlag::IsExact);
- LLVM_DEBUG(dbgs() << " with " << *Fixable);
- ++NumTransformedToWInstrs;
- }
+ Register DstReg = MI->getOperand(0).getReg();
+ if (!MRI.constrainRegClass(SrcReg, MRI.getRegClass(DstReg)))
+ continue;
- LLVM_DEBUG(dbgs() << "Removing redundant sign-extension\n");
- MRI.replaceRegWith(DstReg, SrcReg);
- MRI.clearKillFlags(SrcReg);
- MI->eraseFromParent();
- ++NumRemovedSExtW;
- MadeChange = true;
+ // Convert Fixable instructions to their W versions.
+ for (MachineInstr *Fixable : FixableDef) {
+ LLVM_DEBUG(dbgs() << "Replacing " << *Fixable);
+ Fixable->setDesc(TII.get(getWOp(Fixable->getOpcode())));
+ Fixable->clearFlag(MachineInstr::MIFlag::NoSWrap);
+ Fixable->clearFlag(MachineInstr::MIFlag::NoUWrap);
+ Fixable->clearFlag(MachineInstr::MIFlag::IsExact);
+ LLVM_DEBUG(dbgs() << " with " << *Fixable);
+ ++NumTransformedToWInstrs;
+ }
+
+ LLVM_DEBUG(dbgs() << "Removing redundant sign-extension\n");
+ MRI.replaceRegWith(DstReg, SrcReg);
+ MRI.clearKillFlags(SrcReg);
+ MI->eraseFromParent();
+ ++NumRemovedSExtW;
+ MadeChange = true;
+ }
}
return MadeChange;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D138043.477049.patch
Type: text/x-patch
Size: 3180 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221122/e16cb6e1/attachment.bin>
More information about the llvm-commits
mailing list