Print vectorization analysis when loop hint is specified.
This patche and a related llvm patch solve the problem of having to explicitly enable analysis when specifying a loop hint pragma to get the diagnostics. Passing AlwasyPrint as the pass name (see below) causes the front-end to print the diagnostic if the user has specified '-Rpass-analysis' without an '=<target-pass>’. Users of loop hints can pass that compiler option without having to specify the pass and they will get diagnostics for only those loops with loop hints.
llvm-svn: 244556
diff --git a/clang/test/Frontend/optimization-remark-analysis.c b/clang/test/Frontend/optimization-remark-analysis.c
new file mode 100644
index 0000000..e71dbfd
--- /dev/null
+++ b/clang/test/Frontend/optimization-remark-analysis.c
@@ -0,0 +1,21 @@
+// RUN: %clang -O1 -fvectorize -emit-llvm -Rpass-analysis -S %s -o - 2>&1 | FileCheck %s --check-prefix=RPASS
+// RUN: %clang -O1 -fvectorize -emit-llvm -S %s -o - 2>&1 | FileCheck %s
+
+// RPASS: {{.*}}:21:1: remark: loop not vectorized: loop contains a switch statement
+// CHECK-NOT: {{.*}}:21:1: remark: loop not vectorized: loop contains a switch statement
+
+double foo(int N, int *Array) {
+ double v = 0.0;
+
+ #pragma clang loop vectorize(enable)
+ for (int i = 0; i < N; i++) {
+ switch(Array[i]) {
+ case 0: v += 1.0f; break;
+ case 1: v -= 0.5f; break;
+ case 2: v *= 2.0f; break;
+ default: v = 0.0f;
+ }
+ }
+
+ return v;
+}