1; RUN: opt -basicaa -loop-distribute -verify-loop-info -verify-dom-info -S \
2; RUN:   < %s | FileCheck %s
3
4; RUN: opt -basicaa -loop-distribute -verify-loop-info -verify-dom-info \
5; RUN:   -loop-accesses -analyze < %s | FileCheck %s --check-prefix=ANALYSIS
6
7; RUN: opt -basicaa -loop-distribute -loop-vectorize -force-vector-width=4 -S \
8; RUN:   < %s | FileCheck %s --check-prefix=VECTORIZE
9
10; We should distribute this loop into a safe (2nd statement) and unsafe loop
11; (1st statement):
12;   for (i = 0; i < n; i++) {
13;     A[i + 1] = A[i] * B[i];
14;     =======================
15;     C[i] = D[i] * E[i];
16;   }
17
18target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
19target triple = "x86_64-apple-macosx10.10.0"
20
21define void @f(i32* noalias %a,
22               i32* noalias %b,
23               i32* noalias %c,
24               i32* noalias %d,
25               i32* noalias %e) {
26entry:
27  br label %for.body
28
29; Verify the two distributed loops.
30
31; CHECK: entry.split.ldist1:
32; CHECK:    br label %for.body.ldist1
33; CHECK: for.body.ldist1:
34; CHECK:    %mulA.ldist1 = mul i32 %loadB.ldist1, %loadA.ldist1
35; CHECK:    br i1 %exitcond.ldist1, label %entry.split, label %for.body.ldist1
36
37; CHECK: entry.split:
38; CHECK:    br label %for.body
39; CHECK: for.body:
40; CHECK:    %mulC = mul i32 %loadD, %loadE
41; CHECK: for.end:
42
43
44; ANALYSIS: for.body:
45; ANALYSIS-NEXT: Memory dependences are safe{{$}}
46; ANALYSIS: for.body.ldist1:
47; ANALYSIS-NEXT: Store to invariant address was not found in loop
48; ANALYSIS-NEXT: Report: unsafe dependent memory operations in loop
49
50
51; VECTORIZE: mul <4 x i32>
52
53for.body:                                         ; preds = %for.body, %entry
54  %ind = phi i64 [ 0, %entry ], [ %add, %for.body ]
55
56  %arrayidxA = getelementptr inbounds i32, i32* %a, i64 %ind
57  %loadA = load i32, i32* %arrayidxA, align 4
58
59  %arrayidxB = getelementptr inbounds i32, i32* %b, i64 %ind
60  %loadB = load i32, i32* %arrayidxB, align 4
61
62  %mulA = mul i32 %loadB, %loadA
63
64  %add = add nuw nsw i64 %ind, 1
65  %arrayidxA_plus_4 = getelementptr inbounds i32, i32* %a, i64 %add
66  store i32 %mulA, i32* %arrayidxA_plus_4, align 4
67
68  %arrayidxD = getelementptr inbounds i32, i32* %d, i64 %ind
69  %loadD = load i32, i32* %arrayidxD, align 4
70
71  %arrayidxE = getelementptr inbounds i32, i32* %e, i64 %ind
72  %loadE = load i32, i32* %arrayidxE, align 4
73
74  %mulC = mul i32 %loadD, %loadE
75
76  %arrayidxC = getelementptr inbounds i32, i32* %c, i64 %ind
77  store i32 %mulC, i32* %arrayidxC, align 4
78
79  %exitcond = icmp eq i64 %add, 20
80  br i1 %exitcond, label %for.end, label %for.body
81
82for.end:                                          ; preds = %for.body
83  ret void
84}
85