From: Philip Reames Date: Wed, 4 Jan 2023 18:45:56 +0000 (-0800) Subject: [MachineCombine] Reorganize code for readability and tracing [nfc] X-Git-Tag: upstream/17.0.6~22138 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9560ac3a250822536fd264a72b5115d7d964e6f3;p=platform%2Fupstream%2Fllvm.git [MachineCombine] Reorganize code for readability and tracing [nfc] --- diff --git a/llvm/lib/CodeGen/MachineCombiner.cpp b/llvm/lib/CodeGen/MachineCombiner.cpp index bced97f7..be70c6d 100644 --- a/llvm/lib/CodeGen/MachineCombiner.cpp +++ b/llvm/lib/CodeGen/MachineCombiner.cpp @@ -90,7 +90,6 @@ public: StringRef getPassName() const override { return "Machine InstCombiner"; } private: - bool doSubstitute(unsigned NewSize, unsigned OldSize, bool OptForSize); bool combineInstructions(MachineBasicBlock *); MachineInstr *getOperandDef(const MachineOperand &MO); bool isTransientMI(const MachineInstr *MI); @@ -485,17 +484,6 @@ bool MachineCombiner::preservesResourceLen( ResLenBeforeCombine + TII->getExtendResourceLenLimit(); } -/// \returns true when new instruction sequence should be generated -/// independent if it lengthens critical path or not -bool MachineCombiner::doSubstitute(unsigned NewSize, unsigned OldSize, - bool OptForSize) { - if (OptForSize && (NewSize < OldSize)) - return true; - if (!TSchedModel.hasInstrSchedModelOrItineraries()) - return true; - return false; -} - /// Inserts InsInstrs and deletes DelInstrs. Incrementally updates instruction /// depths if requested. /// @@ -641,18 +629,16 @@ bool MachineCombiner::combineInstructions(MachineBasicBlock *MBB) { if (VerifyPatternOrder) verifyPatternOrder(MBB, MI, Patterns); - for (auto P : Patterns) { + for (const auto P : Patterns) { SmallVector InsInstrs; SmallVector DelInstrs; DenseMap InstrIdxForVirtReg; TII->genAlternativeCodeSequence(MI, P, InsInstrs, DelInstrs, InstrIdxForVirtReg); - unsigned NewInstCount = InsInstrs.size(); - unsigned OldInstCount = DelInstrs.size(); // Found pattern, but did not generate alternative sequence. // This can happen e.g. when an immediate could not be materialized // in a single instruction. - if (!NewInstCount) + if (InsInstrs.empty()) continue; LLVM_DEBUG(if (dump_intrs) { @@ -667,10 +653,6 @@ bool MachineCombiner::combineInstructions(MachineBasicBlock *MBB) { /*SkipDebugLoc*/false, /*AddNewLine*/true, TII); }); - bool SubstituteAlways = false; - if (ML && TII->isThroughputPattern(P)) - SubstituteAlways = true; - if (IncrementalUpdate && LastUpdate != BlockIter) { // Update depths since the last incremental update. MinInstr->updateDepths(LastUpdate, BlockIter, RegUnits); @@ -698,12 +680,24 @@ bool MachineCombiner::combineInstructions(MachineBasicBlock *MBB) { } } - // Substitute when we optimize for codesize and the new sequence has - // fewer instructions OR - // the new sequence neither lengthens the critical path nor increases - // resource pressure. - if (SubstituteAlways || - doSubstitute(NewInstCount, OldInstCount, OptForSize)) { + if (ML && TII->isThroughputPattern(P)) { + LLVM_DEBUG(dbgs() << "\t Replacing due to throughput pattern in loop\n"); + insertDeleteInstructions(MBB, MI, InsInstrs, DelInstrs, MinInstr, + RegUnits, TII, P, IncrementalUpdate); + // Eagerly stop after the first pattern fires. + Changed = true; + break; + } else if (OptForSize && InsInstrs.size() < DelInstrs.size()) { + LLVM_DEBUG(dbgs() << "\t Replacing due to OptForSize (" + << InsInstrs.size() << " < " + << DelInstrs.size() << ")\n"); + insertDeleteInstructions(MBB, MI, InsInstrs, DelInstrs, MinInstr, + RegUnits, TII, P, IncrementalUpdate); + // Eagerly stop after the first pattern fires. + Changed = true; + break; + } else if (!TSchedModel.hasInstrSchedModelOrItineraries()) { + LLVM_DEBUG(dbgs() << "\t Replacing due to lack of schedule model\n"); insertDeleteInstructions(MBB, MI, InsInstrs, DelInstrs, MinInstr, RegUnits, TII, P, IncrementalUpdate); // Eagerly stop after the first pattern fires.