Skip to content

Commit b274b23

Browse files
authored
[ValueTracking] Treat phi as underlying obj when not decomposing further (llvm#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 llvm#82665. PR: llvm#84339
1 parent aefad27 commit b274b23

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

llvm/lib/Analysis/ValueTracking.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -6131,6 +6131,8 @@ void llvm::getUnderlyingObjects(const Value *V,
61316131
if (!LI || !LI->isLoopHeader(PN->getParent()) ||
61326132
isSameUnderlyingObjectInLoop(PN, LI))
61336133
append_range(Worklist, PN->incoming_values());
6134+
else
6135+
Objects.push_back(P);
61346136
continue;
61356137
}
61366138

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

+6-1
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)