From: Nikita Popov Date: Mon, 24 Apr 2023 15:05:06 +0000 (+0200) Subject: [LICM] Minor optimization (NFC) X-Git-Tag: upstream/17.0.6~10618 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ebd6b5dc6426c5a759d9ed588fe6b972319736ff;p=platform%2Fupstream%2Fllvm.git [LICM] Minor optimization (NFC) Simplify the match in hoistMinMax and only fetch the preheader once. --- diff --git a/llvm/lib/Transforms/Scalar/LICM.cpp b/llvm/lib/Transforms/Scalar/LICM.cpp index b5298cfd258b..5a1945196a72 100644 --- a/llvm/lib/Transforms/Scalar/LICM.cpp +++ b/llvm/lib/Transforms/Scalar/LICM.cpp @@ -883,6 +883,7 @@ bool llvm::hoistRegion(DomTreeNode *N, AAResults *AA, LoopInfo *LI, LoopBlocksRPO Worklist(CurLoop); Worklist.perform(LI); bool Changed = false; + BasicBlock *Preheader = CurLoop->getLoopPreheader(); for (BasicBlock *BB : Worklist) { // Only need to process the contents of this block if it is not part of a // subloop (which would already have been processed). @@ -916,8 +917,7 @@ bool llvm::hoistRegion(DomTreeNode *N, AAResults *AA, LoopInfo *LI, canSinkOrHoistInst(I, AA, DT, CurLoop, MSSAU, true, Flags, ORE) && isSafeToExecuteUnconditionally( I, DT, TLI, CurLoop, SafetyInfo, ORE, - CurLoop->getLoopPreheader()->getTerminator(), AC, - AllowSpeculation)) { + Preheader->getTerminator(), AC, AllowSpeculation)) { hoist(I, DT, CurLoop, CFH.getOrCreateHoistedBlock(BB), SafetyInfo, MSSAU, SE, ORE); HoistedInstructions.push_back(&I); @@ -2421,19 +2421,13 @@ bool pointerInvalidatedByBlock(BasicBlock &BB, MemorySSA &MSSA, MemoryUse &MU) { static bool hoistMinMax(Instruction &I, Loop &L, ICFLoopSafetyInfo &SafetyInfo, MemorySSAUpdater &MSSAU) { bool Inverse = false; - bool IsLogical = false; using namespace PatternMatch; Value *Cond1, *Cond2; - if (match(&I, m_Or(m_Value(Cond1), m_Value(Cond2)))) - Inverse = true; - else if (match(&I, m_LogicalOr(m_Value(Cond1), m_Value(Cond2)))) { + if (match(&I, m_LogicalOr(m_Value(Cond1), m_Value(Cond2)))) { Inverse = true; - IsLogical = true; - } else if (match(&I, m_And(m_Value(Cond1), m_Value(Cond2)))) { + } else if (match(&I, m_LogicalAnd(m_Value(Cond1), m_Value(Cond2)))) { // Do nothing - } else if (match(&I, m_LogicalAnd(m_Value(Cond1), m_Value(Cond2)))) - IsLogical = true; - else + } else return false; auto MatchICmpAgainstInvariant = [&](Value *C, ICmpInst::Predicate &P, @@ -2477,7 +2471,7 @@ static bool hoistMinMax(Instruction &I, Loop &L, ICFLoopSafetyInfo &SafetyInfo, // before (if it was a non-taken input of logical and/or instruction). If it // was poison, we need to freeze it. Note that no new use for LHS and RHS1 are // introduced, so they don't need this. - if (IsLogical) + if (isa(I)) RHS2 = Builder.CreateFreeze(RHS2, RHS2->getName() + ".fr"); Value *NewRHS = Builder.CreateBinaryIntrinsic( id, RHS1, RHS2, nullptr, StringRef("invariant.") +