aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/llvm/lib/CodeGen/MachineCopyPropagation.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2023-12-18 20:30:12 +0000
committerDimitry Andric <dim@FreeBSD.org>2024-04-06 20:11:55 +0000
commit5f757f3ff9144b609b3c433dfd370cc6bdc191ad (patch)
tree1b4e980b866cd26a00af34c0a653eb640bd09caf /contrib/llvm-project/llvm/lib/CodeGen/MachineCopyPropagation.cpp
parent3e1c8a35f741a5d114d0ba670b15191355711fe9 (diff)
parent312c0ed19cc5276a17bacf2120097bec4515b0f1 (diff)
Diffstat (limited to 'contrib/llvm-project/llvm/lib/CodeGen/MachineCopyPropagation.cpp')
-rw-r--r--contrib/llvm-project/llvm/lib/CodeGen/MachineCopyPropagation.cpp41
1 files changed, 22 insertions, 19 deletions
diff --git a/contrib/llvm-project/llvm/lib/CodeGen/MachineCopyPropagation.cpp b/contrib/llvm-project/llvm/lib/CodeGen/MachineCopyPropagation.cpp
index 3453e6c0b8be..a032b31a1fc7 100644
--- a/contrib/llvm-project/llvm/lib/CodeGen/MachineCopyPropagation.cpp
+++ b/contrib/llvm-project/llvm/lib/CodeGen/MachineCopyPropagation.cpp
@@ -134,28 +134,31 @@ public:
const TargetInstrInfo &TII, bool UseCopyInstr) {
// Since Reg might be a subreg of some registers, only invalidate Reg is not
// enough. We have to find the COPY defines Reg or registers defined by Reg
- // and invalidate all of them.
- SmallSet<MCRegister, 8> RegsToInvalidate;
- RegsToInvalidate.insert(Reg);
+ // and invalidate all of them. Similarly, we must invalidate all of the
+ // the subregisters used in the source of the COPY.
+ SmallSet<MCRegUnit, 8> RegUnitsToInvalidate;
+ auto InvalidateCopy = [&](MachineInstr *MI) {
+ std::optional<DestSourcePair> CopyOperands =
+ isCopyInstr(*MI, TII, UseCopyInstr);
+ assert(CopyOperands && "Expect copy");
+
+ auto Dest = TRI.regunits(CopyOperands->Destination->getReg().asMCReg());
+ auto Src = TRI.regunits(CopyOperands->Source->getReg().asMCReg());
+ RegUnitsToInvalidate.insert(Dest.begin(), Dest.end());
+ RegUnitsToInvalidate.insert(Src.begin(), Src.end());
+ };
+
for (MCRegUnit Unit : TRI.regunits(Reg)) {
auto I = Copies.find(Unit);
if (I != Copies.end()) {
- if (MachineInstr *MI = I->second.MI) {
- std::optional<DestSourcePair> CopyOperands =
- isCopyInstr(*MI, TII, UseCopyInstr);
- assert(CopyOperands && "Expect copy");
-
- RegsToInvalidate.insert(
- CopyOperands->Destination->getReg().asMCReg());
- RegsToInvalidate.insert(CopyOperands->Source->getReg().asMCReg());
- }
- RegsToInvalidate.insert(I->second.DefRegs.begin(),
- I->second.DefRegs.end());
+ if (MachineInstr *MI = I->second.MI)
+ InvalidateCopy(MI);
+ if (MachineInstr *MI = I->second.LastSeenUseInCopy)
+ InvalidateCopy(MI);
}
}
- for (MCRegister InvalidReg : RegsToInvalidate)
- for (MCRegUnit Unit : TRI.regunits(InvalidReg))
- Copies.erase(Unit);
+ for (MCRegUnit Unit : RegUnitsToInvalidate)
+ Copies.erase(Unit);
}
/// Clobber a single register, removing it from the tracker's copy maps.
@@ -1144,11 +1147,11 @@ void MachineCopyPropagation::EliminateSpillageCopies(MachineBasicBlock &MBB) {
return;
// If violate property#2, we don't fold the chain.
- for (const MachineInstr *Spill : make_range(SC.begin() + 1, SC.end()))
+ for (const MachineInstr *Spill : drop_begin(SC))
if (CopySourceInvalid.count(Spill))
return;
- for (const MachineInstr *Reload : make_range(RC.begin(), RC.end() - 1))
+ for (const MachineInstr *Reload : drop_end(RC))
if (CopySourceInvalid.count(Reload))
return;