Skip to content

Commit 858a1ae

Browse files
committed
Revert r372082 "[Clang] Pragma vectorize_width() implies vectorize(enable)"
This broke the Chromium build. Consider the following code: float ScaleSumSamples_C(const float* src, float* dst, float scale, int width) { float fsum = 0.f; int i; #if defined(__clang__) #pragma clang loop vectorize_width(4) #endif for (i = 0; i < width; ++i) { float v = *src++; fsum += v * v; *dst++ = v * scale; } return fsum; } Compiling at -Oz, Clang now warns: $ clang++ -target x86_64 -Oz -c /tmp/a.cc /tmp/a.cc:1:7: warning: loop not vectorized: the optimizer was unable to perform the requested transformation; the transformation might be disabled or specified as part of an unsupported transformation ordering [-Wpass-failed=transform-warning] this suggests it's not actually enabling vectorization hard enough. At -Os it asserts instead: $ build.release/bin/clang++ -target x86_64 -Os -c /tmp/a.cc clang-10: /work/llvm.monorepo/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:2734: void llvm::InnerLoopVectorizer::emitMemRuntimeChecks(llvm::Loop*, llvm::BasicBlock*): Assertion ` !BB->getParent()->hasOptSize() && "Cannot emit memory checks when optimizing for size"' failed. Of course neither of these are what the developer expected from the pragma. > Specifying the vectorization width was supposed to implicitly enable > vectorization, except that it wasn't really doing this. It was only > setting the vectorize.width metadata, but not vectorize.enable. > > This should fix PR27643. > > Differential Revision: https://reviews.llvm.org/D66290 llvm-svn: 372225
1 parent 89ad7f7 commit 858a1ae

File tree

3 files changed

+9
-38
lines changed

3 files changed

+9
-38
lines changed

clang/lib/CodeGen/CGLoopInfo.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -270,14 +270,6 @@ LoopInfo::createLoopVectorizeMetadata(const LoopAttributes &Attrs,
270270

271271
// Setting vectorize.width
272272
if (Attrs.VectorizeWidth > 0) {
273-
// This implies vectorize.enable = true, but only add it when it is not
274-
// already enabled.
275-
if (Attrs.VectorizeEnable != LoopAttributes::Enable)
276-
Args.push_back(
277-
MDNode::get(Ctx, {MDString::get(Ctx, "llvm.loop.vectorize.enable"),
278-
ConstantAsMetadata::get(ConstantInt::get(
279-
llvm::Type::getInt1Ty(Ctx), 1))}));
280-
281273
Metadata *Vals[] = {
282274
MDString::get(Ctx, "llvm.loop.vectorize.width"),
283275
ConstantAsMetadata::get(ConstantInt::get(llvm::Type::getInt32Ty(Ctx),

clang/test/CodeGenCXX/pragma-loop-predicate.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ void test5(int *List, int Length) {
5858
List[i] = i * 2;
5959
}
6060

61+
6162
// CHECK: ![[LOOP0]] = distinct !{![[LOOP0]], !3}
6263
// CHECK-NEXT: !3 = !{!"llvm.loop.vectorize.enable", i1 true}
6364

@@ -69,7 +70,7 @@ void test5(int *List, int Length) {
6970

7071
// CHECK-NEXT: ![[LOOP3]] = distinct !{![[LOOP3]], !5, !3}
7172

72-
// CHECK-NEXT: ![[LOOP4]] = distinct !{![[LOOP4]], !3, !10}
73+
// CHECK-NEXT: ![[LOOP4]] = distinct !{![[LOOP4]], !10}
7374
// CHECK-NEXT: !10 = !{!"llvm.loop.vectorize.width", i32 1}
7475

75-
// CHECK-NEXT: ![[LOOP5]] = distinct !{![[LOOP5]], !3, !10}
76+
// CHECK-NEXT: ![[LOOP5]] = distinct !{![[LOOP5]], !10}

clang/test/CodeGenCXX/pragma-loop.cpp

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -158,41 +158,23 @@ void template_test(double *List, int Length) {
158158
for_template_constant_expression_test<double, 2, 4, 8>(List, Length);
159159
}
160160

161-
void vec_width_1(int *List, int Length) {
162-
// CHECK-LABEL: @{{.*}}vec_width_1{{.*}}(
163-
// CHECK: br label {{.*}}, !llvm.loop ![[LOOP_15:.*]]
164-
165-
#pragma clang loop vectorize(enable) vectorize_width(1)
166-
for (int i = 0; i < Length; i++)
167-
List[i] = i * 2;
168-
}
169-
170-
void width_1(int *List, int Length) {
171-
// CHECK-LABEL: @{{.*}}width_1{{.*}}(
172-
// CHECK: br label {{.*}}, !llvm.loop ![[LOOP_16:.*]]
173-
174-
#pragma clang loop vectorize_width(1)
175-
for (int i = 0; i < Length; i++)
176-
List[i] = i * 2;
177-
}
178-
179161
// CHECK: ![[LOOP_1]] = distinct !{![[LOOP_1]], ![[UNROLL_FULL:.*]]}
180162
// CHECK: ![[UNROLL_FULL]] = !{!"llvm.loop.unroll.full"}
181163

182-
// CHECK: ![[LOOP_2]] = distinct !{![[LOOP_2]], ![[UNROLL_DISABLE:.*]], ![[DISTRIBUTE_DISABLE:.*]], ![[VECTORIZE_ENABLE:.*]], ![[WIDTH_8:.*]], ![[INTERLEAVE_4:.*]]}
164+
// CHECK: ![[LOOP_2]] = distinct !{![[LOOP_2]], ![[UNROLL_DISABLE:.*]], ![[DISTRIBUTE_DISABLE:.*]], ![[WIDTH_8:.*]], ![[INTERLEAVE_4:.*]]}
183165
// CHECK: ![[UNROLL_DISABLE]] = !{!"llvm.loop.unroll.disable"}
184166
// CHECK: ![[DISTRIBUTE_DISABLE]] = !{!"llvm.loop.distribute.enable", i1 false}
185-
// CHECK: ![[VECTORIZE_ENABLE]] = !{!"llvm.loop.vectorize.enable", i1 true}
186167
// CHECK: ![[WIDTH_8]] = !{!"llvm.loop.vectorize.width", i32 8}
187168
// CHECK: ![[INTERLEAVE_4]] = !{!"llvm.loop.interleave.count", i32 4}
188169

189-
// CHECK: ![[LOOP_3]] = distinct !{![[LOOP_3]], ![[INTERLEAVE_4:.*]], ![[VECTORIZE_ENABLE]], ![[FOLLOWUP_VECTOR_3:.*]]}
170+
// CHECK: ![[LOOP_3]] = distinct !{![[LOOP_3]], ![[INTERLEAVE_4:.*]], ![[INTENABLE_1:.*]], ![[FOLLOWUP_VECTOR_3:.*]]}
171+
// CHECK: ![[INTENABLE_1]] = !{!"llvm.loop.vectorize.enable", i1 true}
190172
// CHECK: ![[FOLLOWUP_VECTOR_3]] = !{!"llvm.loop.vectorize.followup_all", ![[AFTER_VECTOR_3:.*]]}
191173
// CHECK: ![[AFTER_VECTOR_3]] = distinct !{![[AFTER_VECTOR_3]], ![[ISVECTORIZED:.*]], ![[UNROLL_8:.*]]}
192174
// CHECK: ![[ISVECTORIZED]] = !{!"llvm.loop.isvectorized"}
193175
// CHECK: ![[UNROLL_8]] = !{!"llvm.loop.unroll.count", i32 8}
194176

195-
// CHECK: ![[LOOP_4]] = distinct !{![[LOOP_4]], ![[VECTORIZE_ENABLE]], ![[WIDTH_2:.*]], ![[INTERLEAVE_2:.*]]}
177+
// CHECK: ![[LOOP_4]] = distinct !{![[LOOP_4]], ![[WIDTH_2:.*]], ![[INTERLEAVE_2:.*]]}
196178
// CHECK: ![[WIDTH_2]] = !{!"llvm.loop.vectorize.width", i32 2}
197179
// CHECK: ![[INTERLEAVE_2]] = !{!"llvm.loop.interleave.count", i32 2}
198180

@@ -203,7 +185,7 @@ void width_1(int *List, int Length) {
203185
// CHECK: ![[FOLLOWUP_VECTOR_6]] = !{!"llvm.loop.vectorize.followup_all", ![[AFTER_VECTOR_6:.*]]}
204186
// CHECK: ![[AFTER_VECTOR_6]] = distinct !{![[AFTER_VECTOR_6]], ![[ISVECTORIZED:.*]], ![[UNROLL_8:.*]]}
205187

206-
// CHECK: ![[LOOP_7]] = distinct !{![[LOOP_7]], ![[VECTORIZE_ENABLE]], ![[WIDTH_5:.*]]}
188+
// CHECK: ![[LOOP_7]] = distinct !{![[LOOP_7]], ![[WIDTH_5:.*]]}
207189
// CHECK: ![[WIDTH_5]] = !{!"llvm.loop.vectorize.width", i32 5}
208190

209191
// CHECK: ![[LOOP_8]] = distinct !{![[LOOP_8]], ![[WIDTH_5:.*]]}
@@ -231,9 +213,5 @@ void width_1(int *List, int Length) {
231213
// CHECK: ![[AFTER_VECTOR_13]] = distinct !{![[AFTER_VECTOR_13]], ![[ISVECTORIZED:.*]], ![[UNROLL_32:.*]]}
232214
// CHECK: ![[UNROLL_32]] = !{!"llvm.loop.unroll.count", i32 32}
233215

234-
// CHECK: ![[LOOP_14]] = distinct !{![[LOOP_14]], ![[VECTORIZE_ENABLE]], ![[WIDTH_10:.*]]}
216+
// CHECK: ![[LOOP_14]] = distinct !{![[LOOP_14]], ![[WIDTH_10:.*]]}
235217
// CHECK: ![[WIDTH_10]] = !{!"llvm.loop.vectorize.width", i32 10}
236-
237-
// CHECK: ![[LOOP_15]] = distinct !{![[LOOP_15]], ![[WIDTH_1]], ![[VECTORIZE_ENABLE]]}
238-
239-
// CHECK-NEXT: ![[LOOP_16]] = distinct !{![[LOOP_16]], ![[VECTORIZE_ENABLE]], ![[WIDTH_1]]}

0 commit comments

Comments
 (0)