[llvm] [RISCV] Use range-based for loops in RISCVOptWInstrs. NFC (PR #69647)
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 19 15:09:38 PDT 2023
https://github.com/topperc created https://github.com/llvm/llvm-project/pull/69647
None
>From 4f8e3508c316f8a0f81b88f6f8a1a4bc09404b54 Mon Sep 17 00:00:00 2001
From: Craig Topper <craig.topper at sifive.com>
Date: Thu, 19 Oct 2023 15:08:37 -0700
Subject: [PATCH] [RISCV] Use range-based for loops in RISCVOptWInstrs. NFC
---
llvm/lib/Target/RISCV/RISCVOptWInstrs.cpp | 18 +++++++-----------
1 file changed, 7 insertions(+), 11 deletions(-)
diff --git a/llvm/lib/Target/RISCV/RISCVOptWInstrs.cpp b/llvm/lib/Target/RISCV/RISCVOptWInstrs.cpp
index a33ad8a194afdff..63be3f88d48cc00 100644
--- a/llvm/lib/Target/RISCV/RISCVOptWInstrs.cpp
+++ b/llvm/lib/Target/RISCV/RISCVOptWInstrs.cpp
@@ -602,25 +602,23 @@ bool RISCVOptWInstrs::removeSExtWInstrs(MachineFunction &MF,
bool MadeChange = false;
for (MachineBasicBlock &MBB : MF) {
- for (auto I = MBB.begin(), IE = MBB.end(); I != IE;) {
- MachineInstr *MI = &*I++;
-
+ for (MachineInstr &MI : llvm::make_early_inc_range(MBB)) {
// We're looking for the sext.w pattern ADDIW rd, rs1, 0.
- if (!RISCV::isSEXT_W(*MI))
+ if (!RISCV::isSEXT_W(MI))
continue;
- Register SrcReg = MI->getOperand(1).getReg();
+ Register SrcReg = MI.getOperand(1).getReg();
SmallPtrSet<MachineInstr *, 4> FixableDefs;
// If all users only use the lower bits, this sext.w is redundant.
// Or if all definitions reaching MI sign-extend their output,
// then sext.w is redundant.
- if (!hasAllWUsers(*MI, ST, MRI) &&
+ if (!hasAllWUsers(MI, ST, MRI) &&
!isSignExtendedW(SrcReg, ST, MRI, FixableDefs))
continue;
- Register DstReg = MI->getOperand(0).getReg();
+ Register DstReg = MI.getOperand(0).getReg();
if (!MRI.constrainRegClass(SrcReg, MRI.getRegClass(DstReg)))
continue;
@@ -638,7 +636,7 @@ bool RISCVOptWInstrs::removeSExtWInstrs(MachineFunction &MF,
LLVM_DEBUG(dbgs() << "Removing redundant sign-extension\n");
MRI.replaceRegWith(DstReg, SrcReg);
MRI.clearKillFlags(SrcReg);
- MI->eraseFromParent();
+ MI.eraseFromParent();
++NumRemovedSExtW;
MadeChange = true;
}
@@ -656,9 +654,7 @@ bool RISCVOptWInstrs::stripWSuffixes(MachineFunction &MF,
bool MadeChange = false;
for (MachineBasicBlock &MBB : MF) {
- for (auto I = MBB.begin(), IE = MBB.end(); I != IE; ++I) {
- MachineInstr &MI = *I;
-
+ for (MachineInstr &MI : MBB) {
unsigned Opc;
switch (MI.getOpcode()) {
default:
More information about the llvm-commits
mailing list