Unverified Commit 2ad9fde4 authored by Nikita Popov's avatar Nikita Popov Committed by GitHub
Browse files

[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.
parent ab261eb3
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@
#include "llvm/ADT/PointerIntPair.h"
#include "llvm/ADT/PointerSumType.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/Analysis/AliasAnalysis.h"
#include "llvm/Analysis/MemoryLocation.h"
#include "llvm/IR/PassManager.h"
#include "llvm/IR/PredIteratorCache.h"
@@ -27,7 +28,6 @@

namespace llvm {

class AAResults;
class AssumptionCache;
class BatchAAResults;
class DominatorTree;
@@ -356,6 +356,7 @@ private:
  const TargetLibraryInfo &TLI;
  DominatorTree &DT;
  PredIteratorCache PredCache;
  EarliestEscapeInfo EII;

  unsigned DefaultBlockScanLimit;

@@ -367,7 +368,7 @@ public:
  MemoryDependenceResults(AAResults &AA, AssumptionCache &AC,
                          const TargetLibraryInfo &TLI, DominatorTree &DT,
                          unsigned DefaultBlockScanLimit)
      : AA(AA), AC(AC), TLI(TLI), DT(DT),
      : AA(AA), AC(AC), TLI(TLI), DT(DT), EII(DT),
        DefaultBlockScanLimit(DefaultBlockScanLimit) {}

  /// Handle invalidation in the new PM.
+5 −7
Original line number Diff line number Diff line
@@ -268,7 +268,7 @@ MemDepResult MemoryDependenceResults::getPointerDependencyFrom(
MemDepResult MemoryDependenceResults::getPointerDependencyFrom(
    const MemoryLocation &MemLoc, bool isLoad, BasicBlock::iterator ScanIt,
    BasicBlock *BB, Instruction *QueryInst, unsigned *Limit) {
  BatchAAResults BatchAA(AA);
  BatchAAResults BatchAA(AA, &EII);
  return getPointerDependencyFrom(MemLoc, isLoad, ScanIt, BB, QueryInst, Limit,
                                  BatchAA);
}
@@ -645,11 +645,7 @@ MemDepResult MemoryDependenceResults::getSimplePointerDependencyFrom(
        continue;

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

  BatchAAResults BatchAA(AA);
  BatchAAResults BatchAA(AA, &EII);
  while (!Worklist.empty()) {
    BasicBlock *BB = Worklist.pop_back_val();

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

void MemoryDependenceResults::removeInstruction(Instruction *RemInst) {
  EII.removeInstruction(RemInst);

  // Walk through the Non-local dependencies, removing this one as the value
  // for any cached queries.
  NonLocalDepMapType::iterator NLDI = NonLocalDepsMap.find(RemInst);
+4 −4
Original line number Diff line number Diff line
@@ -65,10 +65,10 @@ lor.end: ; preds = %lor.end.critedge, %
  ret void, !dbg !53
}

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

; Function Attrs: nounwind readnone speculatable willreturn
declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
+1 −2
Original line number Diff line number Diff line
@@ -46,9 +46,8 @@ define i32 @test_store_before_capture(ptr %p) {
; CHECK-NEXT:    store i32 123, ptr [[A]], align 4
; CHECK-NEXT:    [[P2:%.*]] = load ptr, ptr [[P]], align 8
; CHECK-NEXT:    store i32 42, ptr [[P2]], align 4
; CHECK-NEXT:    [[V:%.*]] = load i32, ptr [[A]], align 4
; CHECK-NEXT:    call void @capture(ptr [[A]])
; CHECK-NEXT:    ret i32 [[V]]
; CHECK-NEXT:    ret i32 123
;
  %a = alloca i32
  store i32 123, ptr %a