[llvm-branch-commits] [llvm] TwoAddressInstructions: Use a range loop to move the copy chain (PR #227296)
Matt Arsenault via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue Sep 29 05:48:27 PDT 2026
https://github.com/arsenm created https://github.com/llvm/llvm-project/pull/227296
Cleanup some messy iterator work.
Co-Authored-By: Claude Opus 5 <noreply at anthropic.com>
>From 32c002f030a9504c651aa835b2f4c089af474ae4 Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Tue, 29 Sep 2026 14:43:40 +0200
Subject: [PATCH] TwoAddressInstructions: Use a range loop to move the copy
chain
Cleanup some messy iterator work.
Co-Authored-By: Claude Opus 5 <noreply at anthropic.com>
---
llvm/lib/CodeGen/TwoAddressInstructionPass.cpp | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/llvm/lib/CodeGen/TwoAddressInstructionPass.cpp b/llvm/lib/CodeGen/TwoAddressInstructionPass.cpp
index 9ec96c180a0c1..ee2372e71e297 100644
--- a/llvm/lib/CodeGen/TwoAddressInstructionPass.cpp
+++ b/llvm/lib/CodeGen/TwoAddressInstructionPass.cpp
@@ -1066,12 +1066,13 @@ bool TwoAddressInstructionImpl::rescheduleMIBelowKill(
// We have to move the copies (and any interleaved debug instructions)
// first so that the MBB is still well-formed when calling handleMove().
// Move them back to front, so a copy never ends up above its source def.
- for (MachineBasicBlock::iterator MIIt(MI); std::next(MIIt) != End;) {
- MachineBasicBlock::iterator CopyMI = std::prev(End);
- MBB->splice(InsertPos, MBB, CopyMI);
- if (!CopyMI->isDebugOrPseudoInstr())
- LIS->handleMove(*CopyMI);
- InsertPos = CopyMI;
+ auto Copies = make_range(MachineBasicBlock::reverse_iterator(End),
+ MachineBasicBlock::reverse_iterator(AfterMI));
+ for (MachineInstr &CopyMI : make_early_inc_range(Copies)) {
+ MBB->splice(InsertPos, MBB, &CopyMI);
+ if (!CopyMI.isDebugOrPseudoInstr())
+ LIS->handleMove(CopyMI);
+ InsertPos = &CopyMI;
}
End = std::next(MachineBasicBlock::iterator(MI));
}
More information about the llvm-branch-commits
mailing list