This change adds the new unroll metadata "llvm.loop.unroll.enable" which directs the optimizer to unroll a loop fully if the trip count is known at compile time, and unroll partially if the trip count is not known at compile time. This differs from "llvm.loop.unroll.full" which explicitly does not unroll a loop if the trip count is not known at compile time With this change "#pragma unroll" generates "llvm.loop.unroll.enable" rather than "llvm.loop.unroll.full" metadata. This changes the semantics of "#pragma unroll" slightly to mean "unroll aggressively (fully or partially)" rather than "unroll fully or not at all". The motivating example for this change was some internal code with a loop marked with "#pragma unroll" which only sometimes had a compile-time trip count depending on template magic. When the trip count was a compile-time constant, everything works as expected and the loop is fully unrolled. However, when the trip count was not a compile-time constant the "#pragma unroll" explicitly disabled unrolling of the loop(!). Removing "#pragma unroll" caused the loop to be unrolled partially which was desirable from a performance perspective. llvm-svn: 244467
35 lines
1.4 KiB
C++
35 lines
1.4 KiB
C++
// RUN: %clang_cc1 -std=c++11 -verify %s
|
|
|
|
// Note that this puts the expected lines before the directives to work around
|
|
// limitations in the -verify mode.
|
|
|
|
void test(int *List, int Length) {
|
|
int i = 0;
|
|
|
|
#pragma clang loop vectorize(assume_safety)
|
|
#pragma clang loop interleave(assume_safety)
|
|
while (i + 1 < Length) {
|
|
List[i] = i;
|
|
}
|
|
|
|
/* expected-error {{expected ')'}} */ #pragma clang loop vectorize(assume_safety
|
|
/* expected-error {{expected ')'}} */ #pragma clang loop interleave(assume_safety
|
|
|
|
/* expected-error {{invalid argument; expected 'enable', 'full' or 'disable'}} */ #pragma clang loop unroll(assume_safety)
|
|
|
|
/* expected-error {{invalid argument; expected 'enable', 'assume_safety' or 'disable'}} */ #pragma clang loop vectorize(badidentifier)
|
|
/* expected-error {{invalid argument; expected 'enable', 'assume_safety' or 'disable'}} */ #pragma clang loop interleave(badidentifier)
|
|
/* expected-error {{invalid argument; expected 'enable', 'full' or 'disable'}} */ #pragma clang loop unroll(badidentifier)
|
|
while (i-7 < Length) {
|
|
List[i] = i;
|
|
}
|
|
|
|
/* expected-error {{duplicate directives 'vectorize(assume_safety)' and 'vectorize(enable)'}} */ #pragma clang loop vectorize(enable)
|
|
#pragma clang loop vectorize(assume_safety)
|
|
/* expected-error {{duplicate directives 'interleave(assume_safety)' and 'interleave(enable)'}} */ #pragma clang loop interleave(enable)
|
|
#pragma clang loop interleave(assume_safety)
|
|
while (i-9 < Length) {
|
|
List[i] = i;
|
|
}
|
|
}
|