Skip to content

Commit 5224039

Browse files
authored
[AssumptionCache] Track GlobalValues as affected values. (#65425)
Fixes a corner case of the analysis: previously GlobalValues could be affected by assumptions, but were not tracked within AffectedValues. This patch allows assumptions which affect a given GlobalValue to be looked up via `assumptionsFor()`. A small update to llvm/test/Analysis/ScalarEvolution/ranges.ll was necessary due to knowledge about a global value now being propagated from AssumptionCache -> ValueTracking -> ScalarEvolution.
1 parent aea0ea5 commit 5224039

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

llvm/lib/Analysis/AssumptionCache.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ findAffectedValues(CallBase *CI, TargetTransformInfo *TTI,
6262

6363
auto AddAffected = [&Affected](Value *V, unsigned Idx =
6464
AssumptionCache::ExprResultIdx) {
65-
if (isa<Argument>(V)) {
65+
if (isa<Argument>(V) || isa<GlobalValue>(V)) {
6666
Affected.push_back({V, Idx});
6767
} else if (auto *I = dyn_cast<Instruction>(V)) {
6868
Affected.push_back({I, Idx});

llvm/test/Analysis/AssumptionCache/basic.ll

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,14 @@ entry:
2020

2121
ret void
2222
}
23+
24+
@G = external global i32
25+
define void @test2() {
26+
; CHECK-LABEL: Cached assumptions for function: test2
27+
; CHECK-NEXT: icmp ne ptr @G, null
28+
29+
entry:
30+
%cond1 = icmp ne ptr @G, null
31+
call void @llvm.assume(i1 %cond1)
32+
ret void
33+
}

llvm/test/Analysis/ScalarEvolution/ranges.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ define i64 @ashr_global() {
2929
; CHECK-LABEL: 'ashr_global'
3030
; CHECK-NEXT: Classifying expressions for: @ashr_global
3131
; CHECK-NEXT: %ashr = ashr i64 ptrtoint (ptr @G to i64), 63
32-
; CHECK-NEXT: --> %ashr U: [-1,1) S: [-1,1)
32+
; CHECK-NEXT: --> %ashr U: [0,1) S: [0,1)
3333
; CHECK-NEXT: Determining loop execution counts for: @ashr_global
3434
;
3535
%ashr = ashr i64 ptrtoint (ptr @G to i64), 63

0 commit comments

Comments
 (0)