Skip to content

Commit eca9803

Browse files
fhahnllvmbot
authored andcommitted
[ValueTracking] Treat phi as underlying obj when not decomposing further (#84339)
At the moment, getUnderlyingObjects simply continues for phis that do not refer to the same underlying object in loops, without adding them to the list of underlying objects, effectively ignoring those phis. Instead of ignoring those phis, add them to the list of underlying objects. This fixes a miscompile where LoopAccessAnalysis fails to identify a memory dependence, because no underlying objects can be found for a set of memory accesses. Fixes #82665. PR: #84339 (cherry picked from commit b274b23)
1 parent 78be28f commit eca9803

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

llvm/lib/Analysis/ValueTracking.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5986,6 +5986,8 @@ void llvm::getUnderlyingObjects(const Value *V,
59865986
if (!LI || !LI->isLoopHeader(PN->getParent()) ||
59875987
isSameUnderlyingObjectInLoop(PN, LI))
59885988
append_range(Worklist, PN->incoming_values());
5989+
else
5990+
Objects.push_back(P);
59895991
continue;
59905992
}
59915993

llvm/test/Analysis/LoopAccessAnalysis/underlying-object-loop-varying-phi.ll

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,13 @@ target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128"
77
define void @indirect_ptr_recurrences_read_write(ptr %A, ptr %B) {
88
; CHECK-LABEL: 'indirect_ptr_recurrences_read_write'
99
; CHECK-NEXT: loop:
10-
; CHECK-NEXT: Memory dependences are safe
10+
; CHECK-NEXT: Report: unsafe dependent memory operations in loop. Use #pragma clang loop distribute(enable) to allow loop distribution to attempt to isolate the offending operations into a separate loop
11+
; CHECK-NEXT: Unsafe indirect dependence.
1112
; CHECK-NEXT: Dependences:
13+
; CHECK-NEXT: IndidrectUnsafe:
14+
; CHECK-NEXT: %l = load i32, ptr %ptr.recur, align 4, !tbaa !4 ->
15+
; CHECK-NEXT: store i32 %xor, ptr %ptr.recur, align 4, !tbaa !4
16+
; CHECK-EMPTY:
1217
; CHECK-NEXT: Run-time memory checks:
1318
; CHECK-NEXT: Grouped accesses:
1419
; CHECK-EMPTY:

0 commit comments

Comments
 (0)