Skip to content

Commit 875891a

Browse files
committed
[MemoryDependence] Fix invariant group store
Fix bug in MemoryDependence [and thus GVN] for invariant group. Previously MemDep didn't verify that the store was storing into a pointer rather than a store simply using a pointer. Differential Revision: https://reviews.llvm.org/D98267
1 parent 75f3f77 commit 875891a

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

llvm/lib/Analysis/MemoryDependenceAnalysis.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,9 @@ MemoryDependenceResults::getInvariantGroupPointerDependency(LoadInst *LI,
344344
// If we hit load/store with the same invariant.group metadata (and the
345345
// same pointer operand) we can assume that value pointed by pointer
346346
// operand didn't change.
347-
if ((isa<LoadInst>(U) || isa<StoreInst>(U)) &&
347+
if ((isa<LoadInst>(U) ||
348+
(isa<StoreInst>(U) &&
349+
cast<StoreInst>(U)->getPointerOperand() == Ptr)) &&
348350
U->hasMetadata(LLVMContext::MD_invariant_group))
349351
ClosestDependency = GetClosestDependency(ClosestDependency, U);
350352
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2+
; RUN: opt -gvn -S -o - < %s | FileCheck %s
3+
4+
define double @code(double* %a1) {
5+
; CHECK-LABEL: @code(
6+
; CHECK-NEXT: entry:
7+
; CHECK-NEXT: [[META:%.*]] = alloca double*, align 8
8+
; CHECK-NEXT: store double 1.234500e+00, double* [[A1:%.*]], align 8
9+
; CHECK-NEXT: store double* [[A1]], double** [[META]], align 8, !invariant.group !0
10+
; CHECK-NEXT: ret double 1.234500e+00
11+
;
12+
entry:
13+
%meta = alloca double*
14+
store double 1.23450000e+00, double* %a1, align 8
15+
store double* %a1, double** %meta, align 8, !invariant.group !0
16+
%iload = load double, double* %a1, align 8, !invariant.group !1
17+
ret double %iload
18+
}
19+
20+
!0 = distinct !{}
21+
!1 = distinct !{}

0 commit comments

Comments
 (0)