[llvm] [llvm] Use llvm::is_contained (NFC) (PR #145844)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 25 23:00:42 PDT 2025


https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/145844

llvm::is_contained is shorter than llvm::all_of plus a lambda.


>From 2d8c3e1704e6f32f2b08ac35735341dda593cbed Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Wed, 25 Jun 2025 08:59:16 -0700
Subject: [PATCH] [llvm] Use llvm::is_contained (NFC)

llvm::is_contained is shorter than llvm::all_of plus a lambda.
---
 llvm/lib/MC/MCRegisterInfo.cpp                 |  2 +-
 .../AArch64/AArch64TargetTransformInfo.cpp     |  2 +-
 llvm/lib/Transforms/IPO/StripSymbols.cpp       |  3 +--
 llvm/lib/Transforms/Utils/InlineFunction.cpp   | 18 ++++++++----------
 .../utils/TableGen/Common/CodeGenRegisters.cpp |  2 +-
 5 files changed, 12 insertions(+), 15 deletions(-)

diff --git a/llvm/lib/MC/MCRegisterInfo.cpp b/llvm/lib/MC/MCRegisterInfo.cpp
index 4a9bacdbc8fc4..ba9ef00f9f0d8 100644
--- a/llvm/lib/MC/MCRegisterInfo.cpp
+++ b/llvm/lib/MC/MCRegisterInfo.cpp
@@ -93,7 +93,7 @@ ArrayRef<MCPhysReg> MCRegisterInfo::getCachedAliasesOf(MCRegister R) const {
 
   sort(Aliases);
   Aliases.erase(unique(Aliases), Aliases.end());
-  assert(none_of(Aliases, [&](auto &Cur) { return R == Cur; }) &&
+  assert(!llvm::is_contained(Aliases, R) &&
          "MCRegAliasIteratorImpl includes Self!");
 
   // Always put "self" at the end, so the iterator can choose to ignore it.
diff --git a/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp b/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
index 3387dee8aa4c8..79b2dc2b3845e 100644
--- a/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
+++ b/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
@@ -4855,7 +4855,7 @@ getAppleRuntimeUnrollPreferences(Loop *L, ScalarEvolution &SE,
   auto *Latch = L->getLoopLatch();
   SmallVector<BasicBlock *> Preds(predecessors(Latch));
   if (!Term || !Term->isConditional() || Preds.size() == 1 ||
-      none_of(Preds, [Header](BasicBlock *Pred) { return Header == Pred; }) ||
+      !llvm::is_contained(Preds, Header) ||
       none_of(Preds, [L](BasicBlock *Pred) { return L->contains(Pred); }))
     return;
 
diff --git a/llvm/lib/Transforms/IPO/StripSymbols.cpp b/llvm/lib/Transforms/IPO/StripSymbols.cpp
index ecd0ade131467..ec701b6d0037b 100644
--- a/llvm/lib/Transforms/IPO/StripSymbols.cpp
+++ b/llvm/lib/Transforms/IPO/StripSymbols.cpp
@@ -309,8 +309,7 @@ PreservedAnalyses StripDeadCGProfilePass::run(Module &M,
   SmallVector<Metadata *, 16> ValidCGEdges;
   for (Metadata *Edge : CGProf->operands()) {
     if (auto *EdgeAsNode = dyn_cast_or_null<MDNode>(Edge))
-      if (llvm::all_of(EdgeAsNode->operands(),
-                       [](const Metadata *V) { return V != nullptr; }))
+      if (!llvm::is_contained(EdgeAsNode->operands(), nullptr))
         ValidCGEdges.push_back(Edge);
   }
   M.setModuleFlag(Module::Append, "CG Profile",
diff --git a/llvm/lib/Transforms/Utils/InlineFunction.cpp b/llvm/lib/Transforms/Utils/InlineFunction.cpp
index 7df5e9958182c..673422b7c7fce 100644
--- a/llvm/lib/Transforms/Utils/InlineFunction.cpp
+++ b/llvm/lib/Transforms/Utils/InlineFunction.cpp
@@ -2336,16 +2336,14 @@ remapIndices(Function &Caller, BasicBlock *StartBB,
           Worklist.push_back(Succ);
   }
 
-  assert(
-      llvm::all_of(CalleeCounterMap, [&](const auto &V) { return V != 0; }) &&
-      "Counter index mapping should be either to -1 or to non-zero index, "
-      "because the 0 "
-      "index corresponds to the entry BB of the caller");
-  assert(
-      llvm::all_of(CalleeCallsiteMap, [&](const auto &V) { return V != 0; }) &&
-      "Callsite index mapping should be either to -1 or to non-zero index, "
-      "because there should have been at least a callsite - the inlined one "
-      "- which would have had a 0 index.");
+  assert(!llvm::is_contained(CalleeCounterMap, 0) &&
+         "Counter index mapping should be either to -1 or to non-zero index, "
+         "because the 0 "
+         "index corresponds to the entry BB of the caller");
+  assert(!llvm::is_contained(CalleeCallsiteMap, 0) &&
+         "Callsite index mapping should be either to -1 or to non-zero index, "
+         "because there should have been at least a callsite - the inlined one "
+         "- which would have had a 0 index.");
 
   return {std::move(CalleeCounterMap), std::move(CalleeCallsiteMap)};
 }
diff --git a/llvm/utils/TableGen/Common/CodeGenRegisters.cpp b/llvm/utils/TableGen/Common/CodeGenRegisters.cpp
index 57a243158692b..6260eeee331e1 100644
--- a/llvm/utils/TableGen/Common/CodeGenRegisters.cpp
+++ b/llvm/utils/TableGen/Common/CodeGenRegisters.cpp
@@ -881,7 +881,7 @@ bool CodeGenRegisterClass::hasType(const ValueTypeByHwMode &VT) const {
   if (VT.isSimple()) {
     MVT T = VT.getSimple();
     for (const ValueTypeByHwMode &OurVT : VTs) {
-      if (llvm::count_if(OurVT, [T](auto &&P) { return P.second == T; }))
+      if (llvm::is_contained(llvm::make_second_range(OurVT), T))
         return true;
     }
   }



More information about the llvm-commits mailing list