[BasicAA] Support loop phis in pointsToConstantMemory()
authorNikita Popov <npopov@redhat.com>
Mon, 17 Oct 2022 10:34:55 +0000 (12:34 +0200)
committerNikita Popov <npopov@redhat.com>
Mon, 17 Oct 2022 10:34:55 +0000 (12:34 +0200)
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
llvm/test/Analysis/BasicAA/constant-memory.ll
llvm/test/Transforms/FunctionAttrs/readattrs.ll

index 9ec34fa..7b6b6f7 100644 (file)
@@ -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<AllocaInst>(V))
index a14a1ea..487d3c6 100644 (file)
@@ -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
index ba968ec..f2ea7e4 100644 (file)
@@ -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: