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

via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 25 23:01:10 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mc

Author: Kazu Hirata (kazutakahirata)

<details>
<summary>Changes</summary>

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


---
Full diff: https://github.com/llvm/llvm-project/pull/145844.diff


5 Files Affected:

- (modified) llvm/lib/MC/MCRegisterInfo.cpp (+1-1) 
- (modified) llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp (+1-1) 
- (modified) llvm/lib/Transforms/IPO/StripSymbols.cpp (+1-2) 
- (modified) llvm/lib/Transforms/Utils/InlineFunction.cpp (+8-10) 
- (modified) llvm/utils/TableGen/Common/CodeGenRegisters.cpp (+1-1) 


``````````diff
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;
     }
   }

``````````

</details>


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


More information about the llvm-commits mailing list