<div dir="ltr">Forgot to mention that the original patch was written by Duncan Exon Smith and I added the test case.<br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Mar 31, 2016 at 5:34 PM, Akira Hatanaka via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: ahatanak<br>
Date: Thu Mar 31 19:34:39 2016<br>
New Revision: 265084<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=265084&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=265084&view=rev</a><br>
Log:<br>
[LoopVectorize] Don't unconditionally print vectorization diagnostics<br>
when compiling with LTO.<br>
<br>
r244523 a new class DiagnosticInfoOptimizationRemarkAnalysisAliasing for<br>
optimization analysis remarks related to pointer aliasing without<br>
guarding it in isDiagnosticEnabled in LLVMContext.cpp. This caused the<br>
diagnostic message to be printed unconditionally when compiling with<br>
LTO.<br>
<br>
This commit cleans up isDiagnosticEnabled and makes sure all the<br>
vectorization optimization remarks are guarded.<br>
<br>
rdar://problem/25382153<br>
<br>
Modified:<br>
    llvm/trunk/include/llvm/IR/DiagnosticInfo.h<br>
    llvm/trunk/lib/IR/LLVMContext.cpp<br>
    llvm/trunk/test/LTO/X86/diagnostic-handler-remarks.ll<br>
<br>
Modified: llvm/trunk/include/llvm/IR/DiagnosticInfo.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/DiagnosticInfo.h?rev=265084&r1=265083&r2=265084&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/DiagnosticInfo.h?rev=265084&r1=265083&r2=265084&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/IR/DiagnosticInfo.h (original)<br>
+++ llvm/trunk/include/llvm/IR/DiagnosticInfo.h Thu Mar 31 19:34:39 2016<br>
@@ -58,6 +58,8 @@ enum DiagnosticKind {<br>
   DK_OptimizationRemarkAnalysisFPCommute,<br>
   DK_OptimizationRemarkAnalysisAliasing,<br>
   DK_OptimizationFailure,<br>
+  DK_FirstRemark = DK_OptimizationRemark,<br>
+  DK_LastRemark = DK_OptimizationFailure,<br>
   DK_MIRParser,<br>
   DK_PGOProfile,<br>
   DK_Unsupported,<br>
@@ -340,6 +342,11 @@ public:<br>
   const char *getPassName() const { return PassName; }<br>
   const Twine &getMsg() const { return Msg; }<br>
<br>
+  static bool classof(const DiagnosticInfo *DI) {<br>
+    return DI->getKind() >= DK_FirstRemark &&<br>
+           DI->getKind() <= DK_LastRemark;<br>
+  }<br>
+<br>
 private:<br>
   /// Name of the pass that triggers this report. If this matches the<br>
   /// regular expression given in -Rpass=regexp, then the remark will<br>
<br>
Modified: llvm/trunk/lib/IR/LLVMContext.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/LLVMContext.cpp?rev=265084&r1=265083&r2=265084&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/LLVMContext.cpp?rev=265084&r1=265083&r2=265084&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/IR/LLVMContext.cpp (original)<br>
+++ llvm/trunk/lib/IR/LLVMContext.cpp Thu Mar 31 19:34:39 2016<br>
@@ -223,27 +223,9 @@ static bool isDiagnosticEnabled(const Di<br>
   // pattern, passed via one of the -pass-remarks* flags, matches the name of<br>
   // the pass that is emitting the diagnostic. If there is no match, ignore the<br>
   // diagnostic and return.<br>
-  switch (DI.getKind()) {<br>
-  case llvm::DK_OptimizationRemark:<br>
-    if (!cast<DiagnosticInfoOptimizationRemark>(DI).isEnabled())<br>
-      return false;<br>
-    break;<br>
-  case llvm::DK_OptimizationRemarkMissed:<br>
-    if (!cast<DiagnosticInfoOptimizationRemarkMissed>(DI).isEnabled())<br>
-      return false;<br>
-    break;<br>
-  case llvm::DK_OptimizationRemarkAnalysis:<br>
-    if (!cast<DiagnosticInfoOptimizationRemarkAnalysis>(DI).isEnabled())<br>
-      return false;<br>
-    break;<br>
-  case llvm::DK_OptimizationRemarkAnalysisFPCommute:<br>
-    if (!cast<DiagnosticInfoOptimizationRemarkAnalysisFPCommute>(DI)<br>
-             .isEnabled())<br>
-      return false;<br>
-    break;<br>
-  default:<br>
-    break;<br>
-  }<br>
+  if (auto *Remark = dyn_cast<DiagnosticInfoOptimizationBase>(&DI))<br>
+    return Remark->isEnabled();<br>
+<br>
   return true;<br>
 }<br>
<br>
<br>
Modified: llvm/trunk/test/LTO/X86/diagnostic-handler-remarks.ll<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/LTO/X86/diagnostic-handler-remarks.ll?rev=265084&r1=265083&r2=265084&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/LTO/X86/diagnostic-handler-remarks.ll?rev=265084&r1=265083&r2=265084&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/test/LTO/X86/diagnostic-handler-remarks.ll (original)<br>
+++ llvm/trunk/test/LTO/X86/diagnostic-handler-remarks.ll Thu Mar 31 19:34:39 2016<br>
@@ -3,31 +3,38 @@<br>
<br>
 ; Confirm that there are -pass-remarks.<br>
 ; RUN: llvm-lto -pass-remarks=inline \<br>
+; RUN:          -exported-symbol _func2 -pass-remarks-analysis=loop-vectorize \<br>
 ; RUN:          -exported-symbol _main -o %t.o %t.bc 2>&1 | \<br>
 ; RUN:     FileCheck %s -allow-empty -check-prefix=REMARKS<br>
 ; RUN: llvm-nm %t.o | FileCheck %s -check-prefix NM<br>
<br>
 ; RUN: llvm-lto -pass-remarks=inline -use-diagnostic-handler \<br>
+; RUN:          -exported-symbol _func2 -pass-remarks-analysis=loop-vectorize \<br>
 ; RUN:         -exported-symbol _main -o %t.o %t.bc 2>&1 | \<br>
 ; RUN:     FileCheck %s -allow-empty -check-prefix=REMARKS_DH<br>
 ; RUN: llvm-nm %t.o | FileCheck %s -check-prefix NM<br>
<br>
 ; Confirm that -pass-remarks are not printed by default.<br>
 ; RUN: llvm-lto \<br>
+; RUN:         -exported-symbol _func2 \<br>
 ; RUN:         -exported-symbol _main -o %t.o %t.bc 2>&1 | \<br>
 ; RUN:     FileCheck %s -allow-empty<br>
 ; RUN: llvm-nm %t.o | FileCheck %s -check-prefix NM<br>
<br>
 ; RUN: llvm-lto -use-diagnostic-handler \<br>
+; RUN:         -exported-symbol _func2 \<br>
 ; RUN:         -exported-symbol _main -o %t.o %t.bc 2>&1 | \<br>
 ; RUN:     FileCheck %s -allow-empty<br>
 ; RUN: llvm-nm %t.o | FileCheck %s -check-prefix NM<br>
<br>
-; REMARKS: remark:<br>
-; REMARKS_DH: llvm-lto: remark:<br>
+; REMARKS: remark: {{.*}} foo inlined into main<br>
+; REMARKS: remark: {{.*}} loop not vectorized: cannot prove it is safe to reorder memory operations<br>
+; REMARKS_DH: llvm-lto: remark: {{.*}} foo inlined into main<br>
+; REMARKS_DH: llvm-lto: remark: {{.*}} loop not vectorized: cannot prove it is safe to reorder memory operations<br>
 ; CHECK-NOT: remark:<br>
 ; CHECK-NOT: llvm-lto:<br>
 ; NM-NOT: foo<br>
+; NM: func2<br>
 ; NM: main<br>
<br>
 target triple = "x86_64-apple-darwin"<br>
@@ -43,3 +50,44 @@ define i32 @main() {<br>
   %i = call i32 @foo()<br>
   ret i32 %i<br>
 }<br>
+<br>
+define i32 @func2(i32* %out, i32* %out2, i32* %A, i32* %B, i32* %C, i32* %D, i32* %E, i32* %F) {<br>
+entry:<br>
+  br label %for.body<br>
+<br>
+for.body:                                         ; preds = %for.body, %entry<br>
+  %i.037 = phi i64 [ 0, %entry ], [ %inc, %for.body ]<br>
+  %arrayidx = getelementptr inbounds i32, i32* %A, i64 %i.037<br>
+  %0 = load i32, i32* %arrayidx, align 4<br>
+  %arrayidx1 = getelementptr inbounds i32, i32* %B, i64 %i.037<br>
+  %1 = load i32, i32* %arrayidx1, align 4<br>
+  %add = add nsw i32 %1, %0<br>
+  %arrayidx2 = getelementptr inbounds i32, i32* %C, i64 %i.037<br>
+  %2 = load i32, i32* %arrayidx2, align 4<br>
+  %add3 = add nsw i32 %add, %2<br>
+  %arrayidx4 = getelementptr inbounds i32, i32* %E, i64 %i.037<br>
+  %3 = load i32, i32* %arrayidx4, align 4<br>
+  %add5 = add nsw i32 %add3, %3<br>
+  %arrayidx6 = getelementptr inbounds i32, i32* %F, i64 %i.037<br>
+  %4 = load i32, i32* %arrayidx6, align 4<br>
+  %add7 = add nsw i32 %add5, %4<br>
+  %arrayidx8 = getelementptr inbounds i32, i32* %out, i64 %i.037<br>
+  store i32 %add7, i32* %arrayidx8, align 4<br>
+  %5 = load i32, i32* %arrayidx, align 4<br>
+  %6 = load i32, i32* %arrayidx1, align 4<br>
+  %add11 = add nsw i32 %6, %5<br>
+  %7 = load i32, i32* %arrayidx2, align 4<br>
+  %add13 = add nsw i32 %add11, %7<br>
+  %8 = load i32, i32* %arrayidx4, align 4<br>
+  %add15 = add nsw i32 %add13, %8<br>
+  %9 = load i32, i32* %arrayidx6, align 4<br>
+  %add17 = add nsw i32 %add15, %9<br>
+  %arrayidx18 = getelementptr inbounds i32, i32* %out2, i64 %i.037<br>
+  store i32 %add17, i32* %arrayidx18, align 4<br>
+  %inc = add i64 %i.037, 1<br>
+  %exitcond = icmp eq i64 %inc, 256<br>
+  br i1 %exitcond, label %for.end, label %for.body<br>
+<br>
+for.end:                                          ; preds = %for.body<br>
+  ret i32 undef<br>
+}<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div></div>