[llvm] 7553bad - [LICM] Don't require optimized uses

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 5 02:20:34 PDT 2023


Author: Nikita Popov
Date: 2023-04-05T11:20:25+02:00
New Revision: 7553bad1ac619d5de72489ec06b63a2ace356c22

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

LOG: [LICM] Don't require optimized uses

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 on CTMark.

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

Added: 
    

Modified: 
    llvm/lib/Transforms/Scalar/LICM.cpp
    llvm/test/Analysis/MemorySSA/pr43427.ll
    llvm/test/Analysis/MemorySSA/pr45927.ll
    llvm/test/Analysis/MemorySSA/pr49859.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/LICM.cpp b/llvm/lib/Transforms/Scalar/LICM.cpp
index 94e5e978660b5..9a206956bfe23 100644
--- a/llvm/lib/Transforms/Scalar/LICM.cpp
+++ b/llvm/lib/Transforms/Scalar/LICM.cpp
@@ -401,7 +401,6 @@ bool LoopInvariantCodeMotion::runOnLoop(Loop *L, AAResults *AA, LoopInfo *LI,
   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 @@ bool llvm::canSinkOrHoistInst(Instruction &I, AAResults *AA, DominatorTree *DT,
       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;

diff  --git a/llvm/test/Analysis/MemorySSA/pr43427.ll b/llvm/test/Analysis/MemorySSA/pr43427.ll
index 6b9ac5c5288f1..18d87251e1067 100644
--- a/llvm/test/Analysis/MemorySSA/pr43427.ll
+++ b/llvm/test/Analysis/MemorySSA/pr43427.ll
@@ -19,7 +19,7 @@
 ; CHECK-NEXT: [[NO7]] = MemoryPhi({lbl2,[[NO8]]},{for.end,2})
 
 ; CHECK: cleanup:
-; CHECK-NEXT: MemoryUse([[NO7]])
+; CHECK-NEXT: MemoryUse([[NO2]])
 ; CHECK-NEXT:  %cleanup.dest = load i32, ptr undef, align 1
 
 ; CHECK: lbl1.backedge:

diff  --git a/llvm/test/Analysis/MemorySSA/pr45927.ll b/llvm/test/Analysis/MemorySSA/pr45927.ll
index a6a586feabdaa..7786b80c19a54 100644
--- a/llvm/test/Analysis/MemorySSA/pr45927.ll
+++ b/llvm/test/Analysis/MemorySSA/pr45927.ll
@@ -24,7 +24,7 @@
 ; CHECK-NEXT: store i16 %inc.i.lcssa, ptr @c, align 1
 ; CHECK-NEXT: ; [[NO2:.*]] = MemoryDef([[NO6]])
 ; CHECK-NEXT: store i16 1, ptr @a, align 1
-; CHECK-NEXT: ; MemoryUse([[NO2]])
+; CHECK-NEXT: ; MemoryUse([[NO6]])
 ; CHECK-NEXT: %tmp2 = load i16, ptr @c, align 1
 ; CHECK-NEXT: br label %g.exit
 

diff  --git a/llvm/test/Analysis/MemorySSA/pr49859.ll b/llvm/test/Analysis/MemorySSA/pr49859.ll
index 9778ca831c26c..25ef58698d92d 100644
--- a/llvm/test/Analysis/MemorySSA/pr49859.ll
+++ b/llvm/test/Analysis/MemorySSA/pr49859.ll
@@ -67,7 +67,7 @@ final.cleanup:                                          ; preds = %if.then, %for
   br label %for.end
 
 ; CHECK: for.end:
-; CHECK-NEXT: ; MemoryUse([[NO12]])
+; CHECK-NEXT: ; MemoryUse([[NO20]])
 ; CHECK-NEXT:  %3 = load i8, ptr %sum, align 1
 for.end:                                          ; preds = %final.cleanup
   %8 = load i8, ptr %sum, align 1


        


More information about the llvm-commits mailing list