[PATCH] D147437: [LICM] Don't require optimized uses

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 3 04:51:27 PDT 2023


nikic created this revision.
nikic added reviewers: asbirlea, fhahn.
Herald added subscribers: kmitropoulou, StephenFan, hiraditya.
Herald added a project: All.
nikic requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

LICM currently requests optimized use MSSA form. This is wasteful, because LICM doesn't actually care about most uses, only those of invariant pointers in loops. Everything else doesn't need to be optimized.

LICM already uses the clobber walker in most places. This patch adjusts one place that was using getDefiningAccess() to use it as well, so we no longer have a dependence on pre-optimized uses.

This change is not NFC in that the fallback on the defining access when there are too many clobber calls may now fall back to an unoptimized use. In practice, I've not seen any problems with this though. If desired, we could also increase licm-mssa-optimization-cap to a higher value (increasing this from 100 to 200 has no impact on average compile-time -- but also doesn't appear to have any impact on LICM quality either).

This makes for a 0.9% geomean compile-time improvement: http://llvm-compile-time-tracker.com/compare.php?from=6afe972195454a1110ed8d20c6f2a547e6366379&to=fb64abececc685794fff46227eb7f383218150ce&stat=instructions:u


https://reviews.llvm.org/D147437

Files:
  llvm/lib/Transforms/Scalar/LICM.cpp


Index: llvm/lib/Transforms/Scalar/LICM.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/LICM.cpp
+++ llvm/lib/Transforms/Scalar/LICM.cpp
@@ -401,7 +401,6 @@
   bool Changed = false;
 
   assert(L->isLCSSAForm(*DT) && "Loop is not in LCSSA form.");
-  MSSA->ensureOptimizedUses();
 
   // If this loop has metadata indicating that LICM is not to be performed then
   // just exit.
@@ -1304,7 +1303,8 @@
       if (auto *Accesses = MSSA->getBlockAccesses(BB)) {
         for (const auto &MA : *Accesses)
           if (const auto *MU = dyn_cast<MemoryUse>(&MA)) {
-            auto *MD = MU->getDefiningAccess();
+            auto *MD = getClobberingMemoryAccess(*MSSA, BAA, Flags,
+                const_cast<MemoryUse *>(MU));
             if (!MSSA->isLiveOnEntryDef(MD) &&
                 CurLoop->contains(MD->getBlock()))
               return false;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D147437.510455.patch
Type: text/x-patch
Size: 910 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230403/0f9bd0db/attachment.bin>


More information about the llvm-commits mailing list