From c714da2ceb25c88099b852ff0181af183252f2fe Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Sun, 31 Oct 2021 07:57:32 -0700 Subject: [PATCH] [Transforms] Use {DenseSet,SetVector,SmallPtrSet}::contains (NFC) --- llvm/lib/Transforms/Coroutines/CoroSplit.cpp | 2 +- llvm/lib/Transforms/IPO/FunctionAttrs.cpp | 2 +- llvm/lib/Transforms/IPO/StripSymbols.cpp | 4 ++-- .../Transforms/InstCombine/InstCombineCasts.cpp | 2 +- .../InstCombine/InstCombineCompares.cpp | 8 ++++---- .../Instrumentation/ControlHeightReduction.cpp | 6 +++--- llvm/lib/Transforms/Scalar/Float2Int.cpp | 2 +- .../lib/Transforms/Scalar/LoopIdiomRecognize.cpp | 2 +- llvm/lib/Transforms/Scalar/LoopInterchange.cpp | 16 ++++++---------- llvm/lib/Transforms/Scalar/NewGVN.cpp | 2 +- .../Transforms/Scalar/SpeculativeExecution.cpp | 2 +- llvm/lib/Transforms/Utils/FixIrreducible.cpp | 2 +- llvm/lib/Transforms/Utils/FlattenCFG.cpp | 4 ++-- llvm/lib/Transforms/Utils/SimplifyCFG.cpp | 2 +- 14 files changed, 26 insertions(+), 30 deletions(-) diff --git a/llvm/lib/Transforms/Coroutines/CoroSplit.cpp b/llvm/lib/Transforms/Coroutines/CoroSplit.cpp index d35301fb56282..118b2a3fa8849 100644 --- a/llvm/lib/Transforms/Coroutines/CoroSplit.cpp +++ b/llvm/lib/Transforms/Coroutines/CoroSplit.cpp @@ -1355,7 +1355,7 @@ static bool hasCallsInBlocksBetween(BasicBlock *SaveBB, BasicBlock *ResDesBB) { auto *BB = Worklist.pop_back_val(); Set.insert(BB); for (auto *Pred : predecessors(BB)) - if (Set.count(Pred) == 0) + if (!Set.contains(Pred)) Worklist.push_back(Pred); } diff --git a/llvm/lib/Transforms/IPO/FunctionAttrs.cpp b/llvm/lib/Transforms/IPO/FunctionAttrs.cpp index 21c82bf86bea1..8918d01f3ec27 100644 --- a/llvm/lib/Transforms/IPO/FunctionAttrs.cpp +++ b/llvm/lib/Transforms/IPO/FunctionAttrs.cpp @@ -1439,7 +1439,7 @@ static bool InstrBreaksNonConvergent(Instruction &I, // Breaks non-convergent assumption if CS is a convergent call to a function // not in the SCC. return CB && CB->isConvergent() && - SCCNodes.count(CB->getCalledFunction()) == 0; + !SCCNodes.contains(CB->getCalledFunction()); } /// Helper for NoUnwind inference predicate InstrBreaksAttribute. diff --git a/llvm/lib/Transforms/IPO/StripSymbols.cpp b/llvm/lib/Transforms/IPO/StripSymbols.cpp index 168740a1158ef..9d4e9464f3617 100644 --- a/llvm/lib/Transforms/IPO/StripSymbols.cpp +++ b/llvm/lib/Transforms/IPO/StripSymbols.cpp @@ -214,13 +214,13 @@ static bool StripSymbolNames(Module &M, bool PreserveDbgInfo) { findUsedValues(M.getGlobalVariable("llvm.compiler.used"), llvmUsedValues); for (GlobalVariable &GV : M.globals()) { - if (GV.hasLocalLinkage() && llvmUsedValues.count(&GV) == 0) + if (GV.hasLocalLinkage() && !llvmUsedValues.contains(&GV)) if (!PreserveDbgInfo || !GV.getName().startswith("llvm.dbg")) GV.setName(""); // Internal symbols can't participate in linkage } for (Function &I : M) { - if (I.hasLocalLinkage() && llvmUsedValues.count(&I) == 0) + if (I.hasLocalLinkage() && !llvmUsedValues.contains(&I)) if (!PreserveDbgInfo || !I.getName().startswith("llvm.dbg")) I.setName(""); // Internal symbols can't participate in linkage if (auto *Symtab = I.getValueSymbolTable()) diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp index 4937b48acdec6..ca87477c5d81d 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp @@ -2555,7 +2555,7 @@ Instruction *InstCombinerImpl::optimizeBitCastFromPhi(CastInst &CI, // As long as the user is another old PHI node, then even if we don't // rewrite it, the PHI web we're considering won't have any users // outside itself, so it'll be dead. - if (OldPhiNodes.count(PHI) == 0) + if (!OldPhiNodes.contains(PHI)) return nullptr; } else { return nullptr; diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp index 4634bd07db311..6f73c4e3f4235 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -541,7 +541,7 @@ static bool canRewriteGEPAsOffset(Value *Start, Value *Base, if (!CI->isNoopCast(DL)) return false; - if (Explored.count(CI->getOperand(0)) == 0) + if (!Explored.contains(CI->getOperand(0))) WorkList.push_back(CI->getOperand(0)); } @@ -553,7 +553,7 @@ static bool canRewriteGEPAsOffset(Value *Start, Value *Base, GEP->getType() != Start->getType()) return false; - if (Explored.count(GEP->getOperand(0)) == 0) + if (!Explored.contains(GEP->getOperand(0))) WorkList.push_back(GEP->getOperand(0)); } @@ -575,7 +575,7 @@ static bool canRewriteGEPAsOffset(Value *Start, Value *Base, // Explore the PHI nodes further. for (auto *PN : PHIs) for (Value *Op : PN->incoming_values()) - if (Explored.count(Op) == 0) + if (!Explored.contains(Op)) WorkList.push_back(Op); } @@ -589,7 +589,7 @@ static bool canRewriteGEPAsOffset(Value *Start, Value *Base, auto *Inst = dyn_cast(Val); if (Inst == Base || Inst == PHI || !Inst || !PHI || - Explored.count(PHI) == 0) + !Explored.contains(PHI)) continue; if (PHI->getParent() == Inst->getParent()) diff --git a/llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp b/llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp index 440fc8e805975..497aac30c3f65 100644 --- a/llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp +++ b/llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp @@ -1553,11 +1553,11 @@ static bool negateICmpIfUsedByBranchOrSelectOnly(ICmpInst *ICmp, SI->swapValues(); SI->swapProfMetadata(); if (Scope->TrueBiasedSelects.count(SI)) { - assert(Scope->FalseBiasedSelects.count(SI) == 0 && + assert(!Scope->FalseBiasedSelects.contains(SI) && "Must not be already in"); Scope->FalseBiasedSelects.insert(SI); } else if (Scope->FalseBiasedSelects.count(SI)) { - assert(Scope->TrueBiasedSelects.count(SI) == 0 && + assert(!Scope->TrueBiasedSelects.contains(SI) && "Must not be already in"); Scope->TrueBiasedSelects.insert(SI); } @@ -1592,7 +1592,7 @@ static void insertTrivialPHIs(CHRScope *Scope, SmallVector Users; for (User *U : I.users()) { if (auto *UI = dyn_cast(U)) { - if (BlocksInScope.count(UI->getParent()) == 0 && + if (!BlocksInScope.contains(UI->getParent()) && // Unless there's already a phi for I at the exit block. !(isa(UI) && UI->getParent() == ExitBlock)) { CHR_DEBUG(dbgs() << "V " << I << "\n"); diff --git a/llvm/lib/Transforms/Scalar/Float2Int.cpp b/llvm/lib/Transforms/Scalar/Float2Int.cpp index 74d445c952ed9..a98bb8358aeff 100644 --- a/llvm/lib/Transforms/Scalar/Float2Int.cpp +++ b/llvm/lib/Transforms/Scalar/Float2Int.cpp @@ -372,7 +372,7 @@ bool Float2IntPass::validateAndTransform() { // If it does, transformation would be illegal. // // Don't count the roots, as they terminate the graphs. - if (Roots.count(I) == 0) { + if (!Roots.contains(I)) { // Set the type of the conversion while we're here. if (!ConvertedToTy) ConvertedToTy = I->getType(); diff --git a/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp b/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp index d0b2d52cc75cd..42da86a9ecf50 100644 --- a/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp +++ b/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp @@ -1019,7 +1019,7 @@ mayLoopAccessLocation(Value *Ptr, ModRefInfo Access, Loop *L, for (BasicBlock *B : L->blocks()) for (Instruction &I : *B) - if (IgnoredInsts.count(&I) == 0 && + if (!IgnoredInsts.contains(&I) && isModOrRefSet( intersectModRef(AA.getModRefInfo(&I, StoreLoc), Access))) return true; diff --git a/llvm/lib/Transforms/Scalar/LoopInterchange.cpp b/llvm/lib/Transforms/Scalar/LoopInterchange.cpp index 34545f35b3c33..1d09bb1d5ced7 100644 --- a/llvm/lib/Transforms/Scalar/LoopInterchange.cpp +++ b/llvm/lib/Transforms/Scalar/LoopInterchange.cpp @@ -1710,16 +1710,12 @@ bool LoopInterchangeTransform::adjustLoopBranches() { auto &OuterInnerReductions = LIL.getOuterInnerReductions(); // Now update the reduction PHIs in the inner and outer loop headers. SmallVector InnerLoopPHIs, OuterLoopPHIs; - for (PHINode &PHI : InnerLoopHeader->phis()) { - if (OuterInnerReductions.find(&PHI) == OuterInnerReductions.end()) - continue; - InnerLoopPHIs.push_back(cast(&PHI)); - } - for (PHINode &PHI : OuterLoopHeader->phis()) { - if (OuterInnerReductions.find(&PHI) == OuterInnerReductions.end()) - continue; - OuterLoopPHIs.push_back(cast(&PHI)); - } + for (PHINode &PHI : InnerLoopHeader->phis()) + if (OuterInnerReductions.contains(&PHI)) + InnerLoopPHIs.push_back(cast(&PHI)); + for (PHINode &PHI : OuterLoopHeader->phis()) + if (OuterInnerReductions.contains(&PHI)) + OuterLoopPHIs.push_back(cast(&PHI)); // Now move the remaining reduction PHIs from outer to inner loop header and // vice versa. The PHI nodes must be part of a reduction across the inner and diff --git a/llvm/lib/Transforms/Scalar/NewGVN.cpp b/llvm/lib/Transforms/Scalar/NewGVN.cpp index e2551a4daa007..9855de49485c3 100644 --- a/llvm/lib/Transforms/Scalar/NewGVN.cpp +++ b/llvm/lib/Transforms/Scalar/NewGVN.cpp @@ -3607,7 +3607,7 @@ void NewGVN::convertClassToDFSOrdered( // Skip uses in unreachable blocks, as we're going // to delete them. - if (ReachableBlocks.count(IBlock) == 0) + if (!ReachableBlocks.contains(IBlock)) continue; DomTreeNode *DomNode = DT->getNode(IBlock); diff --git a/llvm/lib/Transforms/Scalar/SpeculativeExecution.cpp b/llvm/lib/Transforms/Scalar/SpeculativeExecution.cpp index dfa30418ea01c..06169a7834f64 100644 --- a/llvm/lib/Transforms/Scalar/SpeculativeExecution.cpp +++ b/llvm/lib/Transforms/Scalar/SpeculativeExecution.cpp @@ -268,7 +268,7 @@ bool SpeculativeExecutionPass::considerHoistingFromTo( if (const auto *DVI = dyn_cast(U)) { return all_of(DVI->location_ops(), [&NotHoisted](Value *V) { if (const auto *I = dyn_cast_or_null(V)) { - if (NotHoisted.count(I) == 0) + if (!NotHoisted.contains(I)) return true; } return false; diff --git a/llvm/lib/Transforms/Utils/FixIrreducible.cpp b/llvm/lib/Transforms/Utils/FixIrreducible.cpp index 10f48fe827f44..8de3ce876babc 100644 --- a/llvm/lib/Transforms/Utils/FixIrreducible.cpp +++ b/llvm/lib/Transforms/Utils/FixIrreducible.cpp @@ -124,7 +124,7 @@ static void reconnectChildLoops(LoopInfo &LI, Loop *ParentLoop, Loop *NewLoop, // children to a new vector. auto FirstChild = std::partition( CandidateLoops.begin(), CandidateLoops.end(), [&](Loop *L) { - return L == NewLoop || Blocks.count(L->getHeader()) == 0; + return L == NewLoop || !Blocks.contains(L->getHeader()); }); SmallVector ChildLoops(FirstChild, CandidateLoops.end()); CandidateLoops.erase(FirstChild, CandidateLoops.end()); diff --git a/llvm/lib/Transforms/Utils/FlattenCFG.cpp b/llvm/lib/Transforms/Utils/FlattenCFG.cpp index dbcacc20b5898..ddd3f597ae019 100644 --- a/llvm/lib/Transforms/Utils/FlattenCFG.cpp +++ b/llvm/lib/Transforms/Utils/FlattenCFG.cpp @@ -162,7 +162,7 @@ bool FlattenCFGOpt::FlattenParallelAndOr(BasicBlock *BB, IRBuilder<> &Builder) { // of \param BB (BB4) and should not have address-taken. // There should exist only one such unconditional // branch among the predecessors. - if (UnCondBlock || !PP || (Preds.count(PP) == 0) || + if (UnCondBlock || !PP || !Preds.contains(PP) || Pred->hasAddressTaken()) return false; @@ -215,7 +215,7 @@ bool FlattenCFGOpt::FlattenParallelAndOr(BasicBlock *BB, IRBuilder<> &Builder) { // PS is the successor which is not BB. Check successors to identify // the last conditional branch. - if (Preds.count(PS) == 0) { + if (!Preds.contains(PS)) { // Case 2. LastCondBlock = Pred; } else { diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp index 848c8a032153a..7b49f47778e07 100644 --- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp @@ -2058,7 +2058,7 @@ static bool SinkCommonCodeFromPredecessors(BasicBlock *BB, unsigned NumPHIdValues = 0; for (auto *I : *LRI) for (auto *V : PHIOperands[I]) { - if (InstructionsToSink.count(V) == 0) + if (!InstructionsToSink.contains(V)) ++NumPHIdValues; // FIXME: this check is overly optimistic. We may end up not sinking // said instruction, due to the very same profitability check.