[llvm] r268836 - [ValueTracking] Hoist some computation out of a loop; NFC

Sanjoy Das via llvm-commits llvm-commits at lists.llvm.org
Fri May 6 19:08:24 PDT 2016


Author: sanjoy
Date: Fri May  6 21:08:24 2016
New Revision: 268836

URL: http://llvm.org/viewvc/llvm-project?rev=268836&view=rev
Log:
[ValueTracking] Hoist some computation out of a loop; NFC

There is no need to match the comparison instruction repeatedly.

Modified:
    llvm/trunk/lib/Analysis/ValueTracking.cpp

Modified: llvm/trunk/lib/Analysis/ValueTracking.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ValueTracking.cpp?rev=268836&r1=268835&r2=268836&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ValueTracking.cpp (original)
+++ llvm/trunk/lib/Analysis/ValueTracking.cpp Fri May  6 21:08:24 2016
@@ -3199,39 +3199,30 @@ static bool isKnownNonNullFromDominating
   assert(V->getType()->isPointerTy() && "V must be pointer type");
 
   unsigned NumUsesExplored = 0;
-  for (auto U : V->users()) {
+  for (auto *U : V->users()) {
     // Avoid massive lists
     if (NumUsesExplored >= DomConditionsMaxUses)
       break;
     NumUsesExplored++;
     // Consider only compare instructions uniquely controlling a branch
-    const ICmpInst *Cmp = dyn_cast<ICmpInst>(U);
-    if (!Cmp)
+    CmpInst::Predicate Pred;
+    if (!match(const_cast<User *>(U),
+               m_c_ICmp(Pred, m_Specific(V), m_Zero())) ||
+        (Pred != ICmpInst::ICMP_EQ && Pred != ICmpInst::ICMP_NE))
       continue;
 
-    for (auto *CmpU : Cmp->users()) {
+    for (auto *CmpU : U->users()) {
       const BranchInst *BI = dyn_cast<BranchInst>(CmpU);
       if (!BI)
         continue;
 
       assert(BI->isConditional() && "uses a comparison!");
 
-      BasicBlock *NonNullSuccessor = nullptr;
-      CmpInst::Predicate Pred;
-
-      if (match(const_cast<ICmpInst*>(Cmp),
-                m_c_ICmp(Pred, m_Specific(V), m_Zero()))) {
-        if (Pred == ICmpInst::ICMP_EQ)
-          NonNullSuccessor = BI->getSuccessor(1);
-        else if (Pred == ICmpInst::ICMP_NE)
-          NonNullSuccessor = BI->getSuccessor(0);
-      }
-
-      if (NonNullSuccessor) {
-        BasicBlockEdge Edge(BI->getParent(), NonNullSuccessor);
-        if (Edge.isSingleEdge() && DT->dominates(Edge, CtxI->getParent()))
-          return true;
-      }
+      BasicBlock *NonNullSuccessor =
+          BI->getSuccessor(Pred == ICmpInst::ICMP_EQ ? 1 : 0);
+      BasicBlockEdge Edge(BI->getParent(), NonNullSuccessor);
+      if (Edge.isSingleEdge() && DT->dominates(Edge, CtxI->getParent()))
+        return true;
     }
   }
 




More information about the llvm-commits mailing list