Skip to content

Commit 632ee84

Browse files
committed
[ValueTracking] Treat phi as underlying obj when not decomposing further
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.
1 parent 5d59fa9 commit 632ee84

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
@@ -6123,6 +6123,8 @@ void llvm::getUnderlyingObjects(const Value *V,
61236123
if (!LI || !LI->isLoopHeader(PN->getParent()) ||
61246124
isSameUnderlyingObjectInLoop(PN, LI))
61256125
append_range(Worklist, PN->incoming_values());
6126+
else
6127+
Objects.push_back(P);
61266128
continue;
61276129
}
61286130

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)