[PATCH] D159385: [AssumptionCache] Track GlobalValues as affected values.

Tyler Lanphear via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 1 15:40:47 PDT 2023


tylanphear created this revision.
Herald added a subscriber: hiraditya.
Herald added a project: All.
tylanphear requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D159385

Files:
  llvm/lib/Analysis/AssumptionCache.cpp
  llvm/test/Analysis/AssumptionCache/basic.ll
  llvm/test/Analysis/ScalarEvolution/ranges.ll


Index: llvm/test/Analysis/ScalarEvolution/ranges.ll
===================================================================
--- llvm/test/Analysis/ScalarEvolution/ranges.ll
+++ llvm/test/Analysis/ScalarEvolution/ranges.ll
@@ -29,7 +29,7 @@
 ; 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
Index: llvm/test/Analysis/AssumptionCache/basic.ll
===================================================================
--- llvm/test/Analysis/AssumptionCache/basic.ll
+++ llvm/test/Analysis/AssumptionCache/basic.ll
@@ -20,3 +20,14 @@
 
   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
+}
Index: llvm/lib/Analysis/AssumptionCache.cpp
===================================================================
--- llvm/lib/Analysis/AssumptionCache.cpp
+++ llvm/lib/Analysis/AssumptionCache.cpp
@@ -62,7 +62,7 @@
 
   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});


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D159385.555520.patch
Type: text/x-patch
Size: 1658 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230901/d7237d03/attachment.bin>


More information about the llvm-commits mailing list