1 // RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c++11 -emit-llvm -o - %s | FileCheck %s
2 
loop1(int * List,int Length)3 void loop1(int *List, int Length) {
4 // CHECK-LABEL: @{{.*}}loop1{{.*}}(
5 // CHECK: br label {{.*}}, !llvm.loop ![[LOOP1:.*]]
6 
7   #pragma clang loop vectorize(enable) vectorize_width(1)
8   for (int i = 0; i < Length; i++)
9     List[i] = i * 2;
10 }
11 
12 // Here, vectorize.enable should be set, obviously, but also check that
13 // metadata isn't added twice.
loop2(int * List,int Length)14 void loop2(int *List, int Length) {
15 // CHECK-LABEL: @{{.*}}loop2{{.*}}(
16 // CHECK: br label {{.*}}, !llvm.loop ![[LOOP2:.*]]
17 
18   #pragma clang loop vectorize(enable) vectorize_width(2)
19   for (int i = 0; i < Length; i++)
20     List[i] = i * 2;
21 }
22 
23 // Test that we do *not* imply vectorize.enable.
loop3(int * List,int Length)24 void loop3(int *List, int Length) {
25 // CHECK-LABEL: @{{.*}}loop3{{.*}}(
26 // CHECK: br label {{.*}}, !llvm.loop ![[LOOP3:.*]]
27 
28   #pragma clang loop vectorize_width(1)
29   for (int i = 0; i < Length; i++)
30     List[i] = i * 2;
31 }
32 
33 // Test that we *do* imply vectorize.enable.
loop4(int * List,int Length)34 void loop4(int *List, int Length) {
35 // CHECK-LABEL: @{{.*}}loop4{{.*}}(
36 // CHECK: br label {{.*}}, !llvm.loop ![[LOOP4:.*]]
37 
38   #pragma clang loop vectorize_width(2)
39   for (int i = 0; i < Length; i++)
40     List[i] = i * 2;
41 }
42 
43 // CHECK: ![[LOOP1]] = distinct !{![[LOOP1]], [[MP:![0-9]+]], ![[VEC_WIDTH_1:.*]], ![[VEC_ENABLE:.*]]}
44 // CHECK: ![[VEC_WIDTH_1]] = !{!"llvm.loop.vectorize.width", i32 1}
45 // CHECK: ![[VEC_ENABLE]] = !{!"llvm.loop.vectorize.enable", i1 true}
46 
47 // CHECK: ![[LOOP2]] = distinct !{![[LOOP2]], [[MP]], ![[VEC_WIDTH_2:.*]], ![[VEC_ENABLE]]}
48 // CHECK: ![[VEC_WIDTH_2]] = !{!"llvm.loop.vectorize.width", i32 2}
49 
50 // CHECK: ![[LOOP3]] = distinct !{![[LOOP3]], [[MP]], ![[VEC_WIDTH_1]]}
51 
52 // CHECK: ![[LOOP4]] = distinct !{![[LOOP4]], [[MP]], ![[VEC_WIDTH_2]], ![[VEC_ENABLE]]}
53