[llvm] 636089d - [GVN] hasUsersIn - merge isa<> and cast<> into single dyn_cast<> and convert for-range loop to any_of() test. NFCI.

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 14 11:42:59 PST 2022


Author: Simon Pilgrim
Date: 2022-12-14T19:42:42Z
New Revision: 636089d8dce257b5f261824d907bdb3d26b7a46e

URL: https://github.com/llvm/llvm-project/commit/636089d8dce257b5f261824d907bdb3d26b7a46e
DIFF: https://github.com/llvm/llvm-project/commit/636089d8dce257b5f261824d907bdb3d26b7a46e.diff

LOG: [GVN] hasUsersIn - merge isa<> and cast<> into single dyn_cast<> and convert for-range loop to any_of() test. NFCI.

Avoid running isa<> and cast<> if we can - dyn_cast<> can more efficiently check for a safe cast and give the casted pointer.

Added: 
    

Modified: 
    llvm/lib/Transforms/Scalar/GVN.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/GVN.cpp b/llvm/lib/Transforms/Scalar/GVN.cpp
index c382814239e32..d51fee78597b7 100644
--- a/llvm/lib/Transforms/Scalar/GVN.cpp
+++ b/llvm/lib/Transforms/Scalar/GVN.cpp
@@ -1890,11 +1890,10 @@ static bool impliesEquivalanceIfFalse(CmpInst* Cmp) {
 
 
 static bool hasUsersIn(Value *V, BasicBlock *BB) {
-  for (User *U : V->users())
-    if (isa<Instruction>(U) &&
-        cast<Instruction>(U)->getParent() == BB)
-      return true;
-  return false;
+  return llvm::any_of(V->users(), [BB](User *U) {
+    auto *I = dyn_cast<Instruction>(U);
+    return I && I->getParent() == BB;
+  });
 }
 
 bool GVNPass::processAssumeIntrinsic(AssumeInst *IntrinsicI) {


        


More information about the llvm-commits mailing list