Skip to content

Commit

Permalink
[LICM] Don't require optimized uses
Browse files Browse the repository at this point in the history
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
  • Loading branch information
nikic committed Apr 5, 2023
1 parent 6a8d8f3 commit 7553bad
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions llvm/lib/Transforms/Scalar/LICM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/Analysis/MemorySSA/pr43427.ll
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/Analysis/MemorySSA/pr45927.ll
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion llvm/test/Analysis/MemorySSA/pr49859.ll
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7553bad

Please sign in to comment.