Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / OpenMP / masked_codegen.cpp
bloba39de12d69337f20fc9c3180e3cfdd171222e266
1 // RUN: %clang_cc1 -verify -fopenmp -x c++ -emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck %s --check-prefixes=ALL,NORMAL
2 // RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s
3 // RUN: %clang_cc1 -fopenmp -x c++ -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefixes=ALL,NORMAL
4 // RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -fopenmp -fexceptions -fcxx-exceptions -debug-info-kind=line-tables-only -x c++ -emit-llvm %s -o - | FileCheck %s --check-prefix=TERM_DEBUG
5 // RUN: %clang_cc1 -verify -fopenmp -fopenmp-enable-irbuilder -x c++ -emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck %s --check-prefixes=ALL,IRBUILDER
6 // RUN: %clang_cc1 -fopenmp -fopenmp-enable-irbuilder -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s
7 // RUN: %clang_cc1 -fopenmp -fopenmp-enable-irbuilder -x c++ -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefixes=ALL,IRBUILDER
9 // RUN: %clang_cc1 -verify -fopenmp-simd -x c++ -emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck --check-prefix SIMD-ONLY0 %s
10 // RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s
11 // RUN: %clang_cc1 -fopenmp-simd -x c++ -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY0 %s
12 // RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -fopenmp-simd -fexceptions -fcxx-exceptions -debug-info-kind=line-tables-only -x c++ -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY0 %s
13 // SIMD-ONLY0-NOT: {{__kmpc|__tgt}}
14 // expected-no-diagnostics
15 #ifndef HEADER
16 #define HEADER
18 // ALL: [[IDENT_T_TY:%.+]] = type { i32, i32, i32, i32, ptr }
20 // ALL: define {{.*}}void [[FOO:@.+]]()
22 void foo() { extern void mayThrow(); mayThrow(); }
24 // ALL-LABEL: @main
25 // TERM_DEBUG-LABEL: @main
26 int main() {
27 // ALL: [[A_ADDR:%.+]] = alloca i8
28 char a;
30 // ALL: [[GTID:%.+]] = call {{.*}}i32 @__kmpc_global_thread_num(ptr [[DEFAULT_LOC:@.+]])
31 // ALL: [[RES:%.+]] = call {{.*}}i32 @__kmpc_masked(ptr [[DEFAULT_LOC]], i32 [[GTID]], i32 0)
32 // ALL-NEXT: [[IS_MASKED:%.+]] = icmp ne i32 [[RES]], 0
33 // ALL-NEXT: br i1 [[IS_MASKED]], label {{%?}}[[THEN:.+]], label {{%?}}[[EXIT:.+]]
34 // ALL: [[THEN]]
35 // ALL-NEXT: store i8 2, ptr [[A_ADDR]]
36 // IRBUILDER-NEXT: br label %[[AFTER:[^ ,]+]]
37 // IRBUILDER: [[AFTER]]
38 // ALL-NEXT: call {{.*}}void @__kmpc_end_masked(ptr [[DEFAULT_LOC]], i32 [[GTID]])
39 // ALL-NEXT: br label {{%?}}[[EXIT]]
40 // ALL: [[EXIT]]
41 #pragma omp masked
42 a = 2;
43 // IRBUILDER: [[GTID:%.+]] = call {{.*}}i32 @__kmpc_global_thread_num(ptr [[DEFAULT_LOC:@.+]])
44 // ALL: [[RES:%.+]] = call {{.*}}i32 @__kmpc_masked(ptr [[DEFAULT_LOC]], i32 [[GTID]], i32 2)
45 // ALL-NEXT: [[IS_MASKED:%.+]] = icmp ne i32 [[RES]], 0
46 // ALL-NEXT: br i1 [[IS_MASKED]], label {{%?}}[[THEN:.+]], label {{%?}}[[EXIT:.+]]
47 // ALL: [[THEN]]
48 // IRBUILDER-NEXT: call {{.*}}void [[FOO]]()
49 // NORMAL-NEXT: invoke {{.*}}void [[FOO]]()
50 // ALL: call {{.*}}void @__kmpc_end_masked(ptr [[DEFAULT_LOC]], i32 [[GTID]])
51 // ALL-NEXT: br label {{%?}}[[EXIT]]
52 // ALL: [[EXIT]]
53 #pragma omp masked filter(2)
54 foo();
55 // ALL: store i32 9, ptr [[X:.+]],
56 // ALL: [[X_VAL:%.+]] = load i32, ptr [[X]]
57 // IRBUILDER: [[GTID:%.+]] = call {{.*}}i32 @__kmpc_global_thread_num(ptr [[DEFAULT_LOC:@.+]])
58 // ALL: [[RES:%.+]] = call {{.*}}i32 @__kmpc_masked(ptr [[DEFAULT_LOC]], i32 [[GTID]], i32 [[X_VAL]])
59 // ALL-NEXT: [[IS_MASKED:%.+]] = icmp ne i32 [[RES]], 0
60 // ALL-NEXT: br i1 [[IS_MASKED]], label {{%?}}[[THEN:.+]], label {{%?}}[[EXIT:.+]]
61 // ALL: [[THEN]]
62 // IRBUILDER-NEXT: call {{.*}}void [[FOO]]()
63 // NORMAL-NEXT: invoke {{.*}}void [[FOO]]()
64 // ALL: call {{.*}}void @__kmpc_end_masked(ptr [[DEFAULT_LOC]], i32 [[GTID]])
65 // ALL-NEXT: br label {{%?}}[[EXIT]]
66 // ALL: [[EXIT]]
67 int x = 9;
68 #pragma omp masked filter(x)
69 foo();
70 // ALL-NOT: call i32 @__kmpc_masked
71 // ALL-NOT: call void @__kmpc_end_masked
72 return a;
75 // ALL-LABEL: lambda_masked
76 // TERM_DEBUG-LABEL: lambda_masked
77 void lambda_masked(int a, int b) {
78 auto l = [=]() {
79 #pragma omp masked
81 // ALL: call i32 @__kmpc_masked(
82 int c = a + b;
86 l();
88 auto l1 = [=]() {
89 #pragma omp parallel
90 #pragma omp masked filter(1)
92 // ALL: call i32 @__kmpc_masked(
93 int c = a + b;
97 l1();
99 int y = 1;
100 auto l2 = [=](int yy) {
101 #pragma omp parallel
102 #pragma omp masked filter(yy)
104 // ALL: call i32 @__kmpc_masked(
105 int c = a + b;
109 l2(y);
112 // ALL-LABEL: parallel_masked
113 // TERM_DEBUG-LABEL: parallel_masked
114 void parallel_masked() {
115 #pragma omp parallel
116 #pragma omp masked filter(1)
117 // TERM_DEBUG-NOT: __kmpc_global_thread_num
118 // TERM_DEBUG: call i32 @__kmpc_masked({{.+}}), !dbg [[DBG_LOC_START:![0-9]+]]
119 // TERM_DEBUG: invoke void {{.*}}foo{{.*}}()
120 // TERM_DEBUG: unwind label %[[TERM_LPAD:.+]],
121 // TERM_DEBUG-NOT: __kmpc_global_thread_num
122 // TERM_DEBUG: call void @__kmpc_end_masked({{.+}}), !dbg [[DBG_LOC_END:![0-9]+]]
123 // TERM_DEBUG: [[TERM_LPAD]]
124 // TERM_DEBUG: call void @__clang_call_terminate
125 // TERM_DEBUG: unreachable
126 foo();
128 int x;
129 #pragma omp parallel
130 #pragma omp masked filter(x)
131 // TERM_DEBUG-NOT: __kmpc_global_thread_num
132 // TERM_DEBUG: call i32 @__kmpc_masked({{.+}}), !dbg [[DBG_LOC_START:![0-9]+]]
133 // TERM_DEBUG: invoke void {{.*}}foo{{.*}}()
134 // TERM_DEBUG: unwind label %[[TERM_LPAD:.+]],
135 // TERM_DEBUG-NOT: __kmpc_global_thread_num
136 // TERM_DEBUG: call void @__kmpc_end_masked({{.+}}), !dbg [[DBG_LOC_END:![0-9]+]]
137 // TERM_DEBUG: [[TERM_LPAD]]
138 // TERM_DEBUG: call void @__clang_call_terminate
139 // TERM_DEBUG: unreachable
140 foo();
142 // TERM_DEBUG-DAG: [[DBG_LOC_START]] = !DILocation(line: [[@LINE-12]],
143 // TERM_DEBUG-DAG: [[DBG_LOC_END]] = !DILocation(line: [[@LINE-3]],
145 #endif