[llvm] 80d3ed6 - [NFC][NewGVN] Remove OpIsSafeForPHIOfOpsHelper()

via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 21 09:27:27 PDT 2022


Author: Konstantina
Date: 2022-09-21T09:25:59-07:00
New Revision: 80d3ed6fb154d9d3fd2e631c454aecbfeab7f02c

URL: https://github.com/llvm/llvm-project/commit/80d3ed6fb154d9d3fd2e631c454aecbfeab7f02c
DIFF: https://github.com/llvm/llvm-project/commit/80d3ed6fb154d9d3fd2e631c454aecbfeab7f02c.diff

LOG: [NFC][NewGVN] Remove OpIsSafeForPHIOfOpsHelper()

Reviewed By: asbirlea

Differential Revision: https://reviews.llvm.org/D130949

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/NewGVN.cpp b/llvm/lib/Transforms/Scalar/NewGVN.cpp
index cbed14b5485c..d1397395ed24 100644
--- a/llvm/lib/Transforms/Scalar/NewGVN.cpp
+++ b/llvm/lib/Transforms/Scalar/NewGVN.cpp
@@ -766,9 +766,6 @@ class NewGVN {
                            SmallPtrSetImpl<Value *> &Visited,
                            MemoryAccess *MemAccess, Instruction *OrigInst,
                            BasicBlock *PredBB);
-  bool OpIsSafeForPHIOfOpsHelper(Value *V, const BasicBlock *PHIBlock,
-                                 SmallPtrSetImpl<const Value *> &Visited,
-                                 SmallVectorImpl<Instruction *> &Worklist);
   bool OpIsSafeForPHIOfOps(Value *Op, const BasicBlock *PHIBlock,
                            SmallPtrSetImpl<const Value *> &);
   void addPhiOfOps(PHINode *Op, BasicBlock *BB, Instruction *ExistingValue);
@@ -2574,58 +2571,6 @@ static bool okayForPHIOfOps(const Instruction *I) {
          isa<LoadInst>(I);
 }
 
-bool NewGVN::OpIsSafeForPHIOfOpsHelper(
-    Value *V, const BasicBlock *PHIBlock,
-    SmallPtrSetImpl<const Value *> &Visited,
-    SmallVectorImpl<Instruction *> &Worklist) {
-
-  if (!isa<Instruction>(V))
-    return true;
-  auto OISIt = OpSafeForPHIOfOps.find(V);
-  if (OISIt != OpSafeForPHIOfOps.end())
-    return OISIt->second;
-
-  // Keep walking until we either dominate the phi block, or hit a phi, or run
-  // out of things to check.
-  if (DT->properlyDominates(getBlockForValue(V), PHIBlock)) {
-    OpSafeForPHIOfOps.insert({V, true});
-    return true;
-  }
-  // PHI in the same block.
-  if (isa<PHINode>(V) && getBlockForValue(V) == PHIBlock) {
-    OpSafeForPHIOfOps.insert({V, false});
-    return false;
-  }
-
-  auto *OrigI = cast<Instruction>(V);
-  // When we hit an instruction that reads memory (load, call, etc), we must
-  // consider any store that may happen in the loop. For now, we assume the
-  // worst: there is a store in the loop that alias with this read.
-  // The case where the load is outside the loop is already covered by the
-  // dominator check above.
-  // TODO: relax this condition
-  if (OrigI->mayReadFromMemory())
-    return false;
-
-  for (auto *Op : OrigI->operand_values()) {
-    if (!isa<Instruction>(Op))
-      continue;
-    // Stop now if we find an unsafe operand.
-    auto OISIt = OpSafeForPHIOfOps.find(OrigI);
-    if (OISIt != OpSafeForPHIOfOps.end()) {
-      if (!OISIt->second) {
-        OpSafeForPHIOfOps.insert({V, false});
-        return false;
-      }
-      continue;
-    }
-    if (!Visited.insert(Op).second)
-      continue;
-    Worklist.push_back(cast<Instruction>(Op));
-  }
-  return true;
-}
-
 // Return true if this operand will be safe to use for phi of ops.
 //
 // The reason some operands are unsafe is that we are not trying to recursively
@@ -2635,13 +2580,56 @@ bool NewGVN::OpIsSafeForPHIOfOpsHelper(
 // be determined to be constant.
 bool NewGVN::OpIsSafeForPHIOfOps(Value *V, const BasicBlock *PHIBlock,
                                  SmallPtrSetImpl<const Value *> &Visited) {
-  SmallVector<Instruction *, 4> Worklist;
-  if (!OpIsSafeForPHIOfOpsHelper(V, PHIBlock, Visited, Worklist))
-    return false;
+  SmallVector<Value *, 4> Worklist;
+  Worklist.push_back(V);
   while (!Worklist.empty()) {
     auto *I = Worklist.pop_back_val();
-    if (!OpIsSafeForPHIOfOpsHelper(I, PHIBlock, Visited, Worklist))
+    if (!isa<Instruction>(I))
+      continue;
+
+    auto OISIt = OpSafeForPHIOfOps.find(I);
+    if (OISIt != OpSafeForPHIOfOps.end())
+      return OISIt->second;
+
+    // Keep walking until we either dominate the phi block, or hit a phi, or run
+    // out of things to check.
+    if (DT->properlyDominates(getBlockForValue(I), PHIBlock)) {
+      OpSafeForPHIOfOps.insert({I, true});
+      continue;
+    }
+    // PHI in the same block.
+    if (isa<PHINode>(I) && getBlockForValue(I) == PHIBlock) {
+      OpSafeForPHIOfOps.insert({I, false});
+      return false;
+    }
+
+    auto *OrigI = cast<Instruction>(I);
+    // When we hit an instruction that reads memory (load, call, etc), we must
+    // consider any store that may happen in the loop. For now, we assume the
+    // worst: there is a store in the loop that alias with this read.
+    // The case where the load is outside the loop is already covered by the
+    // dominator check above.
+    // TODO: relax this condition
+    if (OrigI->mayReadFromMemory())
       return false;
+
+    // Check the operands of the current instruction.
+    for (auto *Op : OrigI->operand_values()) {
+      if (!isa<Instruction>(Op))
+        continue;
+      // Stop now if we find an unsafe operand.
+      auto OISIt = OpSafeForPHIOfOps.find(OrigI);
+      if (OISIt != OpSafeForPHIOfOps.end()) {
+        if (!OISIt->second) {
+          OpSafeForPHIOfOps.insert({I, false});
+          return false;
+        }
+        continue;
+      }
+      if (!Visited.insert(Op).second)
+        continue;
+      Worklist.push_back(cast<Instruction>(Op));
+    }
   }
   OpSafeForPHIOfOps.insert({V, true});
   return true;


        


More information about the llvm-commits mailing list