diff --git a/llvm/lib/Target/ARM/ARMLowOverheadLoops.cpp b/llvm/lib/Target/ARM/ARMLowOverheadLoops.cpp index 868ac7d8bdc4b..dd4579fb6c5d4 100644 --- a/llvm/lib/Target/ARM/ARMLowOverheadLoops.cpp +++ b/llvm/lib/Target/ARM/ARMLowOverheadLoops.cpp @@ -519,36 +519,6 @@ static bool isRegInClass(const MachineOperand &MO, } bool LowOverheadLoop::ValidateLiveOuts() const { - // Collect Q-regs that are live in the exit blocks. We don't collect scalars - // because they won't be affected by lane predication. - const TargetRegisterClass *QPRs = TRI.getRegClass(ARM::MQPRRegClassID); - SmallSet LiveOuts; - SmallVector ExitBlocks; - ML.getExitBlocks(ExitBlocks); - for (auto *MBB : ExitBlocks) - for (const MachineBasicBlock::RegisterMaskPair &RegMask : MBB->liveins()) - if (QPRs->contains(RegMask.PhysReg)) - LiveOuts.insert(RegMask.PhysReg); - - // Collect the instructions in the loop body that define the live-out values. - SmallPtrSet LiveMIs; - assert(ML.getNumBlocks() == 1 && "Expected single block loop!"); - MachineBasicBlock *MBB = ML.getHeader(); - for (auto Reg : LiveOuts) - if (auto *MI = RDA.getLocalLiveOutMIDef(MBB, Reg)) - LiveMIs.insert(MI); - - LLVM_DEBUG(dbgs() << "ARM Loops: Found loop live-outs:\n"; - for (auto *MI : LiveMIs) - dbgs() << " - " << *MI); - // We've already validated that any VPT predication within the loop will be - // equivalent when we perform the predication transformation; so we know that - // any VPT predicated instruction is predicated upon VCTP. Any live-out - // instruction needs to be predicated, so check this here. - for (auto *MI : LiveMIs) - if (!isVectorPredicated(MI)) - return false; - // We want to find out if the tail-predicated version of this loop will // produce the same values as the loop in its original form. For this to // be true, the newly inserted implicit predication must not change the @@ -570,8 +540,10 @@ bool LowOverheadLoop::ValidateLiveOuts() const { // loop and the tail-predicated form too. Because of this, we can insert // loads, stores and other predicated instructions into our KnownFalseZeros // set and build from there. + const TargetRegisterClass *QPRs = TRI.getRegClass(ARM::MQPRRegClassID); SetVector UnknownFalseLanes; SmallPtrSet KnownFalseZeros; + MachineBasicBlock *MBB = ML.getHeader(); for (auto &MI : *MBB) { const MCInstrDesc &MCID = MI.getDesc(); uint64_t Flags = MCID.TSFlags; @@ -637,6 +609,35 @@ bool LowOverheadLoop::ValidateLiveOuts() const { // Any unknown false lanes have been masked away by the user(s). KnownFalseZeros.insert(MI); } + + // Collect Q-regs that are live in the exit blocks. We don't collect scalars + // because they won't be affected by lane predication. + SmallSet LiveOuts; + SmallVector ExitBlocks; + ML.getExitBlocks(ExitBlocks); + for (auto *MBB : ExitBlocks) + for (const MachineBasicBlock::RegisterMaskPair &RegMask : MBB->liveins()) + if (QPRs->contains(RegMask.PhysReg)) + LiveOuts.insert(RegMask.PhysReg); + + // Collect the instructions in the loop body that define the live-out values. + SmallPtrSet LiveMIs; + assert(ML.getNumBlocks() == 1 && "Expected single block loop!"); + for (auto Reg : LiveOuts) + if (auto *MI = RDA.getLocalLiveOutMIDef(MBB, Reg)) + LiveMIs.insert(MI); + + LLVM_DEBUG(dbgs() << "ARM Loops: Found loop live-outs:\n"; + for (auto *MI : LiveMIs) + dbgs() << " - " << *MI); + // We've already validated that any VPT predication within the loop will be + // equivalent when we perform the predication transformation; so we know that + // any VPT predicated instruction is predicated upon VCTP. Any live-out + // instruction needs to be predicated, so check this here. + for (auto *MI : LiveMIs) + if (!isVectorPredicated(MI)) + return false; + return true; }