1; RUN: opt < %s  -loop-vectorize -mtriple=x86_64-apple-macosx10.8.0 -mcpu=corei7-avx -debug-only=loop-vectorize -stats -S 2>&1 | FileCheck %s
2; REQUIRES: asserts
3
4; CHECK: LV: Loop hints: force=enabled
5; CHECK: LV: Loop hints: force=?
6; No more loops in the module
7; CHECK-NOT: LV: Loop hints: force=
8; CHECK: 2 loop-vectorize               - Number of loops analyzed for vectorization
9; CHECK: 1 loop-vectorize               - Number of loops vectorized
10
11target 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"
12target triple = "x86_64-apple-macosx10.8.0"
13
14;
15; The source code for the test:
16;
17; #include <math.h>
18; void foo(float* restrict A, float * restrict B)
19; {
20;   for (int i = 0; i < 1000; i+=2) A[i] = sinf(B[i]);
21; }
22;
23
24;
25; This loop will be vectorized, although the scalar cost is lower than any of vector costs, but vectorization is explicitly forced in metadata.
26;
27
28define void @vectorized(float* noalias nocapture %A, float* noalias nocapture %B) {
29entry:
30  br label %for.body
31
32for.body:
33  %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %entry ]
34  %arrayidx = getelementptr inbounds float, float* %B, i64 %indvars.iv
35  %0 = load float, float* %arrayidx, align 4, !llvm.access.group !11
36  %call = tail call float @llvm.sin.f32(float %0)
37  %arrayidx2 = getelementptr inbounds float, float* %A, i64 %indvars.iv
38  store float %call, float* %arrayidx2, align 4, !llvm.access.group !11
39  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 2
40  %lftr.wideiv = trunc i64 %indvars.iv.next to i32
41  %exitcond = icmp eq i32 %lftr.wideiv, 1000
42  br i1 %exitcond, label %for.end.loopexit, label %for.body, !llvm.loop !1
43
44for.end.loopexit:
45  br label %for.end
46
47for.end:
48  ret void
49}
50
51!1 = !{!1, !2, !{!"llvm.loop.parallel_accesses", !11}}
52!2 = !{!"llvm.loop.vectorize.enable", i1 true}
53!11 = distinct !{}
54
55;
56; This method will not be vectorized, as scalar cost is lower than any of vector costs.
57;
58
59define void @not_vectorized(float* noalias nocapture %A, float* noalias nocapture %B) {
60entry:
61  br label %for.body
62
63for.body:
64  %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %entry ]
65  %arrayidx = getelementptr inbounds float, float* %B, i64 %indvars.iv
66  %0 = load float, float* %arrayidx, align 4, !llvm.access.group !13
67  %call = tail call float @llvm.sin.f32(float %0)
68  %arrayidx2 = getelementptr inbounds float, float* %A, i64 %indvars.iv
69  store float %call, float* %arrayidx2, align 4, !llvm.access.group !13
70  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 2
71  %lftr.wideiv = trunc i64 %indvars.iv.next to i32
72  %exitcond = icmp eq i32 %lftr.wideiv, 1000
73  br i1 %exitcond, label %for.end.loopexit, label %for.body, !llvm.loop !3
74
75for.end.loopexit:
76  br label %for.end
77
78for.end:
79  ret void
80}
81
82declare float @llvm.sin.f32(float) nounwind readnone
83
84; Dummy metadata
85!3 = !{!3, !{!"llvm.loop.parallel_accesses", !13}}
86!13 = distinct !{}
87
88