[llvm] [AssumptionCache] Track GlobalValues as affected values. (PR #65425)
Tyler Lanphear via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 5 17:30:35 PDT 2023
https://github.com/tylanphear created https://github.com/llvm/llvm-project/pull/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.
>From 9efedae519feae8f36cb981b41706d3f22075c61 Mon Sep 17 00:00:00 2001
From: Tyler Lanphear <tyler.lanphear at intel.com>
Date: Fri, 1 Sep 2023 15:50:25 -0700
Subject: [PATCH] [AssumptionCache] Track GlobalValues as affected values.
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.
---
llvm/lib/Analysis/AssumptionCache.cpp | 2 +-
llvm/test/Analysis/AssumptionCache/basic.ll | 11 +++++++++++
llvm/test/Analysis/ScalarEvolution/ranges.ll | 2 +-
3 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/llvm/lib/Analysis/AssumptionCache.cpp b/llvm/lib/Analysis/AssumptionCache.cpp
index b439dc1e6a76d7f..b0df934501114d2 100644
--- a/llvm/lib/Analysis/AssumptionCache.cpp
+++ b/llvm/lib/Analysis/AssumptionCache.cpp
@@ -62,7 +62,7 @@ findAffectedValues(CallBase *CI, TargetTransformInfo *TTI,
auto AddAffected = [&Affected](Value *V, unsigned Idx =
AssumptionCache::ExprResultIdx) {
- if (isa<Argument>(V)) {
+ if (isa<Argument>(V) || isa<GlobalValue>(V)) {
Affected.push_back({V, Idx});
} else if (auto *I = dyn_cast<Instruction>(V)) {
Affected.push_back({I, Idx});
diff --git a/llvm/test/Analysis/AssumptionCache/basic.ll b/llvm/test/Analysis/AssumptionCache/basic.ll
index bd4e7b6449fb750..6056ed1a4c4576d 100644
--- a/llvm/test/Analysis/AssumptionCache/basic.ll
+++ b/llvm/test/Analysis/AssumptionCache/basic.ll
@@ -20,3 +20,14 @@ entry:
ret void
}
+
+ at G = external global i32
+define void @test2() {
+; CHECK-LABEL: Cached assumptions for function: test2
+; CHECK-NEXT: icmp ne ptr @G, null
+
+entry:
+ %cond1 = icmp ne ptr @G, null
+ call void @llvm.assume(i1 %cond1)
+ ret void
+}
diff --git a/llvm/test/Analysis/ScalarEvolution/ranges.ll b/llvm/test/Analysis/ScalarEvolution/ranges.ll
index ad11a94b3963557..d42abac1971fb08 100644
--- a/llvm/test/Analysis/ScalarEvolution/ranges.ll
+++ b/llvm/test/Analysis/ScalarEvolution/ranges.ll
@@ -29,7 +29,7 @@ define i64 @ashr_global() {
; CHECK-LABEL: 'ashr_global'
; CHECK-NEXT: Classifying expressions for: @ashr_global
; CHECK-NEXT: %ashr = ashr i64 ptrtoint (ptr @G to i64), 63
-; CHECK-NEXT: --> %ashr U: [-1,1) S: [-1,1)
+; CHECK-NEXT: --> %ashr U: [0,1) S: [0,1)
; CHECK-NEXT: Determining loop execution counts for: @ashr_global
;
%ashr = ashr i64 ptrtoint (ptr @G to i64), 63
More information about the llvm-commits
mailing list