]> granicus.if.org Git - clang/commitdiff
Append options for vectorization when pointer checking threshold is exceeded.
authorTyler Nowicki <tyler.nowicki@gmail.com>
Mon, 10 Aug 2015 23:05:16 +0000 (23:05 +0000)
committerTyler Nowicki <tyler.nowicki@gmail.com>
Mon, 10 Aug 2015 23:05:16 +0000 (23:05 +0000)
Following one of the appended options will allow the loop to be vectorized. We do not include a command line option for modifying the pointer checking threshold because there is no clang-level interface for this currently.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@244526 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticFrontendKinds.td
lib/CodeGen/CodeGenAction.cpp
test/Frontend/optimization-remark-options.c

index c041a4bff29404e1a038df2f09ca287b0ce8f423..33b660d8db7e3b0ced12c894cda0f449b97e6b29 100644 (file)
@@ -49,6 +49,12 @@ def remark_fe_backend_optimization_remark_analysis_fpcommute : Remark<"%0; "
     "allow commutativity by specifying '#pragma clang loop vectorize(enable)' "
     "before the loop or by providing the compiler option '-ffast-math'">,
     BackendInfo, InGroup<BackendOptimizationRemarkAnalysis>;
+def remark_fe_backend_optimization_remark_analysis_aliasing : Remark<"%0; "
+    "avoid runtime pointer checking when you know the arrays will always be "
+    "independent by specifying '#pragma clang loop vectorize(assume_safety)' "
+    "before the loop or by specifying 'restrict' on the array arguments. "
+    "Erroneous results will occur if these options are incorrectly applied!">,
+    BackendInfo, InGroup<BackendOptimizationRemarkAnalysis>;
 def warn_fe_backend_optimization_failure : Warning<"%0">, BackendInfo,
     InGroup<BackendOptimizationFailure>, DefaultWarn;
 def note_fe_backend_optimization_remark_invalid_loc : Note<"could "
index d47997e231018a15e0d0895b983d9a998f8636e4..b66afad7795a5bde90056ad10f6081d3bdd74d98 100644 (file)
@@ -258,6 +258,8 @@ namespace clang {
         const llvm::DiagnosticInfoOptimizationRemarkAnalysis &D);
     void OptimizationRemarkHandler(
         const llvm::DiagnosticInfoOptimizationRemarkAnalysisFPCommute &D);
+    void OptimizationRemarkHandler(
+        const llvm::DiagnosticInfoOptimizationRemarkAnalysisAliasing &D);
     void OptimizationFailureHandler(
         const llvm::DiagnosticInfoOptimizationFailure &D);
   };
@@ -513,6 +515,17 @@ void BackendConsumer::OptimizationRemarkHandler(
         D, diag::remark_fe_backend_optimization_remark_analysis_fpcommute);
 }
 
+void BackendConsumer::OptimizationRemarkHandler(
+    const llvm::DiagnosticInfoOptimizationRemarkAnalysisAliasing &D) {
+  // Optimization analysis remarks are active only if the -Rpass-analysis
+  // flag has a regular expression that matches the name of the pass
+  // name in \p D.
+  if (CodeGenOpts.OptimizationRemarkAnalysisPattern &&
+      CodeGenOpts.OptimizationRemarkAnalysisPattern->match(D.getPassName()))
+    EmitOptimizationMessage(
+        D, diag::remark_fe_backend_optimization_remark_analysis_aliasing);
+}
+
 void BackendConsumer::OptimizationFailureHandler(
     const llvm::DiagnosticInfoOptimizationFailure &D) {
   EmitOptimizationMessage(D, diag::warn_fe_backend_optimization_failure);
@@ -572,6 +585,12 @@ void BackendConsumer::DiagnosticHandlerImpl(const DiagnosticInfo &DI) {
     OptimizationRemarkHandler(
         cast<DiagnosticInfoOptimizationRemarkAnalysisFPCommute>(DI));
     return;
+  case llvm::DK_OptimizationRemarkAnalysisAliasing:
+    // Optimization remarks are always handled completely by this
+    // handler. There is no generic way of emitting them.
+    OptimizationRemarkHandler(
+        cast<DiagnosticInfoOptimizationRemarkAnalysisAliasing>(DI));
+    return;
   case llvm::DK_OptimizationFailure:
     // Optimization failures are always handled completely by this
     // handler.
index ef36ac505f56d4067ae1955a678fbbc814211f3e..0b649f169c0b958b1d30f48c5c5dd1715b415402 100644 (file)
@@ -10,3 +10,12 @@ double foo(int N) {
 
   return v;
 }
+
+// CHECK: {{.*}}:18:13: remark: loop not vectorized: cannot prove pointers refer to independent arrays in memory. The loop requires 9 runtime independence checks to vectorize the loop, but that would exceed the limit of 8 checks; avoid runtime pointer checking when you know the arrays will always be independent by specifying '#pragma clang loop vectorize(assume_safety)' before the loop or by specifying 'restrict' on the array arguments. Erroneous results will occur if these options are incorrectly applied!
+
+void foo2(int *dw, int *uw, int *A, int *B, int *C, int *D, int N) {
+  for (int i = 0; i < N; i++) {
+    dw[i] = A[i] + B[i - 1] + C[i - 2] + D[i - 3];
+    uw[i] = A[i] + B[i + 1] + C[i + 2] + D[i + 3];
+  }
+}