blob: 787ea88f9457bf0b22e81a8c16278a7c9e7a5a49 [file] [log] [blame]
Adam Nemetb0c4eae2016-03-17 20:32:37 +00001; RUN: opt -basicaa -loop-vectorize -force-vector-width=2 \
2; RUN: -force-vector-interleave=1 -S < %s \
3; RUN: | FileCheck %s -check-prefix=BOTH -check-prefix=LV
4; RUN: opt -basicaa -scoped-noalias -loop-vectorize -dse -force-vector-width=2 \
5; RUN: -force-vector-interleave=1 -S < %s \
6; RUN: | FileCheck %s -check-prefix=BOTH -check-prefix=DSE
7
8target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
9
10; This loop needs to be versioned with memchecks between {A, B} x {C} before
11; it can be vectorized.
12;
13; for (i = 0; i < n; i++) {
14; C[i] = A[i] + 1;
15; C[i] += B[i];
16; }
17;
18; Check that the corresponding noalias metadata is added to the vector loop
19; but not to the scalar loop.
20;
21; Since in the versioned vector loop C and B can no longer alias, the first
22; store to C[i] can be DSE'd.
23
24
25define void @f(i32* %a, i32* %b, i32* %c) {
26entry:
27 br label %for.body
28
29; BOTH: vector.memcheck:
30; BOTH: vector.body:
31for.body: ; preds = %for.body, %entry
32 %ind = phi i64 [ 0, %entry ], [ %inc, %for.body ]
33
34 %arrayidxA = getelementptr inbounds i32, i32* %a, i64 %ind
35; Scope 1
36; LV: = load {{.*}} !alias.scope !0
37 %loadA = load i32, i32* %arrayidxA, align 4
38
39 %add = add nuw i32 %loadA, 2
40
41 %arrayidxC = getelementptr inbounds i32, i32* %c, i64 %ind
42; Noalias with scope 1 and 6
43; LV: store {{.*}} !alias.scope !3, !noalias !5
44; DSE-NOT: store
45 store i32 %add, i32* %arrayidxC, align 4
46
47 %arrayidxB = getelementptr inbounds i32, i32* %b, i64 %ind
48; Scope 6
49; LV: = load {{.*}} !alias.scope !7
50 %loadB = load i32, i32* %arrayidxB, align 4
51
52 %add2 = add nuw i32 %add, %loadB
53
54; Noalias with scope 1 and 6
55; LV: store {{.*}} !alias.scope !3, !noalias !5
56; DSE: store
57 store i32 %add2, i32* %arrayidxC, align 4
58
59 %inc = add nuw nsw i64 %ind, 1
60 %exitcond = icmp eq i64 %inc, 20
61 br i1 %exitcond, label %for.end, label %for.body
62
63; BOTH: for.body:
64; BOTH-NOT: !alias.scope
65; BOTH-NOT: !noalias
66
67for.end: ; preds = %for.body
68 ret void
69}
70
71; LV: !0 = !{!1}
72; LV: !1 = distinct !{!1, !2}
73; LV: !2 = distinct !{!2, !"LVerDomain"}
74; LV: !3 = !{!4}
75; LV: !4 = distinct !{!4, !2}
76; LV: !5 = !{!1, !6}
77; LV: !6 = distinct !{!6, !2}
78; LV: !7 = !{!6}