[llvm] e4abb64 - [LoopUnswitch] Use reference variables instead of pointer one

Jingu Kang via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 29 05:36:26 PDT 2021


Author: Jingu Kang
Date: 2021-03-29T13:08:46+01:00
New Revision: e4abb64100e4fe8f9ea400ddeb5c82fadbd67ef9

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

LOG: [LoopUnswitch] Use reference variables instead of pointer one

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

Added: 
    

Modified: 
    llvm/include/llvm/Transforms/Utils/LoopUtils.h
    llvm/lib/Transforms/Scalar/LoopUnswitch.cpp
    llvm/lib/Transforms/Utils/LoopUtils.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Transforms/Utils/LoopUtils.h b/llvm/include/llvm/Transforms/Utils/LoopUtils.h
index eb2b393818ef5..bf12941e5f4e1 100644
--- a/llvm/include/llvm/Transforms/Utils/LoopUtils.h
+++ b/llvm/include/llvm/Transforms/Utils/LoopUtils.h
@@ -513,8 +513,8 @@ struct IVConditionInfo {
 /// If the branch condition of the header is partially invariant, return a pair
 /// containing the instructions to duplicate and a boolean Constant to update
 /// the condition in the loops created for the true or false successors.
-Optional<IVConditionInfo> hasPartialIVCondition(Loop *L, unsigned MSSAThreshold,
-                                                MemorySSA *MSSA, AAResults *AA);
+Optional<IVConditionInfo> hasPartialIVCondition(Loop &L, unsigned MSSAThreshold,
+                                                MemorySSA &MSSA, AAResults &AA);
 
 } // end namespace llvm
 

diff  --git a/llvm/lib/Transforms/Scalar/LoopUnswitch.cpp b/llvm/lib/Transforms/Scalar/LoopUnswitch.cpp
index b8b8dba989d02..73b80dd01824b 100644
--- a/llvm/lib/Transforms/Scalar/LoopUnswitch.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopUnswitch.cpp
@@ -848,7 +848,7 @@ bool LoopUnswitch::processCurrentLoop() {
   if (MSSA &&
       !findOptionMDForLoop(CurrentLoop, "llvm.loop.unswitch.partial.disable")) {
     if (auto Info =
-            llvm::hasPartialIVCondition(CurrentLoop, MSSAThreshold, MSSA, AA)) {
+            hasPartialIVCondition(*CurrentLoop, MSSAThreshold, *MSSA, *AA)) {
       assert(!Info->InstToDuplicate.empty() &&
              "need at least a partially invariant condition");
       LLVM_DEBUG(dbgs() << "loop-unswitch: Found partially invariant condition "

diff  --git a/llvm/lib/Transforms/Utils/LoopUtils.cpp b/llvm/lib/Transforms/Utils/LoopUtils.cpp
index d95445b9b4c77..d2482fe601369 100644
--- a/llvm/lib/Transforms/Utils/LoopUtils.cpp
+++ b/llvm/lib/Transforms/Utils/LoopUtils.cpp
@@ -1706,29 +1706,18 @@ std::pair<Instruction *, Instruction *> llvm::addRuntimeChecks(
   return std::make_pair(FirstInst, Check);
 }
 
-/// Check if the loop header has a conditional branch that is not
-/// loop-invariant, because it involves load instructions. If all paths from
-/// either the true or false successor to the header or loop exists do not
-/// modify the memory feeding the condition, perform 'partial unswitching'. That
-/// is, duplicate the instructions feeding the condition in the pre-header. Then
-/// unswitch on the duplicated condition. The condition is now known in the
-/// unswitched version for the 'invariant' path through the original loop.
-///
-/// If the branch condition of the header is partially invariant, return a pair
-/// containing the instructions to duplicate and a boolean Constant to update
-/// the condition in the loops created for the true or false successors.
-Optional<IVConditionInfo> llvm::hasPartialIVCondition(Loop *L,
+Optional<IVConditionInfo> llvm::hasPartialIVCondition(Loop &L,
                                                       unsigned MSSAThreshold,
-                                                      MemorySSA *MSSA,
-                                                      AAResults *AA) {
-  auto *TI = dyn_cast<BranchInst>(L->getHeader()->getTerminator());
+                                                      MemorySSA &MSSA,
+                                                      AAResults &AA) {
+  auto *TI = dyn_cast<BranchInst>(L.getHeader()->getTerminator());
   if (!TI || !TI->isConditional())
     return {};
 
   auto *CondI = dyn_cast<CmpInst>(TI->getCondition());
   // The case with the condition outside the loop should already be handled
   // earlier.
-  if (!CondI || !L->contains(CondI))
+  if (!CondI || !L.contains(CondI))
     return {};
 
   SmallVector<Instruction *> InstToDuplicate;
@@ -1741,7 +1730,7 @@ Optional<IVConditionInfo> llvm::hasPartialIVCondition(Loop *L,
   SmallVector<MemoryLocation, 4> AccessedLocs;
   while (!WorkList.empty()) {
     Instruction *I = dyn_cast<Instruction>(WorkList.pop_back_val());
-    if (!I || !L->contains(I))
+    if (!I || !L.contains(I))
       continue;
 
     // TODO: support additional instructions.
@@ -1754,7 +1743,7 @@ Optional<IVConditionInfo> llvm::hasPartialIVCondition(Loop *L,
         return {};
 
     InstToDuplicate.push_back(I);
-    if (MemoryAccess *MA = MSSA->getMemoryAccess(I)) {
+    if (MemoryAccess *MA = MSSA.getMemoryAccess(I)) {
       if (auto *MemUse = dyn_cast_or_null<MemoryUse>(MA)) {
         // Queue the defining access to check for alias checks.
         AccessesToCheck.push_back(MemUse->getDefiningAccess());
@@ -1772,9 +1761,9 @@ Optional<IVConditionInfo> llvm::hasPartialIVCondition(Loop *L,
     return {};
 
   SmallVector<BasicBlock *, 4> ExitingBlocks;
-  L->getExitingBlocks(ExitingBlocks);
+  L.getExitingBlocks(ExitingBlocks);
   auto HasNoClobbersOnPath =
-      [L, AA, &AccessedLocs, &ExitingBlocks, &InstToDuplicate,
+      [&L, &AA, &AccessedLocs, &ExitingBlocks, &InstToDuplicate,
        MSSAThreshold](BasicBlock *Succ, BasicBlock *Header,
                       SmallVector<MemoryAccess *, 4> AccessesToCheck)
       -> Optional<IVConditionInfo> {
@@ -1791,7 +1780,7 @@ Optional<IVConditionInfo> llvm::hasPartialIVCondition(Loop *L,
 
     while (!WorkList.empty()) {
       BasicBlock *Current = WorkList.pop_back_val();
-      if (!L->contains(Current))
+      if (!L.contains(Current))
         continue;
       const auto &SeenIns = Seen.insert(Current);
       if (!SeenIns.second)
@@ -1829,9 +1818,9 @@ Optional<IVConditionInfo> llvm::hasPartialIVCondition(Loop *L,
       // For a MemoryDef, check if is aliases any of the location feeding
       // the original condition.
       if (auto *CurrentDef = dyn_cast<MemoryDef>(Current)) {
-        if (any_of(AccessedLocs, [AA, CurrentDef](MemoryLocation &Loc) {
+        if (any_of(AccessedLocs, [&AA, CurrentDef](MemoryLocation &Loc) {
               return isModSet(
-                  AA->getModRefInfo(CurrentDef->getMemoryInst(), Loc));
+                  AA.getModRefInfo(CurrentDef->getMemoryInst(), Loc));
             }))
           return {};
       }
@@ -1843,7 +1832,7 @@ Optional<IVConditionInfo> llvm::hasPartialIVCondition(Loop *L,
     // We could also allow loops with known trip counts without mustprogress,
     // but ScalarEvolution may not be available.
     Info.PathIsNoop &=
-        L->getHeader()->getParent()->mustProgress() || hasMustProgress(L);
+        L.getHeader()->getParent()->mustProgress() || hasMustProgress(&L);
 
     // If the path is considered a no-op so far, check if it reaches a
     // single exit block without any phis. This ensures no values from the
@@ -1853,7 +1842,7 @@ Optional<IVConditionInfo> llvm::hasPartialIVCondition(Loop *L,
         if (!Seen.contains(Exiting))
           continue;
         for (auto *Succ : successors(Exiting)) {
-          if (L->contains(Succ))
+          if (L.contains(Succ))
             continue;
 
           Info.PathIsNoop &= llvm::empty(Succ->phis()) &&
@@ -1878,12 +1867,12 @@ Optional<IVConditionInfo> llvm::hasPartialIVCondition(Loop *L,
   if (TI->getSuccessor(0) == TI->getSuccessor(1))
     return {};
 
-  if (auto Info = HasNoClobbersOnPath(TI->getSuccessor(0), L->getHeader(),
+  if (auto Info = HasNoClobbersOnPath(TI->getSuccessor(0), L.getHeader(),
                                       AccessesToCheck)) {
     Info->KnownValue = ConstantInt::getTrue(TI->getContext());
     return Info;
   }
-  if (auto Info = HasNoClobbersOnPath(TI->getSuccessor(1), L->getHeader(),
+  if (auto Info = HasNoClobbersOnPath(TI->getSuccessor(1), L.getHeader(),
                                       AccessesToCheck)) {
     Info->KnownValue = ConstantInt::getFalse(TI->getContext());
     return Info;


        


More information about the llvm-commits mailing list