From cb3bf9371c8848b49505083ad85c6165a7fb20f5 Mon Sep 17 00:00:00 2001 From: Tyler Nowicki Date: Mon, 10 Aug 2015 23:05:16 +0000 Subject: [PATCH] Append options for vectorization when pointer checking threshold is exceeded. 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 --- .../clang/Basic/DiagnosticFrontendKinds.td | 6 ++++++ lib/CodeGen/CodeGenAction.cpp | 19 +++++++++++++++++++ test/Frontend/optimization-remark-options.c | 9 +++++++++ 3 files changed, 34 insertions(+) diff --git a/include/clang/Basic/DiagnosticFrontendKinds.td b/include/clang/Basic/DiagnosticFrontendKinds.td index c041a4bff2..33b660d8db 100644 --- a/include/clang/Basic/DiagnosticFrontendKinds.td +++ b/include/clang/Basic/DiagnosticFrontendKinds.td @@ -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; +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; def warn_fe_backend_optimization_failure : Warning<"%0">, BackendInfo, InGroup, DefaultWarn; def note_fe_backend_optimization_remark_invalid_loc : Note<"could " diff --git a/lib/CodeGen/CodeGenAction.cpp b/lib/CodeGen/CodeGenAction.cpp index d47997e231..b66afad779 100644 --- a/lib/CodeGen/CodeGenAction.cpp +++ b/lib/CodeGen/CodeGenAction.cpp @@ -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(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(DI)); + return; case llvm::DK_OptimizationFailure: // Optimization failures are always handled completely by this // handler. diff --git a/test/Frontend/optimization-remark-options.c b/test/Frontend/optimization-remark-options.c index ef36ac505f..0b649f169c 100644 --- a/test/Frontend/optimization-remark-options.c +++ b/test/Frontend/optimization-remark-options.c @@ -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]; + } +} -- 2.40.0