Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / OpenMP / irbuilder_for_iterator.cpp
blob91bbb6fc18ddb126d2721edb18f29449bd7ca470
1 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --function-signature --include-generated-funcs --replace-value-regex "__omp_offloading_[0-9a-z]+_[0-9a-z]+" "reduction_size[.].+[.]" "pl_cond[.].+[.|,]" --prefix-filecheck-ir-name _
2 // RUN: %clang_cc1 -fopenmp-enable-irbuilder -verify -fopenmp -x c++ -triple x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck %s
3 // expected-no-diagnostics
5 #ifndef HEADER
6 #define HEADER
8 struct MyIterator {
9 MyIterator(unsigned pos);
10 MyIterator(const MyIterator &other);
11 const MyIterator &operator=(const MyIterator &that);
12 MyIterator &operator++();
13 int operator-(const MyIterator &that) const;
14 MyIterator &operator+=(unsigned a);
15 MyIterator operator+(unsigned a) const;
16 bool operator==(const MyIterator &that) const;
17 bool operator!=(const MyIterator &that) const;
18 unsigned operator*() const;
21 extern "C" void workshareloop_iterator(float *a, float *b, float *c) {
22 #pragma omp for
23 for (MyIterator it = MyIterator(7); it != MyIterator(41); ++it) {
24 unsigned i = *it;
25 a[i] = b[i] * c[i];
29 #endif // HEADER
30 // CHECK-LABEL: define {{[^@]+}}@workshareloop_iterator
31 // CHECK-SAME: (ptr noundef [[A:%.*]], ptr noundef [[B:%.*]], ptr noundef [[C:%.*]]) #[[ATTR0:[0-9]+]] {
32 // CHECK-NEXT: entry:
33 // CHECK-NEXT: [[A_ADDR:%.*]] = alloca ptr, align 8
34 // CHECK-NEXT: [[B_ADDR:%.*]] = alloca ptr, align 8
35 // CHECK-NEXT: [[C_ADDR:%.*]] = alloca ptr, align 8
36 // CHECK-NEXT: [[IT:%.*]] = alloca [[STRUCT_MYITERATOR:%.*]], align 1
37 // CHECK-NEXT: [[AGG_CAPTURED:%.*]] = alloca [[STRUCT_ANON:%.*]], align 8
38 // CHECK-NEXT: [[AGG_CAPTURED1:%.*]] = alloca [[STRUCT_ANON_0:%.*]], align 1
39 // CHECK-NEXT: [[DOTCOUNT_ADDR:%.*]] = alloca i64, align 8
40 // CHECK-NEXT: [[I:%.*]] = alloca i32, align 4
41 // CHECK-NEXT: [[P_LASTITER:%.*]] = alloca i32, align 4
42 // CHECK-NEXT: [[P_LOWERBOUND:%.*]] = alloca i64, align 8
43 // CHECK-NEXT: [[P_UPPERBOUND:%.*]] = alloca i64, align 8
44 // CHECK-NEXT: [[P_STRIDE:%.*]] = alloca i64, align 8
45 // CHECK-NEXT: store ptr [[A]], ptr [[A_ADDR]], align 8
46 // CHECK-NEXT: store ptr [[B]], ptr [[B_ADDR]], align 8
47 // CHECK-NEXT: store ptr [[C]], ptr [[C_ADDR]], align 8
48 // CHECK-NEXT: call void @_ZN10MyIteratorC1Ej(ptr noundef nonnull align 1 dereferenceable(1) [[IT]], i32 noundef 7)
49 // CHECK-NEXT: [[TMP0:%.*]] = getelementptr inbounds [[STRUCT_ANON]], ptr [[AGG_CAPTURED]], i32 0, i32 0
50 // CHECK-NEXT: store ptr [[IT]], ptr [[TMP0]], align 8
51 // CHECK-NEXT: [[TMP1:%.*]] = getelementptr inbounds [[STRUCT_ANON_0]], ptr [[AGG_CAPTURED1]], i32 0, i32 0
52 // CHECK-NEXT: call void @_ZN10MyIteratorC1ERKS_(ptr noundef nonnull align 1 dereferenceable(1) [[TMP1]], ptr noundef nonnull align 1 dereferenceable(1) [[IT]])
53 // CHECK-NEXT: call void @__captured_stmt(ptr [[DOTCOUNT_ADDR]], ptr [[AGG_CAPTURED]])
54 // CHECK-NEXT: [[DOTCOUNT:%.*]] = load i64, ptr [[DOTCOUNT_ADDR]], align 8
55 // CHECK-NEXT: br label [[OMP_LOOP_PREHEADER:%.*]]
56 // CHECK: omp_loop.preheader:
57 // CHECK-NEXT: store i64 0, ptr [[P_LOWERBOUND]], align 8
58 // CHECK-NEXT: [[TMP2:%.*]] = sub i64 [[DOTCOUNT]], 1
59 // CHECK-NEXT: store i64 [[TMP2]], ptr [[P_UPPERBOUND]], align 8
60 // CHECK-NEXT: store i64 1, ptr [[P_STRIDE]], align 8
61 // CHECK-NEXT: [[OMP_GLOBAL_THREAD_NUM:%.*]] = call i32 @__kmpc_global_thread_num(ptr @[[GLOB1:[0-9]+]])
62 // CHECK-NEXT: call void @__kmpc_for_static_init_8u(ptr @[[GLOB1]], i32 [[OMP_GLOBAL_THREAD_NUM]], i32 34, ptr [[P_LASTITER]], ptr [[P_LOWERBOUND]], ptr [[P_UPPERBOUND]], ptr [[P_STRIDE]], i64 1, i64 0)
63 // CHECK-NEXT: [[TMP3:%.*]] = load i64, ptr [[P_LOWERBOUND]], align 8
64 // CHECK-NEXT: [[TMP4:%.*]] = load i64, ptr [[P_UPPERBOUND]], align 8
65 // CHECK-NEXT: [[TMP5:%.*]] = sub i64 [[TMP4]], [[TMP3]]
66 // CHECK-NEXT: [[TMP6:%.*]] = add i64 [[TMP5]], 1
67 // CHECK-NEXT: br label [[OMP_LOOP_HEADER:%.*]]
68 // CHECK: omp_loop.header:
69 // CHECK-NEXT: [[OMP_LOOP_IV:%.*]] = phi i64 [ 0, [[OMP_LOOP_PREHEADER]] ], [ [[OMP_LOOP_NEXT:%.*]], [[OMP_LOOP_INC:%.*]] ]
70 // CHECK-NEXT: br label [[OMP_LOOP_COND:%.*]]
71 // CHECK: omp_loop.cond:
72 // CHECK-NEXT: [[OMP_LOOP_CMP:%.*]] = icmp ult i64 [[OMP_LOOP_IV]], [[TMP6]]
73 // CHECK-NEXT: br i1 [[OMP_LOOP_CMP]], label [[OMP_LOOP_BODY:%.*]], label [[OMP_LOOP_EXIT:%.*]]
74 // CHECK: omp_loop.body:
75 // CHECK-NEXT: [[TMP7:%.*]] = add i64 [[OMP_LOOP_IV]], [[TMP3]]
76 // CHECK-NEXT: call void @__captured_stmt.1(ptr [[IT]], i64 [[TMP7]], ptr [[AGG_CAPTURED1]])
77 // CHECK-NEXT: [[CALL:%.*]] = call noundef i32 @_ZNK10MyIteratordeEv(ptr noundef nonnull align 1 dereferenceable(1) [[IT]])
78 // CHECK-NEXT: store i32 [[CALL]], ptr [[I]], align 4
79 // CHECK-NEXT: [[TMP8:%.*]] = load ptr, ptr [[B_ADDR]], align 8
80 // CHECK-NEXT: [[TMP9:%.*]] = load i32, ptr [[I]], align 4
81 // CHECK-NEXT: [[IDXPROM:%.*]] = zext i32 [[TMP9]] to i64
82 // CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds float, ptr [[TMP8]], i64 [[IDXPROM]]
83 // CHECK-NEXT: [[TMP10:%.*]] = load float, ptr [[ARRAYIDX]], align 4
84 // CHECK-NEXT: [[TMP11:%.*]] = load ptr, ptr [[C_ADDR]], align 8
85 // CHECK-NEXT: [[TMP12:%.*]] = load i32, ptr [[I]], align 4
86 // CHECK-NEXT: [[IDXPROM2:%.*]] = zext i32 [[TMP12]] to i64
87 // CHECK-NEXT: [[ARRAYIDX3:%.*]] = getelementptr inbounds float, ptr [[TMP11]], i64 [[IDXPROM2]]
88 // CHECK-NEXT: [[TMP13:%.*]] = load float, ptr [[ARRAYIDX3]], align 4
89 // CHECK-NEXT: [[MUL:%.*]] = fmul float [[TMP10]], [[TMP13]]
90 // CHECK-NEXT: [[TMP14:%.*]] = load ptr, ptr [[A_ADDR]], align 8
91 // CHECK-NEXT: [[TMP15:%.*]] = load i32, ptr [[I]], align 4
92 // CHECK-NEXT: [[IDXPROM4:%.*]] = zext i32 [[TMP15]] to i64
93 // CHECK-NEXT: [[ARRAYIDX5:%.*]] = getelementptr inbounds float, ptr [[TMP14]], i64 [[IDXPROM4]]
94 // CHECK-NEXT: store float [[MUL]], ptr [[ARRAYIDX5]], align 4
95 // CHECK-NEXT: br label [[OMP_LOOP_INC]]
96 // CHECK: omp_loop.inc:
97 // CHECK-NEXT: [[OMP_LOOP_NEXT]] = add nuw i64 [[OMP_LOOP_IV]], 1
98 // CHECK-NEXT: br label [[OMP_LOOP_HEADER]]
99 // CHECK: omp_loop.exit:
100 // CHECK-NEXT: call void @__kmpc_for_static_fini(ptr @[[GLOB1]], i32 [[OMP_GLOBAL_THREAD_NUM]])
101 // CHECK-NEXT: [[OMP_GLOBAL_THREAD_NUM6:%.*]] = call i32 @__kmpc_global_thread_num(ptr @[[GLOB1]])
102 // CHECK-NEXT: call void @__kmpc_barrier(ptr @[[GLOB2:[0-9]+]], i32 [[OMP_GLOBAL_THREAD_NUM6]])
103 // CHECK-NEXT: br label [[OMP_LOOP_AFTER:%.*]]
104 // CHECK: omp_loop.after:
105 // CHECK-NEXT: ret void
108 // CHECK-LABEL: define {{[^@]+}}@__captured_stmt
109 // CHECK-SAME: (ptr noundef nonnull align 8 dereferenceable(8) [[DISTANCE:%.*]], ptr noalias noundef [[__CONTEXT:%.*]]) #[[ATTR2:[0-9]+]] {
110 // CHECK-NEXT: entry:
111 // CHECK-NEXT: [[DISTANCE_ADDR:%.*]] = alloca ptr, align 8
112 // CHECK-NEXT: [[__CONTEXT_ADDR:%.*]] = alloca ptr, align 8
113 // CHECK-NEXT: [[DOTSTART:%.*]] = alloca [[STRUCT_MYITERATOR:%.*]], align 1
114 // CHECK-NEXT: [[DOTSTOP:%.*]] = alloca [[STRUCT_MYITERATOR]], align 1
115 // CHECK-NEXT: [[DOTSTEP:%.*]] = alloca i64, align 8
116 // CHECK-NEXT: store ptr [[DISTANCE]], ptr [[DISTANCE_ADDR]], align 8
117 // CHECK-NEXT: store ptr [[__CONTEXT]], ptr [[__CONTEXT_ADDR]], align 8
118 // CHECK-NEXT: [[TMP0:%.*]] = load ptr, ptr [[__CONTEXT_ADDR]], align 8
119 // CHECK-NEXT: [[TMP1:%.*]] = getelementptr inbounds [[STRUCT_ANON:%.*]], ptr [[TMP0]], i32 0, i32 0
120 // CHECK-NEXT: [[TMP2:%.*]] = load ptr, ptr [[TMP1]], align 8
121 // CHECK-NEXT: call void @_ZN10MyIteratorC1ERKS_(ptr noundef nonnull align 1 dereferenceable(1) [[DOTSTART]], ptr noundef nonnull align 1 dereferenceable(1) [[TMP2]])
122 // CHECK-NEXT: call void @_ZN10MyIteratorC1Ej(ptr noundef nonnull align 1 dereferenceable(1) [[DOTSTOP]], i32 noundef 41)
123 // CHECK-NEXT: store i64 1, ptr [[DOTSTEP]], align 8
124 // CHECK-NEXT: [[TMP3:%.*]] = load i64, ptr [[DOTSTEP]], align 8
125 // CHECK-NEXT: [[CMP:%.*]] = icmp ult i64 [[TMP3]], 0
126 // CHECK-NEXT: br i1 [[CMP]], label [[COND_TRUE:%.*]], label [[COND_FALSE:%.*]]
127 // CHECK: cond.true:
128 // CHECK-NEXT: [[CALL:%.*]] = call noundef i32 @_ZNK10MyIteratormiERKS_(ptr noundef nonnull align 1 dereferenceable(1) [[DOTSTART]], ptr noundef nonnull align 1 dereferenceable(1) [[DOTSTOP]])
129 // CHECK-NEXT: [[CONV:%.*]] = sext i32 [[CALL]] to i64
130 // CHECK-NEXT: [[TMP4:%.*]] = load i64, ptr [[DOTSTEP]], align 8
131 // CHECK-NEXT: [[SUB:%.*]] = sub i64 0, [[TMP4]]
132 // CHECK-NEXT: [[DIV:%.*]] = udiv i64 [[CONV]], [[SUB]]
133 // CHECK-NEXT: br label [[COND_END:%.*]]
134 // CHECK: cond.false:
135 // CHECK-NEXT: [[CALL1:%.*]] = call noundef i32 @_ZNK10MyIteratormiERKS_(ptr noundef nonnull align 1 dereferenceable(1) [[DOTSTOP]], ptr noundef nonnull align 1 dereferenceable(1) [[DOTSTART]])
136 // CHECK-NEXT: [[CONV2:%.*]] = sext i32 [[CALL1]] to i64
137 // CHECK-NEXT: [[TMP5:%.*]] = load i64, ptr [[DOTSTEP]], align 8
138 // CHECK-NEXT: [[DIV3:%.*]] = udiv i64 [[CONV2]], [[TMP5]]
139 // CHECK-NEXT: br label [[COND_END]]
140 // CHECK: cond.end:
141 // CHECK-NEXT: [[COND:%.*]] = phi i64 [ [[DIV]], [[COND_TRUE]] ], [ [[DIV3]], [[COND_FALSE]] ]
142 // CHECK-NEXT: [[TMP6:%.*]] = load ptr, ptr [[DISTANCE_ADDR]], align 8
143 // CHECK-NEXT: store i64 [[COND]], ptr [[TMP6]], align 8
144 // CHECK-NEXT: ret void
147 // CHECK-LABEL: define {{[^@]+}}@__captured_stmt.1
148 // CHECK-SAME: (ptr noundef nonnull align 1 dereferenceable(1) [[LOOPVAR:%.*]], i64 noundef [[LOGICAL:%.*]], ptr noalias noundef [[__CONTEXT:%.*]]) #[[ATTR2]] {
149 // CHECK-NEXT: entry:
150 // CHECK-NEXT: [[LOOPVAR_ADDR:%.*]] = alloca ptr, align 8
151 // CHECK-NEXT: [[LOGICAL_ADDR:%.*]] = alloca i64, align 8
152 // CHECK-NEXT: [[__CONTEXT_ADDR:%.*]] = alloca ptr, align 8
153 // CHECK-NEXT: [[REF_TMP:%.*]] = alloca [[STRUCT_MYITERATOR:%.*]], align 1
154 // CHECK-NEXT: store ptr [[LOOPVAR]], ptr [[LOOPVAR_ADDR]], align 8
155 // CHECK-NEXT: store i64 [[LOGICAL]], ptr [[LOGICAL_ADDR]], align 8
156 // CHECK-NEXT: store ptr [[__CONTEXT]], ptr [[__CONTEXT_ADDR]], align 8
157 // CHECK-NEXT: [[TMP0:%.*]] = load ptr, ptr [[__CONTEXT_ADDR]], align 8
158 // CHECK-NEXT: [[TMP1:%.*]] = getelementptr inbounds [[STRUCT_ANON_0:%.*]], ptr [[TMP0]], i32 0, i32 0
159 // CHECK-NEXT: [[TMP2:%.*]] = load i64, ptr [[LOGICAL_ADDR]], align 8
160 // CHECK-NEXT: [[MUL:%.*]] = mul i64 1, [[TMP2]]
161 // CHECK-NEXT: [[CONV:%.*]] = trunc i64 [[MUL]] to i32
162 // CHECK-NEXT: call void @_ZNK10MyIteratorplEj(ptr sret([[STRUCT_MYITERATOR]]) align 1 [[REF_TMP]], ptr noundef nonnull align 1 dereferenceable(1) [[TMP1]], i32 noundef [[CONV]])
163 // CHECK-NEXT: [[TMP3:%.*]] = load ptr, ptr [[LOOPVAR_ADDR]], align 8
164 // CHECK-NEXT: [[CALL:%.*]] = call noundef nonnull align 1 dereferenceable(1) ptr @_ZN10MyIteratoraSERKS_(ptr noundef nonnull align 1 dereferenceable(1) [[TMP3]], ptr noundef nonnull align 1 dereferenceable(1) [[REF_TMP]])
165 // CHECK-NEXT: ret void