Skip to content

PR for llvm/llvm-project#65195 #685

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 2 commits into from
Sep 5, 2023
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
3 changes: 3 additions & 0 deletions llvm/include/llvm/Analysis/LazyValueInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ class LazyValueInfo {
/// PredBB to OldSucc to be from PredBB to NewSucc instead.
void threadEdge(BasicBlock *PredBB, BasicBlock *OldSucc, BasicBlock *NewSucc);

/// Remove information related to this value from the cache.
void forgetValue(Value *V);

/// Inform the analysis cache that we have erased a block.
void eraseBlock(BasicBlock *BB);

Expand Down
9 changes: 9 additions & 0 deletions llvm/lib/Analysis/LazyValueInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,10 @@ class LazyValueInfoImpl {
F.print(OS, &Writer);
}

/// This is part of the update interface to remove information related to this
/// value from the cache.
void forgetValue(Value *V) { TheCache.eraseValue(V); }

/// This is part of the update interface to inform the cache
/// that a block has been deleted.
void eraseBlock(BasicBlock *BB) {
Expand Down Expand Up @@ -1969,6 +1973,11 @@ void LazyValueInfo::threadEdge(BasicBlock *PredBB, BasicBlock *OldSucc,
}
}

void LazyValueInfo::forgetValue(Value *V) {
if (PImpl)
getImpl(PImpl, AC, nullptr).forgetValue(V);
}

void LazyValueInfo::eraseBlock(BasicBlock *BB) {
if (PImpl) {
getImpl(PImpl, AC, BB->getModule()).eraseBlock(BB);
Expand Down
2 changes: 2 additions & 0 deletions llvm/lib/Transforms/Scalar/JumpThreading.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1269,6 +1269,7 @@ bool JumpThreadingPass::simplifyPartiallyRedundantLoad(LoadInst *LoadI) {
if (IsLoadCSE) {
LoadInst *NLoadI = cast<LoadInst>(AvailableVal);
combineMetadataForCSE(NLoadI, LoadI, false);
LVI->forgetValue(NLoadI);
};

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

for (LoadInst *PredLoadI : CSELoads) {
combineMetadataForCSE(PredLoadI, LoadI, true);
LVI->forgetValue(PredLoadI);
}

LoadI->replaceAllUsesWith(PN);
Expand Down
59 changes: 59 additions & 0 deletions llvm/test/Transforms/JumpThreading/invalidate-lvi.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 3
; RUN: opt -S -passes=jump-threading < %s | FileCheck %s

declare void @set_value(ptr)

declare void @bar()

define void @foo(i1 %0) {
; CHECK-LABEL: define void @foo(
; CHECK-SAME: i1 [[TMP0:%.*]]) {
; CHECK-NEXT: start:
; CHECK-NEXT: [[V:%.*]] = alloca i64, align 8
; CHECK-NEXT: call void @set_value(ptr [[V]])
; CHECK-NEXT: [[L1:%.*]] = load i64, ptr [[V]], align 8
; CHECK-NEXT: br i1 [[TMP0]], label [[BB0:%.*]], label [[BB2:%.*]]
; CHECK: bb0:
; CHECK-NEXT: [[C1:%.*]] = icmp eq i64 [[L1]], 0
; CHECK-NEXT: br i1 [[C1]], label [[BB2_THREAD:%.*]], label [[BB2]]
; CHECK: bb2.thread:
; CHECK-NEXT: store i64 0, ptr [[V]], align 8
; CHECK-NEXT: br label [[BB4:%.*]]
; CHECK: bb2:
; CHECK-NEXT: [[L2:%.*]] = phi i64 [ [[L1]], [[BB0]] ], [ [[L1]], [[START:%.*]] ]
; CHECK-NEXT: [[TMP1:%.*]] = icmp eq i64 [[L2]], 2
; CHECK-NEXT: br i1 [[TMP1]], label [[BB3:%.*]], label [[BB4]]
; CHECK: bb3:
; CHECK-NEXT: call void @bar()
; CHECK-NEXT: ret void
; CHECK: bb4:
; CHECK-NEXT: ret void
;
start:
%v = alloca i64, align 8
call void @set_value(ptr %v)
%l1 = load i64, ptr %v, align 8, !range !0
br i1 %0, label %bb0, label %bb2

bb0: ; preds = %start
%c1 = icmp eq i64 %l1, 0
br i1 %c1, label %bb1, label %bb2

bb1: ; preds = %bb0
store i64 0, ptr %v, align 8
br label %bb2

bb2: ; preds = %bb1, %bb0, %start
%l2 = load i64, ptr %v, align 8
%1 = icmp eq i64 %l2, 2
br i1 %1, label %bb3, label %bb4

bb3: ; preds = %bb2
call void @bar()
ret void

bb4: ; preds = %bb2
ret void
}

!0 = !{i64 0, i64 2}