[llvm] 0b72b9d - [ValueLattice] Simplify canTrackGlobalVariableInterprocedurally (NFC).

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 9 10:33:34 PDT 2020


Author: Florian Hahn
Date: 2020-07-09T18:33:09+01:00
New Revision: 0b72b9d07fcdf888a7020f16f8e497f1e83d2d90

URL: https://github.com/llvm/llvm-project/commit/0b72b9d07fcdf888a7020f16f8e497f1e83d2d90
DIFF: https://github.com/llvm/llvm-project/commit/0b72b9d07fcdf888a7020f16f8e497f1e83d2d90.diff

LOG: [ValueLattice] Simplify canTrackGlobalVariableInterprocedurally (NFC).

using all_of and checking for valid users in the lambda seems more
straight forward. Also adds a comment explaining what we are checking.

Added: 
    

Modified: 
    llvm/lib/Analysis/ValueLatticeUtils.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/ValueLatticeUtils.cpp b/llvm/lib/Analysis/ValueLatticeUtils.cpp
index 3f9287e26ce7..53638c351f72 100644
--- a/llvm/lib/Analysis/ValueLatticeUtils.cpp
+++ b/llvm/lib/Analysis/ValueLatticeUtils.cpp
@@ -28,16 +28,14 @@ bool llvm::canTrackGlobalVariableInterprocedurally(GlobalVariable *GV) {
   if (GV->isConstant() || !GV->hasLocalLinkage() ||
       !GV->hasDefinitiveInitializer())
     return false;
-  return !any_of(GV->users(), [&](User *U) {
-    if (auto *Store = dyn_cast<StoreInst>(U)) {
-      if (Store->getValueOperand() == GV || Store->isVolatile())
-        return true;
-    } else if (auto *Load = dyn_cast<LoadInst>(U)) {
-      if (Load->isVolatile())
-        return true;
-    } else {
-      return true;
-    }
+  return all_of(GV->users(), [&](User *U) {
+    // Currently all users of a global variable have to be none-volatile loads
+    // or stores and the global cannot be stored itself.
+    if (auto *Store = dyn_cast<StoreInst>(U))
+      return Store->getValueOperand() != GV && !Store->isVolatile();
+    if (auto *Load = dyn_cast<LoadInst>(U))
+      return !Load->isVolatile();
+
     return false;
   });
 }


        


More information about the llvm-commits mailing list