[cfe-dev] Why doesn't pragma vectorize warn by default on failure
Gonzalo BG
gonzalobg88 at gmail.com
Thu Jul 23 03:29:17 PDT 2015
On Wed, Jul 22, 2015 at 11:48 PM, Tyler Nowicki <tnowicki at apple.com> wrote:
> Perhaps we should let the user specify vectorize without an option
> ‘#pragma loop vectorize’ to say ‘warn me if the structure of the loop
> cannot be vectorized otherwise select the fastest code according to the
> cost-model’.
This sounds like a great idea.
I would also like to get a full diagnostic about why vectorization failed.
That is, have -Rpass-missed=loop-vectorize and
-Rpass-analysis=loop-vectorize enabled by default.
> Its possible there is a bug in the code for generating the warning or we
missed generating it somewhere. Could you provide the loop body?
I provide a minimal example below (in Appendix A). It seems the diagnostic
triggers or not depending on the optimization level selected, which makes
sense now that I looked more into it. For example:
When compiling with O0, O2, O3, and Ofast I get no diagnostic, and in fact,
the loop is not vectorized because it is actually eliminated.
When compiling with O1 I get by default without passing any extra flags the
diagnostic I wanted:
> file.cpp:13:1: error: loop not vectorized: failed explicitly specified
loop
> vectorization [-Werror,-Wpass-failed]
>}
>^
>
>1 error generated.
It is also not hard to get "no diagnostic" even for loops that could be
vectorized (godbolt+assembly: http://goo.gl/nfeXOX). In that example, the
code is vectorized for a size of 100. But changing the size of 8 removes
the vectorization "silently". This is good and makes sense. For a size of 8
it is probably not worth it to vectorize the loop, and whatever cost model
the vectorizer uses knows this.
Thanks all of you for your help. It is greatly appreciated.
Appendix A: source code
#include <iostream>
constexpr int indirection(int *__restrict a, int i) { return a[i]; }
constexpr int foo(int start) {
int count = start;
int a[8] = {0, 1, 2, 3, 4, 5, 6, 7};
#pragma clang loop vectorize(enable)
for (int i = 0; i != 8; ++i) {
count += indirection(a, i);
}
return count;
}
int main() {
int start = 0;
std::cin >> start;
std::cout << foo(start);
return 0;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20150723/3c000b90/attachment.html>
More information about the cfe-dev
mailing list