Skip to content

Commit 2b3a410

Browse files
authored
[DA] Check element size when analyzing deps between same instruction (#148813)
DependenceAnalysis checks whether the given addresses are divisible by the element size of corresponding load/store instructions. However, this check was only executed when the two instructions (Src and Dst) are different. We must also perform the same check when Src and Dst are the same instruction. Fix the test added in #147715.
1 parent 60ae9c9 commit 2b3a410

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

llvm/lib/Analysis/DependenceAnalysis.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3670,14 +3670,12 @@ DependenceInfo::depends(Instruction *Src, Instruction *Dst,
36703670
const SCEV *SrcEv = SE->getMinusSCEV(SrcSCEV, SrcBase);
36713671
const SCEV *DstEv = SE->getMinusSCEV(DstSCEV, DstBase);
36723672

3673-
if (Src != Dst) {
3674-
// Check that memory access offsets are multiples of element sizes.
3675-
if (!SE->isKnownMultipleOf(SrcEv, EltSize, Assume) ||
3676-
!SE->isKnownMultipleOf(DstEv, EltSize, Assume)) {
3677-
LLVM_DEBUG(dbgs() << "can't analyze SCEV with different offsets\n");
3678-
return std::make_unique<Dependence>(Src, Dst,
3679-
SCEVUnionPredicate(Assume, *SE));
3680-
}
3673+
// Check that memory access offsets are multiples of element sizes.
3674+
if (!SE->isKnownMultipleOf(SrcEv, EltSize, Assume) ||
3675+
!SE->isKnownMultipleOf(DstEv, EltSize, Assume)) {
3676+
LLVM_DEBUG(dbgs() << "can't analyze SCEV with different offsets\n");
3677+
return std::make_unique<Dependence>(Src, Dst,
3678+
SCEVUnionPredicate(Assume, *SE));
36813679
}
36823680

36833681
if (!Assume.empty()) {

llvm/test/Analysis/DependenceAnalysis/DifferentOffsets.ll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
define i32 @alias_with_different_offsets(ptr nocapture %A) {
1212
; CHECK-LABEL: 'alias_with_different_offsets'
1313
; CHECK-NEXT: Src: store i32 2, ptr %arrayidx, align 1 --> Dst: store i32 2, ptr %arrayidx, align 1
14-
; CHECK-NEXT: da analyze - none!
14+
; CHECK-NEXT: da analyze - confused!
1515
; CHECK-NEXT: Src: store i32 2, ptr %arrayidx, align 1 --> Dst: %0 = load i32, ptr %A, align 1
1616
; CHECK-NEXT: da analyze - confused!
1717
; CHECK-NEXT: Src: %0 = load i32, ptr %A, align 1 --> Dst: %0 = load i32, ptr %A, align 1
@@ -207,11 +207,11 @@ end:
207207
; *((long long *)idx) = 1;
208208
; }
209209
;
210-
; FIXME: There are loop-carried dependencies across iterations in the store.
210+
; There are loop-carried dependencies across iterations in the store.
211211
define void @multidim_accesses2(ptr %A) {
212212
; CHECK-LABEL: 'multidim_accesses2'
213213
; CHECK-NEXT: Src: store i64 1, ptr %idx, align 4 --> Dst: store i64 1, ptr %idx, align 4
214-
; CHECK-NEXT: da analyze - none!
214+
; CHECK-NEXT: da analyze - confused!
215215
;
216216
entry:
217217
br label %for.i

llvm/test/Analysis/DependenceAnalysis/MIVCheckConst.ll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ define void @test(ptr %A, ptr %B, i1 %arg, i32 %n, i32 %m) #0 align 2 {
4040
; CHECK-NEXT: da analyze - confused!
4141
; CHECK-NEXT: Src: %v27 = load <32 x i32>, ptr %v25, align 256 --> Dst: %v27 = load <32 x i32>, ptr %v25, align 256
4242
; CHECK-NEXT: da analyze - consistent input [0 S S]!
43+
; CHECK-NEXT: Runtime Assumptions:
44+
; CHECK-NEXT: Equal predicate: (zext i7 (4 * (trunc i32 %v1 to i7) * (1 + (trunc i32 %n to i7))) to i32) == 0
45+
; CHECK-NEXT: Equal predicate: (8 * (zext i4 (trunc i32 %v1 to i4) to i32))<nuw><nsw> == 0
4346
; CHECK-NEXT: Src: %v27 = load <32 x i32>, ptr %v25, align 256 --> Dst: %v32 = load <32 x i32>, ptr %v30, align 128
4447
; CHECK-NEXT: da analyze - input [* S S|<]!
4548
; CHECK-NEXT: Runtime Assumptions:

0 commit comments

Comments
 (0)