Skip to content

[MemDepAnalysis] Don't reuse NonLocalPointerDeps cache if memory location size differs #116936

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 12 additions & 34 deletions llvm/lib/Analysis/MemoryDependenceAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1066,40 +1066,18 @@ bool MemoryDependenceResults::getNonLocalPointerDepFromBB(
// Invariant loads don't participate in caching. Thus no need to reconcile.
if (!isInvariantLoad && !Pair.second) {
if (CacheInfo->Size != Loc.Size) {
bool ThrowOutEverything;
if (CacheInfo->Size.hasValue() && Loc.Size.hasValue()) {
// FIXME: We may be able to do better in the face of results with mixed
// precision. We don't appear to get them in practice, though, so just
// be conservative.
ThrowOutEverything =
CacheInfo->Size.isPrecise() != Loc.Size.isPrecise() ||
!TypeSize::isKnownGE(CacheInfo->Size.getValue(),
Loc.Size.getValue());
} else {
// For our purposes, unknown size > all others.
ThrowOutEverything = !Loc.Size.hasValue();
}

if (ThrowOutEverything) {
// The query's Size is greater than the cached one. Throw out the
// cached data and proceed with the query at the greater size.
CacheInfo->Pair = BBSkipFirstBlockPair();
CacheInfo->Size = Loc.Size;
for (auto &Entry : CacheInfo->NonLocalDeps)
if (Instruction *Inst = Entry.getResult().getInst())
RemoveFromReverseMap(ReverseNonLocalPtrDeps, Inst, CacheKey);
CacheInfo->NonLocalDeps.clear();
// The cache is cleared (in the above line) so we will have lost
// information about blocks we have already visited. We therefore must
// assume that the cache information is incomplete.
IsIncomplete = true;
} else {
// This query's Size is less than the cached one. Conservatively restart
// the query using the greater size.
return getNonLocalPointerDepFromBB(
QueryInst, Pointer, Loc.getWithNewSize(CacheInfo->Size), isLoad,
StartBB, Result, Visited, SkipFirstBlock, IsIncomplete);
}
// The query's Size is not equal to the cached one. Throw out the cached
// data and proceed with the query with the new size.
CacheInfo->Pair = BBSkipFirstBlockPair();
CacheInfo->Size = Loc.Size;
for (auto &Entry : CacheInfo->NonLocalDeps)
if (Instruction *Inst = Entry.getResult().getInst())
RemoveFromReverseMap(ReverseNonLocalPtrDeps, Inst, CacheKey);
CacheInfo->NonLocalDeps.clear();
// The cache is cleared (in the above line) so we will have lost
// information about blocks we have already visited. We therefore must
// assume that the cache information is incomplete.
IsIncomplete = true;
}

// If the query's AATags are inconsistent with the cached one,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ define i8 @f(i1 %arg0, i1 %arg1, i1 %arg2) {
; CHECK-NEXT: call void @use(i64 undef)
; CHECK-NEXT: br label %[[BB9:.*]]
; CHECK: [[BB7]]:
; CHECK-NEXT: [[LOAD8:%.*]] = load i8, ptr [[CALL]], align 4
; CHECK-NEXT: br label %[[BB9]]
; CHECK: [[BB9]]:
; CHECK-NEXT: ret i8 4
; CHECK-NEXT: [[PHI10:%.*]] = phi i8 [ [[LOAD8]], %[[BB7]] ], [ 4, %[[BB6]] ]
; CHECK-NEXT: ret i8 [[PHI10]]
;
bb:
br i1 %arg2, label %bb2, label %bb11
Expand Down
24 changes: 12 additions & 12 deletions llvm/test/Transforms/GVN/PRE/rle.ll
Original file line number Diff line number Diff line change
Expand Up @@ -673,15 +673,15 @@ define i8 @phi_trans4(ptr %p) {
; CHECK-NEXT: [[X3:%.*]] = getelementptr i8, ptr [[P:%.*]], i32 192
; CHECK-NEXT: store i8 -64, ptr [[X3]], align 1
; CHECK-NEXT: [[X:%.*]] = getelementptr i8, ptr [[P]], i32 4
; CHECK-NEXT: [[Y:%.*]] = load i8, ptr [[X]], align 1
; CHECK-NEXT: [[Y2_PRE:%.*]] = load i8, ptr [[X]], align 1
; CHECK-NEXT: br label [[LOOP:%.*]]
; CHECK: loop:
; CHECK-NEXT: [[Y2:%.*]] = phi i8 [ [[Y]], [[ENTRY:%.*]] ], [ 0, [[LOOP]] ]
; CHECK-NEXT: [[Y2:%.*]] = phi i8 [ [[Y2_PRE]], [[ENTRY:%.*]] ], [ 0, [[LOOP]] ]
; CHECK-NEXT: [[COND:%.*]] = call i1 @cond2()
; CHECK-NEXT: store i32 0, ptr [[X3]], align 4
; CHECK-NEXT: br i1 [[COND]], label [[LOOP]], label [[OUT:%.*]]
; CHECK: out:
; CHECK-NEXT: [[R:%.*]] = add i8 [[Y]], [[Y2]]
; CHECK-NEXT: [[R:%.*]] = add i8 [[Y2_PRE]], [[Y2]]
; CHECK-NEXT: ret i8 [[R]]
;
entry:
Expand Down Expand Up @@ -772,18 +772,18 @@ define i32 @phi_trans6(ptr noalias nocapture readonly %x, i1 %cond) {
; CHECK-NEXT: call void @use_i32(i32 [[L0]])
; CHECK-NEXT: br label [[HEADER:%.*]]
; CHECK: header:
; CHECK-NEXT: [[L1:%.*]] = phi i32 [ [[L0]], [[ENTRY:%.*]] ], [ [[L1_PRE:%.*]], [[LATCH_HEADER_CRIT_EDGE:%.*]] ]
; CHECK-NEXT: [[L1_PRE:%.*]] = phi i32 [ [[L0]], [[ENTRY:%.*]] ], [ [[L1_PRE1:%.*]], [[LATCH_HEADER_CRIT_EDGE:%.*]] ]
; CHECK-NEXT: [[IV:%.*]] = phi i32 [ 0, [[ENTRY]] ], [ [[IV_NEXT:%.*]], [[LATCH_HEADER_CRIT_EDGE]] ]
; CHECK-NEXT: indirectbr ptr blockaddress(@phi_trans6, [[LATCH:%.*]]), [label %latch]
; CHECK: latch:
; CHECK-NEXT: [[IV_NEXT]] = add i32 [[IV]], 1
; CHECK-NEXT: br i1 [[COND:%.*]], label [[EXIT:%.*]], label [[LATCH_HEADER_CRIT_EDGE]]
; CHECK: latch.header_crit_edge:
; CHECK-NEXT: [[GEP_1_PHI_TRANS_INSERT_PHI_TRANS_INSERT:%.*]] = getelementptr i32, ptr [[X]], i32 [[IV_NEXT]]
; CHECK-NEXT: [[L1_PRE]] = load i32, ptr [[GEP_1_PHI_TRANS_INSERT_PHI_TRANS_INSERT]], align 4
; CHECK-NEXT: [[L1_PRE1]] = load i32, ptr [[GEP_1_PHI_TRANS_INSERT_PHI_TRANS_INSERT]], align 4
; CHECK-NEXT: br label [[HEADER]]
; CHECK: exit:
; CHECK-NEXT: ret i32 [[L1]]
; CHECK-NEXT: ret i32 [[L1_PRE]]
;
entry:
%l0 = load i32, ptr %x
Expand Down Expand Up @@ -1057,18 +1057,18 @@ define void @load_load_partial_alias_loop(ptr %P) {
; LE-NEXT: [[TMP0:%.*]] = trunc i32 [[V_1_32]] to i8
; LE-NEXT: br label [[LOOP:%.*]]
; LE: loop:
; LE-NEXT: [[V_I:%.*]] = phi i8 [ [[TMP0]], [[ENTRY:%.*]] ], [ [[V_I_PRE:%.*]], [[LOOP_LOOP_CRIT_EDGE:%.*]] ]
; LE-NEXT: [[V_I:%.*]] = phi i8 [ [[TMP0]], [[ENTRY:%.*]] ], [ [[TMP2:%.*]], [[LOOP_LOOP_CRIT_EDGE:%.*]] ]
; LE-NEXT: [[I:%.*]] = phi i64 [ 1, [[ENTRY]] ], [ [[I_INC:%.*]], [[LOOP_LOOP_CRIT_EDGE]] ]
; LE-NEXT: [[P_I:%.*]] = getelementptr i8, ptr [[P]], i64 [[I]]
; LE-NEXT: call void @use.i8(i8 [[V_I]])
; LE-NEXT: [[V_I_32:%.*]] = load i32, ptr [[P_I]], align 4
; LE-NEXT: call void @use.i32(i32 [[V_I_32]])
; LE-NEXT: [[I_INC]] = add i64 [[I]], 1
; LE-NEXT: [[CMP:%.*]] = icmp ne i64 [[I_INC]], 64
; LE-NEXT: [[TMP1:%.*]] = lshr i32 [[V_I_32]], 8
; LE-NEXT: [[TMP2]] = trunc i32 [[TMP1]] to i8
; LE-NEXT: br i1 [[CMP]], label [[LOOP_LOOP_CRIT_EDGE]], label [[EXIT:%.*]]
; LE: loop.loop_crit_edge:
; LE-NEXT: [[P_I_PHI_TRANS_INSERT:%.*]] = getelementptr i8, ptr [[P]], i64 [[I_INC]]
; LE-NEXT: [[V_I_PRE]] = load i8, ptr [[P_I_PHI_TRANS_INSERT]], align 1
; LE-NEXT: br label [[LOOP]]
; LE: exit:
; LE-NEXT: ret void
Expand All @@ -1084,18 +1084,18 @@ define void @load_load_partial_alias_loop(ptr %P) {
; BE-NEXT: [[TMP1:%.*]] = trunc i32 [[TMP0]] to i8
; BE-NEXT: br label [[LOOP:%.*]]
; BE: loop:
; BE-NEXT: [[V_I:%.*]] = phi i8 [ [[TMP1]], [[ENTRY:%.*]] ], [ [[V_I_PRE:%.*]], [[LOOP_LOOP_CRIT_EDGE:%.*]] ]
; BE-NEXT: [[V_I:%.*]] = phi i8 [ [[TMP1]], [[ENTRY:%.*]] ], [ [[TMP3:%.*]], [[LOOP_LOOP_CRIT_EDGE:%.*]] ]
; BE-NEXT: [[I:%.*]] = phi i64 [ 1, [[ENTRY]] ], [ [[I_INC:%.*]], [[LOOP_LOOP_CRIT_EDGE]] ]
; BE-NEXT: [[P_I:%.*]] = getelementptr i8, ptr [[P]], i64 [[I]]
; BE-NEXT: call void @use.i8(i8 [[V_I]])
; BE-NEXT: [[V_I_32:%.*]] = load i32, ptr [[P_I]], align 4
; BE-NEXT: call void @use.i32(i32 [[V_I_32]])
; BE-NEXT: [[I_INC]] = add i64 [[I]], 1
; BE-NEXT: [[CMP:%.*]] = icmp ne i64 [[I_INC]], 64
; BE-NEXT: [[TMP2:%.*]] = lshr i32 [[V_I_32]], 16
; BE-NEXT: [[TMP3]] = trunc i32 [[TMP2]] to i8
; BE-NEXT: br i1 [[CMP]], label [[LOOP_LOOP_CRIT_EDGE]], label [[EXIT:%.*]]
; BE: loop.loop_crit_edge:
; BE-NEXT: [[P_I_PHI_TRANS_INSERT:%.*]] = getelementptr i8, ptr [[P]], i64 [[I_INC]]
; BE-NEXT: [[V_I_PRE]] = load i8, ptr [[P_I_PHI_TRANS_INSERT]], align 1
; BE-NEXT: br label [[LOOP]]
; BE: exit:
; BE-NEXT: ret void
Expand Down
Loading