Skip to content

Commit dccf183

Browse files
dianqktru
authored andcommitted
[JumpThreading] Invalidate LVI after combineMetadataForCSE.
(cherry picked from commit 7ded71b1e43fff0be3acb74038bfea87f38d5cfa)
1 parent ae9c45b commit dccf183

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed

llvm/include/llvm/Analysis/LazyValueInfo.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ class LazyValueInfo {
115115
/// PredBB to OldSucc to be from PredBB to NewSucc instead.
116116
void threadEdge(BasicBlock *PredBB, BasicBlock *OldSucc, BasicBlock *NewSucc);
117117

118+
/// Remove information related to this value from the cache.
119+
void forgetValue(Value *V);
120+
118121
/// Inform the analysis cache that we have erased a block.
119122
void eraseBlock(BasicBlock *BB);
120123

llvm/lib/Analysis/LazyValueInfo.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,10 @@ class LazyValueInfoImpl {
465465
F.print(OS, &Writer);
466466
}
467467

468+
/// This is part of the update interface to remove information related to this
469+
/// value from the cache.
470+
void forgetValue(Value *V) { TheCache.eraseValue(V); }
471+
468472
/// This is part of the update interface to inform the cache
469473
/// that a block has been deleted.
470474
void eraseBlock(BasicBlock *BB) {
@@ -1969,6 +1973,11 @@ void LazyValueInfo::threadEdge(BasicBlock *PredBB, BasicBlock *OldSucc,
19691973
}
19701974
}
19711975

1976+
void LazyValueInfo::forgetValue(Value *V) {
1977+
if (PImpl)
1978+
getImpl(PImpl, AC, nullptr).forgetValue(V);
1979+
}
1980+
19721981
void LazyValueInfo::eraseBlock(BasicBlock *BB) {
19731982
if (PImpl) {
19741983
getImpl(PImpl, AC, BB->getModule()).eraseBlock(BB);

llvm/lib/Transforms/Scalar/JumpThreading.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1269,6 +1269,7 @@ bool JumpThreadingPass::simplifyPartiallyRedundantLoad(LoadInst *LoadI) {
12691269
if (IsLoadCSE) {
12701270
LoadInst *NLoadI = cast<LoadInst>(AvailableVal);
12711271
combineMetadataForCSE(NLoadI, LoadI, false);
1272+
LVI->forgetValue(NLoadI);
12721273
};
12731274

12741275
// If the returned value is the load itself, replace with poison. This can
@@ -1461,6 +1462,7 @@ bool JumpThreadingPass::simplifyPartiallyRedundantLoad(LoadInst *LoadI) {
14611462

14621463
for (LoadInst *PredLoadI : CSELoads) {
14631464
combineMetadataForCSE(PredLoadI, LoadI, true);
1465+
LVI->forgetValue(PredLoadI);
14641466
}
14651467

14661468
LoadI->replaceAllUsesWith(PN);

llvm/test/Transforms/JumpThreading/invalidate-lvi.ll

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,21 @@ define void @foo(i1 %0) {
1212
; CHECK-NEXT: [[V:%.*]] = alloca i64, align 8
1313
; CHECK-NEXT: call void @set_value(ptr [[V]])
1414
; CHECK-NEXT: [[L1:%.*]] = load i64, ptr [[V]], align 8
15-
; CHECK-NEXT: br i1 [[TMP0]], label [[BB0:%.*]], label [[BB4:%.*]]
15+
; CHECK-NEXT: br i1 [[TMP0]], label [[BB0:%.*]], label [[BB2:%.*]]
1616
; CHECK: bb0:
1717
; CHECK-NEXT: [[C1:%.*]] = icmp eq i64 [[L1]], 0
18-
; CHECK-NEXT: br i1 [[C1]], label [[BB1:%.*]], label [[BB4]]
19-
; CHECK: bb1:
18+
; CHECK-NEXT: br i1 [[C1]], label [[BB2_THREAD:%.*]], label [[BB2]]
19+
; CHECK: bb2.thread:
2020
; CHECK-NEXT: store i64 0, ptr [[V]], align 8
21-
; CHECK-NEXT: br label [[BB4]]
21+
; CHECK-NEXT: br label [[BB4:%.*]]
22+
; CHECK: bb2:
23+
; CHECK-NEXT: [[L2:%.*]] = phi i64 [ [[L1]], [[BB0]] ], [ [[L1]], [[START:%.*]] ]
24+
; CHECK-NEXT: [[TMP1:%.*]] = icmp eq i64 [[L2]], 2
25+
; CHECK-NEXT: br i1 [[TMP1]], label [[BB3:%.*]], label [[BB4]]
26+
; CHECK: bb3:
27+
; CHECK-NEXT: call void @bar()
28+
; CHECK-NEXT: ret void
2229
; CHECK: bb4:
23-
; CHECK-NEXT: [[L2:%.*]] = phi i64 [ 0, [[BB1]] ], [ [[L1]], [[BB0]] ], [ [[L1]], [[START:%.*]] ]
2430
; CHECK-NEXT: ret void
2531
;
2632
start:

0 commit comments

Comments
 (0)