From 436fb271862d721f9292169a979791508fad96c7 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Mon, 17 Oct 2022 12:34:55 +0200 Subject: [PATCH] [BasicAA] Support loop phis in pointsToConstantMemory() When looking for underlying objects, if we encounter one that we have already seen, then we should skip it (as it has already been checked) rather than bail out. In particular, this adds support for the case where we have a loop use of a phi recurrence. --- llvm/lib/Analysis/BasicAliasAnalysis.cpp | 2 +- llvm/test/Analysis/BasicAA/constant-memory.ll | 4 ++-- llvm/test/Transforms/FunctionAttrs/readattrs.ll | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/llvm/lib/Analysis/BasicAliasAnalysis.cpp b/llvm/lib/Analysis/BasicAliasAnalysis.cpp index 9ec34fa..7b6b6f7 100644 --- a/llvm/lib/Analysis/BasicAliasAnalysis.cpp +++ b/llvm/lib/Analysis/BasicAliasAnalysis.cpp @@ -695,7 +695,7 @@ bool BasicAAResult::pointsToConstantMemory(const MemoryLocation &Loc, do { const Value *V = getUnderlyingObject(Worklist.pop_back_val()); if (!Visited.insert(V).second) - return AAResultBase::pointsToConstantMemory(Loc, AAQI, OrLocal); + continue; // An alloca instruction defines local memory. if (OrLocal && isa(V)) diff --git a/llvm/test/Analysis/BasicAA/constant-memory.ll b/llvm/test/Analysis/BasicAA/constant-memory.ll index a14a1ea..487d3c6 100644 --- a/llvm/test/Analysis/BasicAA/constant-memory.ll +++ b/llvm/test/Analysis/BasicAA/constant-memory.ll @@ -13,9 +13,9 @@ define void @basic(ptr %p) { ret void } -; FIXME: This should be at least only Ref. +; FIXME: This could be NoModRef ; CHECK-LABEL: Function: recphi -; Both ModRef: Ptr: i32* %p <-> call void @dummy() +; CHECK: Just Ref: Ptr: i32* %p <-> call void @dummy() define void @recphi() { entry: br label %loop diff --git a/llvm/test/Transforms/FunctionAttrs/readattrs.ll b/llvm/test/Transforms/FunctionAttrs/readattrs.ll index ba968ec..f2ea7e4 100644 --- a/llvm/test/Transforms/FunctionAttrs/readattrs.ll +++ b/llvm/test/Transforms/FunctionAttrs/readattrs.ll @@ -289,7 +289,7 @@ define void @fptr_test2c(ptr %p, ptr %f) { } define void @alloca_recphi() { -; CHECK: Function Attrs: nofree norecurse nosync nounwind +; CHECK: Function Attrs: nofree norecurse nosync nounwind readnone ; CHECK-LABEL: define {{[^@]+}}@alloca_recphi ; CHECK-SAME: () #[[ATTR14:[0-9]+]] { ; CHECK-NEXT: entry: -- 2.7.4