1; RUN: opt -loop-accesses -analyze -enable-new-pm=0 %s 2>&1 | FileCheck %s
2; RUN: opt -disable-output -passes='require<scalar-evolution>,require<aa>,loop(print-access-info)' %s 2>&1 | FileCheck %s
3
4target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
5
6; CHECK-LABEL: function 'forked_ptrs_different_base_same_offset':
7; CHECK-NEXT:  for.body:
8; CHECK-NEXT:    Report: cannot identify array bounds
9; CHECK-NEXT:    Dependences:
10; CHECK-NEXT:    Run-time memory checks:
11; CHECK-NEXT:    Grouped accesses:
12; CHECK-EMPTY:
13; CHECK-NEXT:    Non vectorizable stores to invariant address were not found in loop.
14; CHECK-NEXT:    SCEV assumptions:
15; CHECK-EMPTY:
16; CHECK-NEXT:    Expressions re-written:
17
18;;;; Derived from the following C code
19;; void forked_ptrs_different_base_same_offset(float *A, float *B, float *C, int *D) {
20;;   for (int i=0; i<100; i++) {
21;;     if (D[i] != 0) {
22;;       C[i] = A[i];
23;;     } else {
24;;       C[i] = B[i];
25;;     }
26;;   }
27;; }
28
29define dso_local void @forked_ptrs_different_base_same_offset(float* nocapture readonly %Base1, float* nocapture readonly %Base2, float* nocapture %Dest, i32* nocapture readonly %Preds) {
30entry:
31  br label %for.body
32
33for.cond.cleanup:
34  ret void
35
36for.body:
37  %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
38  %arrayidx = getelementptr inbounds i32, i32* %Preds, i64 %indvars.iv
39  %0 = load i32, i32* %arrayidx, align 4
40  %cmp1.not = icmp eq i32 %0, 0
41  %spec.select = select i1 %cmp1.not, float* %Base2, float* %Base1
42  %.sink.in = getelementptr inbounds float, float* %spec.select, i64 %indvars.iv
43  %.sink = load float, float* %.sink.in, align 4
44  %1 = getelementptr inbounds float, float* %Dest, i64 %indvars.iv
45  store float %.sink, float* %1, align 4
46  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
47  %exitcond.not = icmp eq i64 %indvars.iv.next, 100
48  br i1 %exitcond.not, label %for.cond.cleanup, label %for.body
49}
50
51; CHECK-LABEL: function 'forked_ptrs_same_base_different_offset':
52; CHECK-NEXT:   for.body:
53; CHECK-NEXT:     Report: cannot identify array bounds
54; CHECK-NEXT:     Dependences:
55; CHECK-NEXT:     Run-time memory checks:
56; CHECK-NEXT:     Grouped accesses:
57; CHECK-EMPTY:
58; CHECK-NEXT:     Non vectorizable stores to invariant address were not found in loop.
59; CHECK-NEXT:     SCEV assumptions:
60; CHECK-EMPTY:
61; CHECK-NEXT:     Expressions re-written:
62
63;;;; Derived from the following C code
64;; void forked_ptrs_same_base_different_offset(float *A, float *B, int *C) {
65;;   int offset;
66;;   for (int i = 0; i < 100; i++) {
67;;     if (C[i] != 0)
68;;       offset = i;
69;;     else
70;;       offset = i+1;
71;;     B[i] = A[offset];
72;;   }
73;; }
74
75define dso_local void @forked_ptrs_same_base_different_offset(float* nocapture readonly %Base, float* nocapture %Dest, i32* nocapture readonly %Preds) {
76entry:
77  br label %for.body
78
79for.cond.cleanup:                                 ; preds = %for.body
80  ret void
81
82for.body:                                         ; preds = %entry, %for.body
83  %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
84  %i.014 = phi i32 [ 0, %entry ], [ %add, %for.body ]
85  %arrayidx = getelementptr inbounds i32, i32* %Preds, i64 %indvars.iv
86  %0 = load i32, i32* %arrayidx, align 4
87  %cmp1.not = icmp eq i32 %0, 0
88  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
89  %add = add nuw nsw i32 %i.014, 1
90  %1 = trunc i64 %indvars.iv to i32
91  %offset.0 = select i1 %cmp1.not, i32 %add, i32 %1
92  %idxprom213 = zext i32 %offset.0 to i64
93  %arrayidx3 = getelementptr inbounds float, float* %Base, i64 %idxprom213
94  %2 = load float, float* %arrayidx3, align 4
95  %arrayidx5 = getelementptr inbounds float, float* %Dest, i64 %indvars.iv
96  store float %2, float* %arrayidx5, align 4
97  %exitcond.not = icmp eq i64 %indvars.iv.next, 100
98  br i1 %exitcond.not, label %for.cond.cleanup, label %for.body
99}
100
101;;;; Cases that can be handled by a forked pointer but are not currently allowed.
102
103; CHECK-LABEL: function 'forked_ptrs_uniform_and_strided_forks':
104; CHECK-NEXT:  for.body:
105; CHECK-NEXT:    Report: cannot identify array bounds
106; CHECK-NEXT:    Dependences:
107; CHECK-NEXT:    Run-time memory checks:
108; CHECK-NEXT:    Grouped accesses:
109; CHECK-EMPTY:
110; CHECK-NEXT:    Non vectorizable stores to invariant address were not found in loop.
111; CHECK-NEXT:    SCEV assumptions:
112; CHECK-EMPTY:
113; CHECK-NEXT:    Expressions re-written:
114
115;;;; Derived from forked_ptrs_same_base_different_offset with a manually
116;;;; added uniform offset and a mul to provide a stride
117
118define dso_local void @forked_ptrs_uniform_and_strided_forks(float* nocapture readonly %Base, float* nocapture %Dest, i32* nocapture readonly %Preds) {
119entry:
120  br label %for.body
121
122for.cond.cleanup:                                 ; preds = %for.body
123  ret void
124
125for.body:                                         ; preds = %entry, %for.body
126  %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
127  %i.014 = phi i32 [ 0, %entry ], [ %add, %for.body ]
128  %arrayidx = getelementptr inbounds i32, i32* %Preds, i64 %indvars.iv
129  %0 = load i32, i32* %arrayidx, align 4
130  %cmp1.not = icmp eq i32 %0, 0
131  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
132  %add = add nuw nsw i32 %i.014, 1
133  %1 = trunc i64 %indvars.iv to i32
134  %mul = mul i32 %1, 3
135  %offset.0 = select i1 %cmp1.not, i32 4, i32 %mul
136  %idxprom213 = sext i32 %offset.0 to i64
137  %arrayidx3 = getelementptr inbounds float, float* %Base, i64 %idxprom213
138  %2 = load float, float* %arrayidx3, align 4
139  %arrayidx5 = getelementptr inbounds float, float* %Dest, i64 %indvars.iv
140  store float %2, float* %arrayidx5, align 4
141  %exitcond.not = icmp eq i64 %indvars.iv.next, 100
142  br i1 %exitcond.not, label %for.cond.cleanup, label %for.body
143}
144
145; CHECK-LABEL:  function 'forked_ptrs_gather_and_contiguous_forks':
146; CHECK-NEXT:   for.body:
147; CHECK-NEXT:     Report: cannot identify array bounds
148; CHECK-NEXT:     Dependences:
149; CHECK-NEXT:     Run-time memory checks:
150; CHECK-NEXT:     Grouped accesses:
151; CHECK-EMPTY:
152; CHECK-NEXT:     Non vectorizable stores to invariant address were not found in loop.
153; CHECK-NEXT:     SCEV assumptions:
154; CHECK-EMPTY:
155; CHECK-NEXT:     Expressions re-written:
156
157;;;; Derived from forked_ptrs_same_base_different_offset with a gather
158;;;; added using Preds as an index array in addition to the per-iteration
159;;;; condition.
160
161define dso_local void @forked_ptrs_gather_and_contiguous_forks(float* nocapture readonly %Base1, float* nocapture readonly %Base2, float* nocapture %Dest, i32* nocapture readonly %Preds) {
162entry:
163  br label %for.body
164
165for.cond.cleanup:                                 ; preds = %for.body
166  ret void
167
168for.body:                                         ; preds = %entry, %for.body
169  %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
170  %arrayidx = getelementptr inbounds i32, i32* %Preds, i64 %indvars.iv
171  %0 = load i32, i32* %arrayidx, align 4
172  %cmp1.not = icmp eq i32 %0, 0
173  %arrayidx9 = getelementptr inbounds float, float* %Base2, i64 %indvars.iv
174  %idxprom4 = sext i32 %0 to i64
175  %arrayidx5 = getelementptr inbounds float, float* %Base1, i64 %idxprom4
176  %.sink.in = select i1 %cmp1.not, float* %arrayidx9, float* %arrayidx5
177  %.sink = load float, float* %.sink.in, align 4
178  %1 = getelementptr inbounds float, float* %Dest, i64 %indvars.iv
179  store float %.sink, float* %1, align 4
180  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
181  %exitcond.not = icmp eq i64 %indvars.iv.next, 100
182  br i1 %exitcond.not, label %for.cond.cleanup, label %for.body
183}
184