xref: /minix3/external/bsd/llvm/dist/clang/test/OpenMP/simd_metadata.c (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -fopenmp=libiomp5 -triple x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck %s
2*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -fopenmp=libiomp5 -triple powerpc64-unknown-unknown -emit-llvm %s -o - | FileCheck %s
3*0a6a1f1dSLionel Sambuc 
h1(float * c,float * a,double b[],int size)4*0a6a1f1dSLionel Sambuc void h1(float *c, float *a, double b[], int size)
5*0a6a1f1dSLionel Sambuc {
6*0a6a1f1dSLionel Sambuc // CHECK-LABEL: define void @h1
7*0a6a1f1dSLionel Sambuc   int t = 0;
8*0a6a1f1dSLionel Sambuc #pragma omp simd safelen(16) linear(t) aligned(c:32) aligned(a,b)
9*0a6a1f1dSLionel Sambuc // CHECK:         [[C_PTRINT:%.+]] = ptrtoint
10*0a6a1f1dSLionel Sambuc // CHECK-NEXT:    [[C_MASKEDPTR:%.+]] = and i{{[0-9]+}} [[C_PTRINT]], 31
11*0a6a1f1dSLionel Sambuc // CHECK-NEXT:    [[C_MASKCOND:%.+]] = icmp eq i{{[0-9]+}} [[C_MASKEDPTR]], 0
12*0a6a1f1dSLionel Sambuc // CHECK-NEXT:    call void @llvm.assume(i1 [[C_MASKCOND]])
13*0a6a1f1dSLionel Sambuc // CHECK:         [[A_PTRINT:%.+]] = ptrtoint
14*0a6a1f1dSLionel Sambuc // CHECK-NEXT:    [[A_MASKEDPTR:%.+]] = and i{{[0-9]+}} [[A_PTRINT]], 15
15*0a6a1f1dSLionel Sambuc // CHECK-NEXT:    [[A_MASKCOND:%.+]] = icmp eq i{{[0-9]+}} [[A_MASKEDPTR]], 0
16*0a6a1f1dSLionel Sambuc // CHECK-NEXT:    call void @llvm.assume(i1 [[A_MASKCOND]])
17*0a6a1f1dSLionel Sambuc // CHECK:         [[B_PTRINT:%.+]] = ptrtoint
18*0a6a1f1dSLionel Sambuc // CHECK-NEXT:    [[B_MASKEDPTR:%.+]] = and i{{[0-9]+}} [[B_PTRINT]], 15
19*0a6a1f1dSLionel Sambuc // CHECK-NEXT:    [[B_MASKCOND:%.+]] = icmp eq i{{[0-9]+}} [[B_MASKEDPTR]], 0
20*0a6a1f1dSLionel Sambuc // CHECK-NEXT:    call void @llvm.assume(i1 [[B_MASKCOND]])
21*0a6a1f1dSLionel Sambuc   for (int i = 0; i < size; ++i) {
22*0a6a1f1dSLionel Sambuc     c[i] = a[i] * a[i] + b[i] * b[t];
23*0a6a1f1dSLionel Sambuc     ++t;
24*0a6a1f1dSLionel Sambuc // do not emit parallel_loop_access metadata due to usage of safelen clause.
25*0a6a1f1dSLionel Sambuc // CHECK-NOT: store float {{.+}}, float* {{.+}}, align {{.+}}, !llvm.mem.parallel_loop_access {{![0-9]+}}
26*0a6a1f1dSLionel Sambuc   }
27*0a6a1f1dSLionel Sambuc }
28*0a6a1f1dSLionel Sambuc 
h2(float * c,float * a,float * b,int size)29*0a6a1f1dSLionel Sambuc void h2(float *c, float *a, float *b, int size)
30*0a6a1f1dSLionel Sambuc {
31*0a6a1f1dSLionel Sambuc // CHECK-LABEL: define void @h2
32*0a6a1f1dSLionel Sambuc   int t = 0;
33*0a6a1f1dSLionel Sambuc #pragma omp simd linear(t)
34*0a6a1f1dSLionel Sambuc   for (int i = 0; i < size; ++i) {
35*0a6a1f1dSLionel Sambuc     c[i] = a[i] * a[i] + b[i] * b[t];
36*0a6a1f1dSLionel Sambuc     ++t;
37*0a6a1f1dSLionel Sambuc // CHECK: store float {{.+}}, float* {{.+}}, align {{.+}}, !llvm.mem.parallel_loop_access [[LOOP_H2_HEADER:![0-9]+]]
38*0a6a1f1dSLionel Sambuc   }
39*0a6a1f1dSLionel Sambuc }
40*0a6a1f1dSLionel Sambuc 
h3(float * c,float * a,float * b,int size)41*0a6a1f1dSLionel Sambuc void h3(float *c, float *a, float *b, int size)
42*0a6a1f1dSLionel Sambuc {
43*0a6a1f1dSLionel Sambuc // CHECK-LABEL: define void @h3
44*0a6a1f1dSLionel Sambuc #pragma omp simd
45*0a6a1f1dSLionel Sambuc   for (int i = 0; i < size; ++i) {
46*0a6a1f1dSLionel Sambuc     for (int j = 0; j < size; ++j) {
47*0a6a1f1dSLionel Sambuc       c[j*i] = a[i] * b[j];
48*0a6a1f1dSLionel Sambuc     }
49*0a6a1f1dSLionel Sambuc   }
50*0a6a1f1dSLionel Sambuc // do not emit parallel_loop_access for nested loop.
51*0a6a1f1dSLionel Sambuc // CHECK-NOT: store float {{.+}}, float* {{.+}}, align {{.+}}, !llvm.mem.parallel_loop_access {{![0-9]+}}
52*0a6a1f1dSLionel Sambuc }
53*0a6a1f1dSLionel Sambuc 
54*0a6a1f1dSLionel Sambuc // Metadata for h1:
55*0a6a1f1dSLionel Sambuc // CHECK: [[LOOP_H1_HEADER:![0-9]+]] = distinct !{[[LOOP_H1_HEADER]], [[LOOP_WIDTH_16:![0-9]+]], [[LOOP_VEC_ENABLE:![0-9]+]]}
56*0a6a1f1dSLionel Sambuc // CHECK: [[LOOP_WIDTH_16]] = !{!"llvm.loop.vectorize.width", i32 16}
57*0a6a1f1dSLionel Sambuc // CHECK: [[LOOP_VEC_ENABLE]] = !{!"llvm.loop.vectorize.enable", i1 true}
58*0a6a1f1dSLionel Sambuc //
59*0a6a1f1dSLionel Sambuc // Metadata for h2:
60*0a6a1f1dSLionel Sambuc // CHECK: [[LOOP_H2_HEADER]] = distinct !{[[LOOP_H2_HEADER]], [[LOOP_VEC_ENABLE]]}
61*0a6a1f1dSLionel Sambuc //
62*0a6a1f1dSLionel Sambuc // Metadata for h3:
63*0a6a1f1dSLionel Sambuc // CHECK: [[LOOP_H3_HEADER:![0-9]+]] = distinct !{[[LOOP_H3_HEADER]], [[LOOP_VEC_ENABLE]]}
64*0a6a1f1dSLionel Sambuc //
65