Skip to content

Commit 2ad9fde

Browse files
authored
[MemDep] Use EarliestEscapeInfo (#69727)
Use BatchAA with EarliestEscapeInfo instead of callCapturesBefore() in MemDepAnalysis. The advantage of this is that it will also take not-captured-before information into account for non-calls (see test_store_before_capture for a representative example), and that this is a cached analysis. The disadvantage is that EII is slightly less precise than full CapturedBefore analysis. In practice the impact is positive, with gvn.NumGVNLoad going from 22022 to 22808 on test-suite. The impact to compile-time is also positive, mainly in the ThinLTO configuration.
1 parent ab261eb commit 2ad9fde

File tree

4 files changed

+13
-15
lines changed

4 files changed

+13
-15
lines changed

llvm/include/llvm/Analysis/MemoryDependenceAnalysis.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "llvm/ADT/PointerIntPair.h"
1919
#include "llvm/ADT/PointerSumType.h"
2020
#include "llvm/ADT/SmallPtrSet.h"
21+
#include "llvm/Analysis/AliasAnalysis.h"
2122
#include "llvm/Analysis/MemoryLocation.h"
2223
#include "llvm/IR/PassManager.h"
2324
#include "llvm/IR/PredIteratorCache.h"
@@ -27,7 +28,6 @@
2728

2829
namespace llvm {
2930

30-
class AAResults;
3131
class AssumptionCache;
3232
class BatchAAResults;
3333
class DominatorTree;
@@ -356,6 +356,7 @@ class MemoryDependenceResults {
356356
const TargetLibraryInfo &TLI;
357357
DominatorTree &DT;
358358
PredIteratorCache PredCache;
359+
EarliestEscapeInfo EII;
359360

360361
unsigned DefaultBlockScanLimit;
361362

@@ -367,7 +368,7 @@ class MemoryDependenceResults {
367368
MemoryDependenceResults(AAResults &AA, AssumptionCache &AC,
368369
const TargetLibraryInfo &TLI, DominatorTree &DT,
369370
unsigned DefaultBlockScanLimit)
370-
: AA(AA), AC(AC), TLI(TLI), DT(DT),
371+
: AA(AA), AC(AC), TLI(TLI), DT(DT), EII(DT),
371372
DefaultBlockScanLimit(DefaultBlockScanLimit) {}
372373

373374
/// Handle invalidation in the new PM.

llvm/lib/Analysis/MemoryDependenceAnalysis.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ MemDepResult MemoryDependenceResults::getPointerDependencyFrom(
268268
MemDepResult MemoryDependenceResults::getPointerDependencyFrom(
269269
const MemoryLocation &MemLoc, bool isLoad, BasicBlock::iterator ScanIt,
270270
BasicBlock *BB, Instruction *QueryInst, unsigned *Limit) {
271-
BatchAAResults BatchAA(AA);
271+
BatchAAResults BatchAA(AA, &EII);
272272
return getPointerDependencyFrom(MemLoc, isLoad, ScanIt, BB, QueryInst, Limit,
273273
BatchAA);
274274
}
@@ -645,11 +645,7 @@ MemDepResult MemoryDependenceResults::getSimplePointerDependencyFrom(
645645
continue;
646646

647647
// See if this instruction (e.g. a call or vaarg) mod/ref's the pointer.
648-
ModRefInfo MR = BatchAA.getModRefInfo(Inst, MemLoc);
649-
// If necessary, perform additional analysis.
650-
if (isModAndRefSet(MR))
651-
MR = BatchAA.callCapturesBefore(Inst, MemLoc, &DT);
652-
switch (MR) {
648+
switch (BatchAA.getModRefInfo(Inst, MemLoc)) {
653649
case ModRefInfo::NoModRef:
654650
// If the call has no effect on the queried pointer, just ignore it.
655651
continue;
@@ -1227,7 +1223,7 @@ bool MemoryDependenceResults::getNonLocalPointerDepFromBB(
12271223
bool GotWorklistLimit = false;
12281224
LLVM_DEBUG(AssertSorted(*Cache));
12291225

1230-
BatchAAResults BatchAA(AA);
1226+
BatchAAResults BatchAA(AA, &EII);
12311227
while (!Worklist.empty()) {
12321228
BasicBlock *BB = Worklist.pop_back_val();
12331229

@@ -1539,6 +1535,8 @@ void MemoryDependenceResults::invalidateCachedPredecessors() {
15391535
}
15401536

15411537
void MemoryDependenceResults::removeInstruction(Instruction *RemInst) {
1538+
EII.removeInstruction(RemInst);
1539+
15421540
// Walk through the Non-local dependencies, removing this one as the value
15431541
// for any cached queries.
15441542
NonLocalDepMapType::iterator NLDI = NonLocalDepsMap.find(RemInst);

llvm/test/CodeGen/BPF/CORE/no-narrow-load.ll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ lor.end: ; preds = %lor.end.critedge, %
6565
ret void, !dbg !53
6666
}
6767

68-
; CHECK: r[[LOAD1:[0-9]+]] = *(u32 *)(r{{[0-9]+}} + 4)
69-
; CHECK: r[[LOAD1]] &= 65536
70-
; CHECK: r[[LOAD2:[0-9]+]] = *(u32 *)(r{{[0-9]+}} + 4)
71-
; CHECK: r[[LOAD2]] &= 32768
68+
; CHECK: r[[LOAD:[0-9]+]] = *(u32 *)(r{{[0-9]+}} + 4)
69+
; CHECK: r[[COPY:[0-9]+]] = r[[LOAD]]
70+
; CHECK: r[[COPY]] &= 65536
71+
; CHECK: r[[LOAD]] &= 32768
7272

7373
; Function Attrs: nounwind readnone speculatable willreturn
7474
declare void @llvm.dbg.declare(metadata, metadata, metadata) #1

llvm/test/Transforms/GVN/captured-before.ll

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,8 @@ define i32 @test_store_before_capture(ptr %p) {
4646
; CHECK-NEXT: store i32 123, ptr [[A]], align 4
4747
; CHECK-NEXT: [[P2:%.*]] = load ptr, ptr [[P]], align 8
4848
; CHECK-NEXT: store i32 42, ptr [[P2]], align 4
49-
; CHECK-NEXT: [[V:%.*]] = load i32, ptr [[A]], align 4
5049
; CHECK-NEXT: call void @capture(ptr [[A]])
51-
; CHECK-NEXT: ret i32 [[V]]
50+
; CHECK-NEXT: ret i32 123
5251
;
5352
%a = alloca i32
5453
store i32 123, ptr %a

0 commit comments

Comments
 (0)