1; RUN: opt < %s -loop-vectorize -force-vector-width=4 -force-vector-interleave=1 -dce -instcombine -pass-remarks=loop-vectorize -pass-remarks-missed=loop-vectorize -S 2>&1 | FileCheck %s -check-prefix=OVERRIDE
2; RUN: opt < %s -loop-vectorize -force-vector-width=4 -force-vector-interleave=1 -pragma-vectorize-memory-check-threshold=6 -dce -instcombine -pass-remarks=loop-vectorize -pass-remarks-missed=loop-vectorize -S 2>&1 | FileCheck %s
3
4target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
5
6; First loop produced diagnostic pass remark.
7;CHECK: remark: {{.*}}:0:0: vectorized loop (vectorization width: 4, interleaved count: 1)
8; Second loop produces diagnostic analysis remark.
9;CHECK: remark: {{.*}}:0:0: loop not vectorized: cannot prove it is safe to reorder memory operations
10
11; First loop produced diagnostic pass remark.
12;OVERRIDE: remark: {{.*}}:0:0: vectorized loop (vectorization width: 4, interleaved count: 1)
13; Second loop produces diagnostic pass remark.
14;OVERRIDE: remark: {{.*}}:0:0: vectorized loop (vectorization width: 4, interleaved count: 1)
15
16; We are vectorizing with 6 runtime checks.
17;CHECK-LABEL: func1x6(
18;CHECK: <4 x i32>
19;CHECK: ret
20;OVERRIDE-LABEL: func1x6(
21;OVERRIDE: <4 x i32>
22;OVERRIDE: ret
23define i32 @func1x6(i32* nocapture %out, i32* nocapture %A, i32* nocapture %B, i32* nocapture %C, i32* nocapture %D, i32* nocapture %E, i32* nocapture %F) {
24entry:
25  br label %for.body
26
27for.body:                                         ; preds = %for.body, %entry
28  %i.016 = phi i64 [ 0, %entry ], [ %inc, %for.body ]
29  %arrayidx = getelementptr inbounds i32, i32* %A, i64 %i.016
30  %0 = load i32, i32* %arrayidx, align 4
31  %arrayidx1 = getelementptr inbounds i32, i32* %B, i64 %i.016
32  %1 = load i32, i32* %arrayidx1, align 4
33  %add = add nsw i32 %1, %0
34  %arrayidx2 = getelementptr inbounds i32, i32* %C, i64 %i.016
35  %2 = load i32, i32* %arrayidx2, align 4
36  %add3 = add nsw i32 %add, %2
37  %arrayidx4 = getelementptr inbounds i32, i32* %E, i64 %i.016
38  %3 = load i32, i32* %arrayidx4, align 4
39  %add5 = add nsw i32 %add3, %3
40  %arrayidx6 = getelementptr inbounds i32, i32* %F, i64 %i.016
41  %4 = load i32, i32* %arrayidx6, align 4
42  %add7 = add nsw i32 %add5, %4
43  %arrayidx8 = getelementptr inbounds i32, i32* %out, i64 %i.016
44  store i32 %add7, i32* %arrayidx8, align 4
45  %inc = add i64 %i.016, 1
46  %exitcond = icmp eq i64 %inc, 256
47  br i1 %exitcond, label %for.end, label %for.body
48
49for.end:                                          ; preds = %for.body
50  ret i32 undef
51}
52
53; We are not vectorizing with 12 runtime checks.
54;CHECK-LABEL: func2x6(
55;CHECK-NOT: <4 x i32>
56;CHECK: ret
57; We vectorize with 12 checks if a vectorization hint is provided.
58;OVERRIDE-LABEL: func2x6(
59;OVERRIDE: <4 x i32>
60;OVERRIDE: ret
61define i32 @func2x6(i32* nocapture %out, i32* nocapture %out2, i32* nocapture %A, i32* nocapture %B, i32* nocapture %C, i32* nocapture %D, i32* nocapture %E, i32* nocapture %F) {
62entry:
63  br label %for.body
64
65for.body:                                         ; preds = %for.body, %entry
66  %i.037 = phi i64 [ 0, %entry ], [ %inc, %for.body ]
67  %arrayidx = getelementptr inbounds i32, i32* %A, i64 %i.037
68  %0 = load i32, i32* %arrayidx, align 4
69  %arrayidx1 = getelementptr inbounds i32, i32* %B, i64 %i.037
70  %1 = load i32, i32* %arrayidx1, align 4
71  %add = add nsw i32 %1, %0
72  %arrayidx2 = getelementptr inbounds i32, i32* %C, i64 %i.037
73  %2 = load i32, i32* %arrayidx2, align 4
74  %add3 = add nsw i32 %add, %2
75  %arrayidx4 = getelementptr inbounds i32, i32* %E, i64 %i.037
76  %3 = load i32, i32* %arrayidx4, align 4
77  %add5 = add nsw i32 %add3, %3
78  %arrayidx6 = getelementptr inbounds i32, i32* %F, i64 %i.037
79  %4 = load i32, i32* %arrayidx6, align 4
80  %add7 = add nsw i32 %add5, %4
81  %arrayidx8 = getelementptr inbounds i32, i32* %out, i64 %i.037
82  store i32 %add7, i32* %arrayidx8, align 4
83  %5 = load i32, i32* %arrayidx, align 4
84  %6 = load i32, i32* %arrayidx1, align 4
85  %add11 = add nsw i32 %6, %5
86  %7 = load i32, i32* %arrayidx2, align 4
87  %add13 = add nsw i32 %add11, %7
88  %8 = load i32, i32* %arrayidx4, align 4
89  %add15 = add nsw i32 %add13, %8
90  %9 = load i32, i32* %arrayidx6, align 4
91  %add17 = add nsw i32 %add15, %9
92  %arrayidx18 = getelementptr inbounds i32, i32* %out2, i64 %i.037
93  store i32 %add17, i32* %arrayidx18, align 4
94  %inc = add i64 %i.037, 1
95  %exitcond = icmp eq i64 %inc, 256
96  br i1 %exitcond, label %for.end, label %for.body
97
98for.end:                                          ; preds = %for.body
99  ret i32 undef
100}
101
102