xref: /llvm-project/llvm/test/Analysis/LoopAccessAnalysis/forward-loop-independent.ll (revision 8ebe499e07760b0d18b5721b298efc9e4a241916)
1; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py UTC_ARGS: --version 4
2; RUN: opt -passes='print<access-info>' -disable-output  < %s 2>&1 | FileCheck %s
3
4; Check that loop-independent forward dependences are discovered properly.
5;
6; FIXME: This does not actually always work which is pretty confusing.  Right
7; now there is hack in LAA that tries to figure out loop-independent forward
8; dependeces *outside* of the MemoryDepChecker logic (i.e. proper dependence
9; analysis).
10;
11; Therefore if there is only loop-independent dependences for an array
12; (i.e. the same index is used), we don't discover the forward dependence.
13; So, at ***, we add another non-I-based access of A to trigger
14; MemoryDepChecker analysis for accesses of A.
15;
16;   for (unsigned i = 0; i < 100; i++) {
17;     A[i + 1] = B[i] + 1;   // ***
18;     A[i] = B[i] + 2;
19;     C[i] = A[i] * 2;
20;   }
21
22target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
23
24define void @f(ptr noalias %A, ptr noalias %B, ptr noalias %C, i64 %N) {
25; CHECK-LABEL: 'f'
26; CHECK-NEXT:    for.body:
27; 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
28; CHECK-NEXT:  Forward loop carried data dependence that prevents store-to-load forwarding.
29; CHECK-NEXT:      Dependences:
30; CHECK-NEXT:        Forward:
31; CHECK-NEXT:            store i32 %b_p1, ptr %Aidx, align 4 ->
32; CHECK-NEXT:            %a = load i32, ptr %Aidx, align 4
33; CHECK-EMPTY:
34; CHECK-NEXT:        ForwardButPreventsForwarding:
35; CHECK-NEXT:            store i32 %b_p2, ptr %Aidx_next, align 4 ->
36; CHECK-NEXT:            %a = load i32, ptr %Aidx, align 4
37; CHECK-EMPTY:
38; CHECK-NEXT:        Forward:
39; CHECK-NEXT:            store i32 %b_p2, ptr %Aidx_next, align 4 ->
40; CHECK-NEXT:            store i32 %b_p1, ptr %Aidx, align 4
41; CHECK-EMPTY:
42; CHECK-NEXT:      Run-time memory checks:
43; CHECK-NEXT:      Grouped accesses:
44; CHECK-EMPTY:
45; CHECK-NEXT:      Non vectorizable stores to invariant address were not found in loop.
46; CHECK-NEXT:      SCEV assumptions:
47; CHECK-EMPTY:
48; CHECK-NEXT:      Expressions re-written:
49;
50
51entry:
52  br label %for.body
53
54for.body:                                         ; preds = %for.body, %entry
55  %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
56  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
57
58  %Bidx = getelementptr inbounds i32, ptr %B, i64 %indvars.iv
59  %Cidx = getelementptr inbounds i32, ptr %C, i64 %indvars.iv
60  %Aidx_next = getelementptr inbounds i32, ptr %A, i64 %indvars.iv.next
61  %Aidx = getelementptr inbounds i32, ptr %A, i64 %indvars.iv
62
63  %b = load i32, ptr %Bidx, align 4
64  %b_p2 = add i32 %b, 1
65  store i32 %b_p2, ptr %Aidx_next, align 4
66
67  %b_p1 = add i32 %b, 2
68  store i32 %b_p1, ptr %Aidx, align 4
69
70  %a = load i32, ptr %Aidx, align 4
71  %c = mul i32 %a, 2
72  store i32 %c, ptr %Cidx, align 4
73
74  %exitcond = icmp eq i64 %indvars.iv.next, %N
75  br i1 %exitcond, label %for.end, label %for.body
76
77for.end:                                          ; preds = %for.body
78  ret void
79}
80