llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.01k stars 11.96k forks source link

Rpass-analysis=loop-vectorize warns on source locations that are not in the preprocessed file #27090

Open 54aefcd4-c07d-4252-8441-723563c8826f opened 8 years ago

54aefcd4-c07d-4252-8441-723563c8826f commented 8 years ago
Bugzilla Link 26716
Version trunk
OS All
CC @echristo,@hfinkel

Extended Description

In a nutshell, I have a huge piece of code and was looking at the vectorization analysis from -Rpass-analysis=loop-vectorize which produces a lot of output.

So I went on an ifdefed some large chunk of code out (my program still compiles fine).

I get a couple of warnings by Rpass analysis that some loop cannot be vectorized, but to my surprise it points to a line (and shows the line) within the ifdefed out code.

First thought was, generate the preprocessed sources, delta it, and submit a bug but... since the code is ifdefed out, the error cannot be reproduced from the preprocessed sources.

I've been trying to come up with a minimal example that reproduces it for half an hour without any luck. So this is all I got.

54aefcd4-c07d-4252-8441-723563c8826f commented 8 years ago

Preprocessed sources of program that reproduces the errors To reproduce compile with clang-trunk as follows:

clang++ -Ofast -DNDEBUG -g3 -std=c++14 preprocessed.i -Rpass-analysis=loop-vectorize

Basically almost none of the -Rpass-analysis warnings points to a loop, but some of them (the first two) point to comments:

// a copy of the GCC Runtime Library Exception along with this program; ^

and some point to main:

int main() { ^

In my program they sometimes point to code within 200 LOC of ifdef-ed out statements (that wouldn't even compile if were to be included). Something must be off with the source file information that Rpass gets, is as if it doesn't see the same file that i do.

echristo commented 8 years ago

Any sort of testcase would be useful, yes. :)

hfinkel commented 8 years ago

@​Hal I can add a 400k LOC preprocessed source file that reproduces this issue a couple of times if you want to look into it.

You might want to attach it compressed (I don't recall what the file-size upload limit is).

54aefcd4-c07d-4252-8441-723563c8826f commented 8 years ago

@​Hal I can add a 400k LOC preprocessed source file that reproduces this issue a couple of times if you want to look into it.

54aefcd4-c07d-4252-8441-723563c8826f commented 8 years ago

So with the fully preprocessed file using -frewrite-includes i get the error at least twice, but i also get a lot of

note: could not determine the original source location for ...

is there a way to fix them in the preprocessed file? The whole source code is within that file but there is a lot of noise:

if 0 / expanded by -frewrite-includes /

include

endif / expanded by -frewrite-includes /

123 "/usr/lib64/gcc/x86_64-suse-linux/4.9/../../../../include/c++/4.9/cstddef" 1 3

// -- C++ -- forwarding header.

which might be giving trouble to clang.

I've given up in trying to generate a test case by hand.

54aefcd4-c07d-4252-8441-723563c8826f commented 8 years ago

So I just made some progress with -frewrite-includes which basically just includes the includes but leaves all other macros intact. I get results of the form:

/usr/lib64/gcc/x86_64-suse-linux/4.9/../../../../include/c++/4.9/cstddef:11:1: remark: loop not vectorized: vectorization is not beneficial and is not explicitly forced [-Rpass-analysis=loop-vectorize] // This library is distributed in the hope that it will be useful, ^ /usr/lib64/gcc/x86_64-suse-linux/4.9/../../../../include/c++/4.9/cstddef:21:1: remark: loop not vectorized: vectorization is not beneficial and is not explicitly forced [-Rpass-analysis=loop-vectorize] // a copy of the GCC Runtime Library Exception along with this program;