Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit ebc4674

Browse files
committed
Merging r309353 and r309355:
------------------------------------------------------------------------ r309353 | davide | 2017-07-27 19:57:43 -0700 (Thu, 27 Jul 2017) | 3 lines [JumpThreading] Add an option to dump LazyValueInfo after the run. Differential Revision: https://reviews.llvm.org/D35973 ------------------------------------------------------------------------ ------------------------------------------------------------------------ r309355 | davide | 2017-07-27 20:10:43 -0700 (Thu, 27 Jul 2017) | 24 lines [JumpThreading] Stop falsely preserving LazyValueInfo. JumpThreading claims to preserve LVI, but it doesn't preserve the analyses which LVI holds a reference to (e.g. the Dominator). In the current pass manager infrastructure, after JT runs, the PM frees these analyses (including DominatorTree) but preserves LVI. CorrelatedValuePropagation runs immediately after and queries a corrupted domtree, causing weird miscompiles. This commit disables the preservation of LVI for the time being. Eventually, we should either move LVI to a proper dependency tracking mechanism (i.e. an analyses shouldn't hold references to other analyses and compute them on demand if needed), or we should teach all the passes preserving LVI to preserve the analyses LVI depends on. The new pass manager has a mechanism to invalidate LVI in case one of the analyses it depends on becomes invalid, so this problem shouldn't exist (at least not in this immediate form), but handling of analyses holding references is still a very delicate subject. Fixes PR33917 (and rustc). ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_50@309439 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent f268da9 commit ebc4674

File tree

3 files changed

+73
-7
lines changed

3 files changed

+73
-7
lines changed

lib/Transforms/Scalar/JumpThreading.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ ImplicationSearchThreshold(
6464
"condition to use to thread over a weaker condition"),
6565
cl::init(3), cl::Hidden);
6666

67+
static cl::opt<bool> PrintLVIAfterJumpThreading(
68+
"print-lvi-after-jump-threading",
69+
cl::desc("Print the LazyValueInfo cache after JumpThreading"), cl::init(false),
70+
cl::Hidden);
71+
6772
namespace {
6873
/// This pass performs 'jump threading', which looks at blocks that have
6974
/// multiple predecessors and multiple successors. If one or more of the
@@ -93,9 +98,10 @@ namespace {
9398
bool runOnFunction(Function &F) override;
9499

95100
void getAnalysisUsage(AnalysisUsage &AU) const override {
101+
if (PrintLVIAfterJumpThreading)
102+
AU.addRequired<DominatorTreeWrapperPass>();
96103
AU.addRequired<AAResultsWrapperPass>();
97104
AU.addRequired<LazyValueInfoWrapperPass>();
98-
AU.addPreserved<LazyValueInfoWrapperPass>();
99105
AU.addPreserved<GlobalsAAWrapperPass>();
100106
AU.addRequired<TargetLibraryInfoWrapperPass>();
101107
}
@@ -137,8 +143,14 @@ bool JumpThreading::runOnFunction(Function &F) {
137143
BFI.reset(new BlockFrequencyInfo(F, *BPI, LI));
138144
}
139145

140-
return Impl.runImpl(F, TLI, LVI, AA, HasProfileData, std::move(BFI),
141-
std::move(BPI));
146+
bool Changed = Impl.runImpl(F, TLI, LVI, AA, HasProfileData, std::move(BFI),
147+
std::move(BPI));
148+
if (PrintLVIAfterJumpThreading) {
149+
dbgs() << "LVI for function '" << F.getName() << "':\n";
150+
LVI->printLVI(F, getAnalysis<DominatorTreeWrapperPass>().getDomTree(),
151+
dbgs());
152+
}
153+
return Changed;
142154
}
143155

144156
PreservedAnalyses JumpThreadingPass::run(Function &F,

test/Analysis/LazyValueAnalysis/lvi-after-jumpthreading.ll

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
; RUN: opt < %s -jump-threading -print-lazy-value-info -disable-output 2>&1 | FileCheck %s
1+
; RUN: opt < %s -jump-threading -print-lvi-after-jump-threading -disable-output 2>&1 | FileCheck %s
22

33
; Testing LVI cache after jump-threading
44

@@ -19,13 +19,10 @@ entry:
1919
; CHECK-NEXT: ; LatticeVal for: 'i32 %a' is: overdefined
2020
; CHECK-NEXT: ; LatticeVal for: 'i32 %length' is: overdefined
2121
; CHECK-NEXT: ; LatticeVal for: ' %iv = phi i32 [ 0, %entry ], [ %iv.next, %backedge ]' in BB: '%backedge' is: constantrange<0, 400>
22-
; CHECK-NEXT: ; LatticeVal for: ' %iv = phi i32 [ 0, %entry ], [ %iv.next, %backedge ]' in BB: '%exit' is: constantrange<399, 400>
2322
; CHECK-NEXT: %iv = phi i32 [ 0, %entry ], [ %iv.next, %backedge ]
2423
; CHECK-NEXT: ; LatticeVal for: ' %iv.next = add nsw i32 %iv, 1' in BB: '%backedge' is: constantrange<1, 401>
25-
; CHECK-NEXT: ; LatticeVal for: ' %iv.next = add nsw i32 %iv, 1' in BB: '%exit' is: constantrange<400, 401>
2624
; CHECK-NEXT: %iv.next = add nsw i32 %iv, 1
2725
; CHECK-NEXT: ; LatticeVal for: ' %cont = icmp slt i32 %iv.next, 400' in BB: '%backedge' is: overdefined
28-
; CHECK-NEXT: ; LatticeVal for: ' %cont = icmp slt i32 %iv.next, 400' in BB: '%exit' is: constantrange<0, -1>
2926
; CHECK-NEXT: %cont = icmp slt i32 %iv.next, 400
3027
; CHECK-NOT: loop
3128
loop:
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2+
; RUN: opt -jump-threading -correlated-propagation %s -S | FileCheck %s
3+
4+
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
5+
target triple = "x86_64-unknown-linux-gnu"
6+
7+
declare i8* @foo()
8+
9+
declare i32 @rust_eh_personality() unnamed_addr
10+
11+
; Function Attrs: nounwind
12+
declare void @llvm.assume(i1) #0
13+
14+
define void @patatino() personality i32 ()* @rust_eh_personality {
15+
; CHECK-LABEL: @patatino(
16+
; CHECK-NEXT: bb9:
17+
; CHECK-NEXT: [[T9:%.*]] = invoke i8* @foo()
18+
; CHECK-NEXT: to label [[GOOD:%.*]] unwind label [[BAD:%.*]]
19+
; CHECK: bad:
20+
; CHECK-NEXT: [[T10:%.*]] = landingpad { i8*, i32 }
21+
; CHECK-NEXT: cleanup
22+
; CHECK-NEXT: resume { i8*, i32 } [[T10]]
23+
; CHECK: good:
24+
; CHECK-NEXT: [[T11:%.*]] = icmp ne i8* [[T9]], null
25+
; CHECK-NEXT: [[T12:%.*]] = zext i1 [[T11]] to i64
26+
; CHECK-NEXT: [[COND:%.*]] = icmp eq i64 [[T12]], 1
27+
; CHECK-NEXT: br i1 [[COND]], label [[IF_TRUE:%.*]], label [[DONE:%.*]]
28+
; CHECK: if_true:
29+
; CHECK-NEXT: call void @llvm.assume(i1 [[T11]])
30+
; CHECK-NEXT: br label [[DONE]]
31+
; CHECK: done:
32+
; CHECK-NEXT: ret void
33+
;
34+
bb9:
35+
%t9 = invoke i8* @foo()
36+
to label %good unwind label %bad
37+
38+
bad:
39+
%t10 = landingpad { i8*, i32 }
40+
cleanup
41+
resume { i8*, i32 } %t10
42+
43+
good:
44+
%t11 = icmp ne i8* %t9, null
45+
%t12 = zext i1 %t11 to i64
46+
%cond = icmp eq i64 %t12, 1
47+
br i1 %cond, label %if_true, label %done
48+
49+
if_true:
50+
call void @llvm.assume(i1 %t11)
51+
br label %done
52+
53+
done:
54+
ret void
55+
}
56+
57+
attributes #0 = { nounwind }

0 commit comments

Comments
 (0)