asbirlea updated this revision to Diff 198540.
asbirlea added a comment.

Added test. The last RUN line fails before this patch (i.e. the flag to disable 
vectorization was not used by the new pass manager)


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D61617/new/

https://reviews.llvm.org/D61617

Files:
  lib/CodeGen/BackendUtil.cpp
  test/CodeGenCXX/no-pragma-loop.cpp


Index: test/CodeGenCXX/no-pragma-loop.cpp
===================================================================
--- /dev/null
+++ test/CodeGenCXX/no-pragma-loop.cpp
@@ -0,0 +1,25 @@
+// RUN: %clang -S -c -O1 -fvectorize -std=c++11 -emit-llvm -o - %s | FileCheck 
%s -check-prefix=CHECK-ENABLE-VECT
+// RUN: %clang -S -c -O1 -fno-vectorize -std=c++11 -emit-llvm -o - %s | 
FileCheck %s -check-prefix=CHECK-DISABLE-VECT
+// RUN: %clang -fexperimental-new-pass-manager -S -c -O1 -fvectorize 
-std=c++11 -emit-llvm -o - %s | FileCheck %s -check-prefix=CHECK-ENABLE-VECT
+// RUN: %clang -fexperimental-new-pass-manager -S -c -O1 -fno-vectorize 
-std=c++11 -emit-llvm -o - %s | FileCheck %s -check-prefix=CHECK-DISABLE-VECT
+
+// CHECK-ENABLE-VECT: for.body:
+// CHECK-ENABLE-VECT: vector.body:
+
+// CHECK-DISABLE-VECT: for.body:
+// CHECK-DISABLE-VECT-NOT: vector.body:
+
+#include <stdio.h>
+
+void for_test() {
+  double A[1000], B[1000];
+  int L = 500;
+  for (int i = 0; i < L; i++) {
+    A[i] = i;
+  }
+  for (int i = 0; i < L; i++) {
+    B[i] = A[i]*5;
+  }
+  printf("%lf %lf\n", A[0], B[0]);
+}
+
Index: lib/CodeGen/BackendUtil.cpp
===================================================================
--- lib/CodeGen/BackendUtil.cpp
+++ lib/CodeGen/BackendUtil.cpp
@@ -1025,7 +1025,14 @@
                           CodeGenOpts.DebugInfoForProfiling);
   }
 
-  PassBuilder PB(TM.get(), PipelineTuningOptions(), PGOOpt);
+  PipelineTuningOptions PTO;
+  // For historical reasons, loop interleaving is set to mirror setting for 
loop
+  // unrolling.
+  PTO.LoopInterleaving = CodeGenOpts.UnrollLoops;
+  PTO.LoopVectorization = CodeGenOpts.VectorizeLoop;
+  PTO.SLPVectorization = CodeGenOpts.VectorizeSLP;
+
+  PassBuilder PB(TM.get(), PTO, PGOOpt);
 
   // Attempt to load pass plugins and register their callbacks with PB.
   for (auto &PluginFN : CodeGenOpts.PassPlugins) {


Index: test/CodeGenCXX/no-pragma-loop.cpp
===================================================================
--- /dev/null
+++ test/CodeGenCXX/no-pragma-loop.cpp
@@ -0,0 +1,25 @@
+// RUN: %clang -S -c -O1 -fvectorize -std=c++11 -emit-llvm -o - %s | FileCheck %s -check-prefix=CHECK-ENABLE-VECT
+// RUN: %clang -S -c -O1 -fno-vectorize -std=c++11 -emit-llvm -o - %s | FileCheck %s -check-prefix=CHECK-DISABLE-VECT
+// RUN: %clang -fexperimental-new-pass-manager -S -c -O1 -fvectorize -std=c++11 -emit-llvm -o - %s | FileCheck %s -check-prefix=CHECK-ENABLE-VECT
+// RUN: %clang -fexperimental-new-pass-manager -S -c -O1 -fno-vectorize -std=c++11 -emit-llvm -o - %s | FileCheck %s -check-prefix=CHECK-DISABLE-VECT
+
+// CHECK-ENABLE-VECT: for.body:
+// CHECK-ENABLE-VECT: vector.body:
+
+// CHECK-DISABLE-VECT: for.body:
+// CHECK-DISABLE-VECT-NOT: vector.body:
+
+#include <stdio.h>
+
+void for_test() {
+  double A[1000], B[1000];
+  int L = 500;
+  for (int i = 0; i < L; i++) {
+    A[i] = i;
+  }
+  for (int i = 0; i < L; i++) {
+    B[i] = A[i]*5;
+  }
+  printf("%lf %lf\n", A[0], B[0]);
+}
+
Index: lib/CodeGen/BackendUtil.cpp
===================================================================
--- lib/CodeGen/BackendUtil.cpp
+++ lib/CodeGen/BackendUtil.cpp
@@ -1025,7 +1025,14 @@
                           CodeGenOpts.DebugInfoForProfiling);
   }
 
-  PassBuilder PB(TM.get(), PipelineTuningOptions(), PGOOpt);
+  PipelineTuningOptions PTO;
+  // For historical reasons, loop interleaving is set to mirror setting for loop
+  // unrolling.
+  PTO.LoopInterleaving = CodeGenOpts.UnrollLoops;
+  PTO.LoopVectorization = CodeGenOpts.VectorizeLoop;
+  PTO.SLPVectorization = CodeGenOpts.VectorizeSLP;
+
+  PassBuilder PB(TM.get(), PTO, PGOOpt);
 
   // Attempt to load pass plugins and register their callbacks with PB.
   for (auto &PluginFN : CodeGenOpts.PassPlugins) {
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to