diff options
Diffstat (limited to 'contrib/llvm-project/llvm/lib/CodeGen/MachineCopyPropagation.cpp')
| -rw-r--r-- | contrib/llvm-project/llvm/lib/CodeGen/MachineCopyPropagation.cpp | 41 | 
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;  | 
