Skip to content

Commit 7553bad

Browse files
committed
[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
1 parent 6a8d8f3 commit 7553bad

File tree

4 files changed

+5
-5
lines changed

4 files changed

+5
-5
lines changed

llvm/lib/Transforms/Scalar/LICM.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,6 @@ bool LoopInvariantCodeMotion::runOnLoop(Loop *L, AAResults *AA, LoopInfo *LI,
401401
bool Changed = false;
402402

403403
assert(L->isLCSSAForm(*DT) && "Loop is not in LCSSA form.");
404-
MSSA->ensureOptimizedUses();
405404

406405
// If this loop has metadata indicating that LICM is not to be performed then
407406
// just exit.
@@ -1304,7 +1303,8 @@ bool llvm::canSinkOrHoistInst(Instruction &I, AAResults *AA, DominatorTree *DT,
13041303
if (auto *Accesses = MSSA->getBlockAccesses(BB)) {
13051304
for (const auto &MA : *Accesses)
13061305
if (const auto *MU = dyn_cast<MemoryUse>(&MA)) {
1307-
auto *MD = MU->getDefiningAccess();
1306+
auto *MD = getClobberingMemoryAccess(*MSSA, BAA, Flags,
1307+
const_cast<MemoryUse *>(MU));
13081308
if (!MSSA->isLiveOnEntryDef(MD) &&
13091309
CurLoop->contains(MD->getBlock()))
13101310
return false;

llvm/test/Analysis/MemorySSA/pr43427.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
; CHECK-NEXT: [[NO7]] = MemoryPhi({lbl2,[[NO8]]},{for.end,2})
2020

2121
; CHECK: cleanup:
22-
; CHECK-NEXT: MemoryUse([[NO7]])
22+
; CHECK-NEXT: MemoryUse([[NO2]])
2323
; CHECK-NEXT: %cleanup.dest = load i32, ptr undef, align 1
2424

2525
; CHECK: lbl1.backedge:

llvm/test/Analysis/MemorySSA/pr45927.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
; CHECK-NEXT: store i16 %inc.i.lcssa, ptr @c, align 1
2525
; CHECK-NEXT: ; [[NO2:.*]] = MemoryDef([[NO6]])
2626
; CHECK-NEXT: store i16 1, ptr @a, align 1
27-
; CHECK-NEXT: ; MemoryUse([[NO2]])
27+
; CHECK-NEXT: ; MemoryUse([[NO6]])
2828
; CHECK-NEXT: %tmp2 = load i16, ptr @c, align 1
2929
; CHECK-NEXT: br label %g.exit
3030

llvm/test/Analysis/MemorySSA/pr49859.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ final.cleanup: ; preds = %if.then, %for
6767
br label %for.end
6868

6969
; CHECK: for.end:
70-
; CHECK-NEXT: ; MemoryUse([[NO12]])
70+
; CHECK-NEXT: ; MemoryUse([[NO20]])
7171
; CHECK-NEXT: %3 = load i8, ptr %sum, align 1
7272
for.end: ; preds = %final.cleanup
7373
%8 = load i8, ptr %sum, align 1

0 commit comments

Comments
 (0)