add print-change diff modes that do not use colour

Summary:
The colour characters currently added to the output of -print-changed=diff
and -print-changed=diff-quiet cause difficulties when capturing the output
and examining it in an editor. Change the function to not have the colour
characters and add 2 new choices (-print-changed=cdiff and
-print-changed=cdiff-quiet) to retain the existing functionality of adding
the colour characters.

Author: Jamie Schmeiser <schmeise@ca.ibm.com>
Reviewed By: aeubanks (Arthur Eubanks) yrouban (Yevgeny Rouban)
Differential Revision: https://reviews.llvm.org/D97398
GitOrigin-RevId: 7f2ae3d55f19421a8bad4bc001e5fd7dfea0ddcb
diff --git a/include/llvm/Passes/StandardInstrumentations.h b/include/llvm/Passes/StandardInstrumentations.h
index f023a29..d24f3fb 100644
--- a/include/llvm/Passes/StandardInstrumentations.h
+++ b/include/llvm/Passes/StandardInstrumentations.h
@@ -327,8 +327,8 @@
 class ChangedIRComparer {
 public:
   ChangedIRComparer(raw_ostream &OS, const ChangedIRData &Before,
-                    const ChangedIRData &After)
-      : Before(Before), After(After), Out(OS) {}
+                    const ChangedIRData &After, bool ColourMode)
+      : Before(Before), After(After), Out(OS), UseColour(ColourMode) {}
 
   // Compare the 2 IRs.
   void compare(Any IR, StringRef Prefix, StringRef PassID, StringRef Name);
@@ -353,6 +353,7 @@
   const ChangedIRData &Before;
   const ChangedIRData &After;
   raw_ostream &Out;
+  bool UseColour;
 };
 
 // A change printer that prints out in-line differences in the basic
@@ -363,8 +364,8 @@
 // -print-module-scope does not affect this change reporter.
 class InLineChangePrinter : public TextChangeReporter<ChangedIRData> {
 public:
-  InLineChangePrinter(bool VerboseMode)
-      : TextChangeReporter<ChangedIRData>(VerboseMode) {}
+  InLineChangePrinter(bool VerboseMode, bool ColourMode)
+      : TextChangeReporter<ChangedIRData>(VerboseMode), UseColour(ColourMode) {}
   ~InLineChangePrinter() override;
   void registerCallbacks(PassInstrumentationCallbacks &PIC);
 
@@ -380,6 +381,8 @@
   // Called to compare the before and after representations of the IR.
   virtual bool same(const ChangedIRData &Before,
                     const ChangedIRData &After) override;
+
+  bool UseColour;
 };
 
 class VerifyInstrumentation {
diff --git a/lib/Passes/StandardInstrumentations.cpp b/lib/Passes/StandardInstrumentations.cpp
index 6019570..1cf1797 100644
--- a/lib/Passes/StandardInstrumentations.cpp
+++ b/lib/Passes/StandardInstrumentations.cpp
@@ -82,19 +82,26 @@
   PrintChangedVerbose,
   PrintChangedQuiet,
   PrintChangedDiffVerbose,
-  PrintChangedDiffQuiet
+  PrintChangedDiffQuiet,
+  PrintChangedColourDiffVerbose,
+  PrintChangedColourDiffQuiet
 };
 static cl::opt<ChangePrinter> PrintChanged(
     "print-changed", cl::desc("Print changed IRs"), cl::Hidden,
     cl::ValueOptional, cl::init(ChangePrinter::NoChangePrinter),
-    cl::values(clEnumValN(ChangePrinter::PrintChangedQuiet, "quiet",
-                          "Run in quiet mode"),
-               clEnumValN(ChangePrinter::PrintChangedDiffVerbose, "diff",
-                          "Display patch-like changes"),
-               clEnumValN(ChangePrinter::PrintChangedDiffQuiet, "diff-quiet",
-                          "Display patch-like changes in quiet mode"),
-               // Sentinel value for unspecified option.
-               clEnumValN(ChangePrinter::PrintChangedVerbose, "", "")));
+    cl::values(
+        clEnumValN(ChangePrinter::PrintChangedQuiet, "quiet",
+                   "Run in quiet mode"),
+        clEnumValN(ChangePrinter::PrintChangedDiffVerbose, "diff",
+                   "Display patch-like changes"),
+        clEnumValN(ChangePrinter::PrintChangedDiffQuiet, "diff-quiet",
+                   "Display patch-like changes in quiet mode"),
+        clEnumValN(ChangePrinter::PrintChangedColourDiffVerbose, "cdiff",
+                   "Display patch-like changes with color"),
+        clEnumValN(ChangePrinter::PrintChangedColourDiffQuiet, "cdiff-quiet",
+                   "Display patch-like changes in quiet mode with color"),
+        // Sentinel value for unspecified option.
+        clEnumValN(ChangePrinter::PrintChangedVerbose, "", "")));
 
 // An option that supports the -print-changed option.  See
 // the description for -print-changed for an explanation of the use
@@ -1112,7 +1119,8 @@
   SmallString<20> Banner =
       formatv("*** IR Dump After {0} ***{1}\n", PassID, Name);
   Out << Banner;
-  ChangedIRComparer(Out, Before, After).compare(IR, "", PassID, Name);
+  ChangedIRComparer(Out, Before, After, UseColour)
+      .compare(IR, "", PassID, Name);
   Out << "\n";
 }
 
@@ -1133,8 +1141,9 @@
       Before, After, [&](const ChangedBlockData *B, const ChangedBlockData *A) {
         StringRef BStr = B ? B->getBody() : "\n";
         StringRef AStr = A ? A->getBody() : "\n";
-        const std::string Removed = "\033[31m-%l\033[0m\n";
-        const std::string Added = "\033[32m+%l\033[0m\n";
+        const std::string Removed =
+            UseColour ? "\033[31m-%l\033[0m\n" : "-%l\n";
+        const std::string Added = UseColour ? "\033[32m+%l\033[0m\n" : "+%l\n";
         const std::string NoChange = " %l\n";
         Out << doSystemDiff(BStr, AStr, Removed, Added, NoChange);
       });
@@ -1142,7 +1151,9 @@
 
 void InLineChangePrinter::registerCallbacks(PassInstrumentationCallbacks &PIC) {
   if (PrintChanged == ChangePrinter::PrintChangedDiffVerbose ||
-      PrintChanged == ChangePrinter::PrintChangedDiffQuiet)
+      PrintChanged == ChangePrinter::PrintChangedDiffQuiet ||
+      PrintChanged == ChangePrinter::PrintChangedColourDiffVerbose ||
+      PrintChanged == ChangePrinter::PrintChangedColourDiffQuiet)
     TextChangeReporter<ChangedIRData>::registerRequiredCallbacks(PIC);
 }
 
@@ -1150,7 +1161,11 @@
                                                    bool VerifyEach)
     : PrintPass(DebugLogging), OptNone(DebugLogging),
       PrintChangedIR(PrintChanged == ChangePrinter::PrintChangedVerbose),
-      PrintChangedDiff(PrintChanged == ChangePrinter::PrintChangedDiffVerbose),
+      PrintChangedDiff(
+          PrintChanged == ChangePrinter::PrintChangedDiffVerbose ||
+              PrintChanged == ChangePrinter::PrintChangedColourDiffVerbose,
+          PrintChanged == ChangePrinter::PrintChangedColourDiffVerbose ||
+              PrintChanged == ChangePrinter::PrintChangedColourDiffQuiet),
       Verify(DebugLogging), VerifyEach(VerifyEach) {}
 
 void StandardInstrumentations::registerCallbacks(
diff --git a/test/Other/ChangePrinters/print-changed-diff.ll b/test/Other/ChangePrinters/print-changed-diff.ll
index 45322c2..b5d408f 100644
--- a/test/Other/ChangePrinters/print-changed-diff.ll
+++ b/test/Other/ChangePrinters/print-changed-diff.ll
@@ -62,6 +62,70 @@
 ; instsimplify is run on f will result in changes
 ; RUN: opt -S -print-changed=diff-quiet -passes="instsimplify,instsimplify" -filter-print-funcs=f  2>&1 -o /dev/null < %s | FileCheck %s --check-prefix=CHECK-DIFF-QUIET-MULT-PASSES-FILTER-FUNC
 
+; Simple checks of -print-changed=cdiff
+;
+; Note that (mostly) only the banners are checked.
+;
+; Simple functionality check.
+; RUN: opt -S -print-changed=cdiff -passes=instsimplify 2>&1 -o /dev/null < %s | FileCheck %s --check-prefix=CHECK-CDIFF-SIMPLE
+;
+; Check that only the passes that change the IR are printed and that the
+; others (including g) are filtered out.
+; RUN: opt -S -print-changed=cdiff -passes=instsimplify -filter-print-funcs=f  2>&1 -o /dev/null < %s | FileCheck %s --check-prefix=CHECK-CDIFF-FUNC-FILTER
+;
+; Check that the reporting of IRs respects is not affected by
+; -print-module-scope
+; RUN: opt -S -print-changed=cdiff -passes=instsimplify -print-module-scope 2>&1 -o /dev/null < %s | FileCheck %s --check-prefix=CHECK-CDIFF-PRINT-MOD-SCOPE
+;
+; Check that reporting of multiple functions happens
+; RUN: opt -S -print-changed=cdiff -passes=instsimplify -filter-print-funcs="f,g" 2>&1 -o /dev/null < %s | FileCheck %s --check-prefix=CHECK-CDIFF-FILTER-MULT-FUNC
+;
+; Check that the reporting of IRs respects -filter-passes
+; RUN: opt -S -print-changed=cdiff -passes="instsimplify,no-op-function" -filter-passes="NoOpFunctionPass" 2>&1 -o /dev/null < %s | FileCheck %s --check-prefix=CHECK-CDIFF-FILTER-PASSES
+;
+; Check that the reporting of IRs respects -filter-passes with multiple passes
+; RUN: opt -S -print-changed=cdiff -passes="instsimplify,no-op-function" -filter-passes="NoOpFunctionPass,InstSimplifyPass" 2>&1 -o /dev/null < %s | FileCheck %s --check-prefix=CHECK-CDIFF-FILTER-MULT-PASSES
+;
+; Check that the reporting of IRs respects both -filter-passes and -filter-print-funcs
+; RUN: opt -S -print-changed=cdiff -passes="instsimplify,no-op-function" -filter-passes="NoOpFunctionPass,InstSimplifyPass" -filter-print-funcs=f 2>&1 -o /dev/null < %s | FileCheck %s --check-prefix=CHECK-CDIFF-FILTER-FUNC-PASSES
+;
+; Check that repeated passes that change the IR are printed and that the
+; others (including g) are filtered out.  Note that only the first time
+; instsimplify is run on f will result in changes
+; RUN: opt -S -print-changed=cdiff -passes="instsimplify,instsimplify" -filter-print-funcs=f  2>&1 -o /dev/null < %s | FileCheck %s --check-prefix=CHECK-CDIFF-MULT-PASSES-FILTER-FUNC
+;
+; Simple checks of -print-changed=cdiff-quiet
+;
+; Note that (mostly) only the banners are checked.
+;
+; Simple functionality check.
+; RUN: opt -S -print-changed=cdiff-quiet -passes=instsimplify 2>&1 -o /dev/null < %s | FileCheck %s --check-prefix=CHECK-CDIFF-QUIET-SIMPLE --allow-empty
+;
+; Check that only the passes that change the IR are printed and that the
+; others (including g) are filtered out.
+; RUN: opt -S -print-changed=cdiff-quiet -passes=instsimplify -filter-print-funcs=f  2>&1 -o /dev/null < %s | FileCheck %s --check-prefix=CHECK-CDIFF-QUIET-FUNC-FILTER
+;
+; Check that the reporting of IRs respects is not affected by
+; -print-module-scope
+; RUN: opt -S -print-changed=cdiff-quiet -passes=instsimplify -print-module-scope 2>&1 -o /dev/null < %s | FileCheck %s --check-prefix=CHECK-CDIFF-QUIET-PRINT-MOD-SCOPE
+;
+; Check that reporting of multiple functions happens
+; RUN: opt -S -print-changed=cdiff-quiet -passes=instsimplify -filter-print-funcs="f,g" 2>&1 -o /dev/null < %s | FileCheck %s --check-prefix=CHECK-CDIFF-QUIET-FILTER-MULT-FUNC
+;
+; Check that the reporting of IRs respects -filter-passes
+; RUN: opt -S -print-changed=cdiff-quiet -passes="instsimplify,no-op-function" -filter-passes="NoOpFunctionPass" 2>&1 -o /dev/null < %s | FileCheck %s --check-prefix=CHECK-CDIFF-QUIET-FILTER-PASSES-NONE --allow-empty
+;
+; Check that the reporting of IRs respects -filter-passes with multiple passes
+; RUN: opt -S -print-changed=cdiff-quiet -passes="instsimplify,no-op-function" -filter-passes="NoOpFunctionPass,InstSimplifyPass" 2>&1 -o /dev/null < %s | FileCheck %s --check-prefix=CHECK-CDIFF-QUIET-FILTER-MULT-PASSES
+;
+; Check that the reporting of IRs respects both -filter-passes and -filter-print-funcs
+; RUN: opt -S -print-changed=cdiff-quiet -passes="instsimplify,no-op-function" -filter-passes="NoOpFunctionPass,InstSimplifyPass" -filter-print-funcs=f 2>&1 -o /dev/null < %s | FileCheck %s --check-prefix=CHECK-CDIFF-QUIET-FILTER-FUNC-PASSES
+;
+; Check that repeated passes that change the IR are printed and that the
+; others (including g) are filtered out.  Note that only the first time
+; instsimplify is run on f will result in changes
+; RUN: opt -S -print-changed=cdiff-quiet -passes="instsimplify,instsimplify" -filter-print-funcs=f  2>&1 -o /dev/null < %s | FileCheck %s --check-prefix=CHECK-CDIFF-QUIET-MULT-PASSES-FILTER-FUNC
+
 define i32 @g() {
 entry:
   %a = add i32 2, 3
@@ -286,3 +350,216 @@
 ; CHECK-DIFF-QUIET-MULT-PASSES-FILTER-FUNC:-  ret i32 %a
 ; CHECK-DIFF-QUIET-MULT-PASSES-FILTER-FUNC:+  ret i32 5
 ; CHECK-DIFF-QUIET-MULT-PASSES-FILTER-FUNC-NOT: *** IR
+
+; CHECK-CDIFF-SIMPLE: *** IR Dump At Start: ***
+; CHECK-CDIFF-SIMPLE: ModuleID = {{.+}}
+; CHECK-CDIFF-SIMPLE: *** IR Dump After VerifierPass (module) omitted because no change ***
+; CHECK-CDIFF-SIMPLE: *** IR Dump After InstSimplifyPass *** (function: g)
+; CHECK-CDIFF-SIMPLE-NOT: ModuleID = {{.+}}
+; CHECK-CDIFF-SIMPLE-NOT: *** IR{{.*}}
+; CHECK-CDIFF-SIMPLE: entry:
+; CHECK-CDIFF-SIMPLE-NEXT:{{.\[31m-}}  %a = add i32 2, 3{{.\[0m}}
+; CHECK-CDIFF-SIMPLE-NEXT:{{.\[31m-}}  ret i32 %a{{.\[0m}}
+; CHECK-CDIFF-SIMPLE-NEXT:{{.\[32m\+}}  ret i32 5{{.\[0m}}
+; CHECK-CDIFF-SIMPLE: *** IR Pass PassManager{{.*}} (function: g) ignored ***
+; CHECK-CDIFF-SIMPLE: *** IR Dump After InstSimplifyPass *** (function: f)
+; CHECK-CDIFF-SIMPLE-NOT: ModuleID = {{.+}}
+; CHECK-CDIFF-SIMPLE-NOT: *** IR{{.*}}
+; CHECK-CDIFF-SIMPLE: entry:
+; CHECK-CDIFF-SIMPLE-NEXT:{{.\[31m-}}  %a = add i32 2, 3{{.\[0m}}
+; CHECK-CDIFF-SIMPLE-NEXT:{{.\[31m-}}  ret i32 %a{{.\[0m}}
+; CHECK-CDIFF-SIMPLE-NEXT:{{.\[32m\+}}  ret i32 5{{.\[0m}}
+; CHECK-CDIFF-SIMPLE: *** IR Pass PassManager{{.*}} (function: f) ignored ***
+; CHECK-CDIFF-SIMPLE: *** IR Pass ModuleToFunctionPassAdaptor (module) ignored ***
+; CHECK-CDIFF-SIMPLE: *** IR Dump After VerifierPass (module) omitted because no change ***
+; CHECK-CDIFF-SIMPLE: *** IR Dump After PrintModulePass (module) omitted because no change ***
+
+; CHECK-CDIFF-FUNC-FILTER: *** IR Dump At Start: ***
+; CHECK-CDIFF-FUNC-FILTER-NEXT: ; ModuleID = {{.+}}
+; CHECK-CDIFF-FUNC-FILTER: *** IR Dump After InstSimplifyPass (function: g) filtered out ***
+; CHECK-CDIFF-FUNC-FILTER: *** IR Dump After InstSimplifyPass *** (function: f)
+; CHECK-CDIFF-FUNC-FILTER-NOT: ModuleID = {{.+}}
+; CHECK-CDIFF-FUNC-FILTER: entry:
+; CHECK-CDIFF-FUNC-FILTER:{{.\[31m-}}  %a = add i32 2, 3{{.\[0m}}
+; CHECK-CDIFF-FUNC-FILTER:{{.\[31m-}}  ret i32 %a{{.\[0m}}
+; CHECK-CDIFF-FUNC-FILTER:{{.\[32m\+}}  ret i32 5{{.\[0m}}
+; CHECK-CDIFF-FUNC-FILTER: *** IR Pass PassManager{{.*}} (function: f) ignored ***
+; CHECK-CDIFF-FUNC-FILTER: *** IR Pass ModuleToFunctionPassAdaptor (module) ignored ***
+; CHECK-CDIFF-FUNC-FILTER: *** IR Dump After VerifierPass (module) omitted because no change ***
+; CHECK-CDIFF-FUNC-FILTER: *** IR Dump After PrintModulePass (module) omitted because no change ***
+
+; CHECK-CDIFF-PRINT-MOD-SCOPE: *** IR Dump At Start: ***
+; CHECK-CDIFF-PRINT-MOD-SCOPE: ModuleID = {{.+}}
+; CHECK-CDIFF-PRINT-MOD-SCOPE: *** IR Dump After InstSimplifyPass *** (function: g)
+; CHECK-CDIFF-PRINT-MOD-SCOPE-NOT: ModuleID = {{.+}}
+; CHECK-CDIFF-PRINT-MOD-SCOPE: entry:
+; CHECK-CDIFF-PRINT-MOD-SCOPE:{{.\[31m-}}  %a = add i32 2, 3{{.\[0m}}
+; CHECK-CDIFF-PRINT-MOD-SCOPE:{{.\[31m-}}  ret i32 %a{{.\[0m}}
+; CHECK-CDIFF-PRINT-MOD-SCOPE:{{.\[32m\+}}  ret i32 5{{.\[0m}}
+; CHECK-CDIFF-PRINT-MOD-SCOPE: *** IR Dump After InstSimplifyPass *** (function: f)
+; CHECK-CDIFF-PRINT-MOD-SCOPE-NOT: ModuleID = {{.+}}
+; CHECK-CDIFF-PRINT-MOD-SCOPE: entry:
+; CHECK-CDIFF-PRINT-MOD-SCOPE:{{.\[31m-}}  %a = add i32 2, 3{{.\[0m}}
+; CHECK-CDIFF-PRINT-MOD-SCOPE:{{.\[31m-}}  ret i32 %a{{.\[0m}}
+; CHECK-CDIFF-PRINT-MOD-SCOPE:{{.\[32m\+}}  ret i32 5{{.\[0m}}
+; CHECK-CDIFF-PRINT-MOD-SCOPE: *** IR Pass PassManager{{.*}} (function: f) ignored ***
+; CHECK-CDIFF-PRINT-MOD-SCOPE: *** IR Pass ModuleToFunctionPassAdaptor (module) ignored ***
+; CHECK-CDIFF-PRINT-MOD-SCOPE: *** IR Dump After VerifierPass (module) omitted because no change ***
+; CHECK-CDIFF-PRINT-MOD-SCOPE: *** IR Dump After PrintModulePass (module) omitted because no change ***
+
+; CHECK-CDIFF-FILTER-MULT-FUNC: *** IR Dump At Start: ***
+; CHECK-CDIFF-FILTER-MULT-FUNC: *** IR Dump After InstSimplifyPass *** (function: g)
+; CHECK-CDIFF-FILTER-MULT-FUNC-NOT: ModuleID = {{.+}}
+; CHECK-CDIFF-FILTER-MULT-FUNC: entry:
+; CHECK-CDIFF-FILTER-MULT-FUNC:{{.\[31m-}}  %a = add i32 2, 3{{.\[0m}}
+; CHECK-CDIFF-FILTER-MULT-FUNC:{{.\[31m-}}  ret i32 %a{{.\[0m}}
+; CHECK-CDIFF-FILTER-MULT-FUNC:{{.\[32m\+}}  ret i32 5{{.\[0m}}
+; CHECK-CDIFF-FILTER-MULT-FUNC: *** IR Dump After InstSimplifyPass *** (function: f)
+; CHECK-CDIFF-FILTER-MULT-FUNC-NOT: ModuleID = {{.+}}
+; CHECK-CDIFF-FILTER-MULT-FUNC: entry:
+; CHECK-CDIFF-FILTER-MULT-FUNC:{{.\[31m-}}  %a = add i32 2, 3{{.\[0m}}
+; CHECK-CDIFF-FILTER-MULT-FUNC:{{.\[31m-}}  ret i32 %a{{.\[0m}}
+; CHECK-CDIFF-FILTER-MULT-FUNC:{{.\[32m\+}}  ret i32 5{{.\[0m}}
+; CHECK-CDIFF-FILTER-MULT-FUNC: *** IR Pass PassManager{{.*}} (function: f) ignored ***
+; CHECK-CDIFF-FILTER-MULT-FUNC: *** IR Pass ModuleToFunctionPassAdaptor (module) ignored ***
+; CHECK-CDIFF-FILTER-MULT-FUNC: *** IR Dump After VerifierPass (module) omitted because no change ***
+; CHECK-CDIFF-FILTER-MULT-FUNC: *** IR Dump After PrintModulePass (module) omitted because no change ***
+
+; CHECK-CDIFF-FILTER-PASSES: *** IR Dump After InstSimplifyPass (function: g) filtered out ***
+; CHECK-CDIFF-FILTER-PASSES: *** IR Dump At Start: *** (function: g)
+; CHECK-CDIFF-FILTER-PASSES: *** IR Dump After NoOpFunctionPass (function: g) omitted because no change ***
+; CHECK-CDIFF-FILTER-PASSES: *** IR Dump After InstSimplifyPass (function: f) filtered out ***
+; CHECK-CDIFF-FILTER-PASSES: *** IR Dump After NoOpFunctionPass (function: f) omitted because no change ***
+
+; CHECK-CDIFF-FILTER-MULT-PASSES: *** IR Dump At Start: *** (function: g)
+; CHECK-CDIFF-FILTER-MULT-PASSES: *** IR Dump After InstSimplifyPass *** (function: g)
+; CHECK-CDIFF-FILTER-MULT-PASSES-NOT: ModuleID = {{.+}}
+; CHECK-CDIFF-FILTER-MULT-PASSES: entry:
+; CHECK-CDIFF-FILTER-MULT-PASSES:{{.\[31m-}}  %a = add i32 2, 3{{.\[0m}}
+; CHECK-CDIFF-FILTER-MULT-PASSES:{{.\[31m-}}  ret i32 %a{{.\[0m}}
+; CHECK-CDIFF-FILTER-MULT-PASSES:{{.\[32m\+}}  ret i32 5{{.\[0m}}
+; CHECK-CDIFF-FILTER-MULT-PASSES: *** IR Dump After NoOpFunctionPass (function: g) omitted because no change ***
+; CHECK-CDIFF-FILTER-MULT-PASSES: *** IR Dump After InstSimplifyPass *** (function: f)
+; CHECK-CDIFF-FILTER-MULT-PASSES-NOT: ModuleID = {{.+}}
+; CHECK-CDIFF-FILTER-MULT-PASSES: entry:
+; CHECK-CDIFF-FILTER-MULT-PASSES:{{.\[31m-}}  %a = add i32 2, 3{{.\[0m}}
+; CHECK-CDIFF-FILTER-MULT-PASSES:{{.\[31m-}}  ret i32 %a{{.\[0m}}
+; CHECK-CDIFF-FILTER-MULT-PASSES:{{.\[32m\+}}  ret i32 5{{.\[0m}}
+; CHECK-CDIFF-FILTER-MULT-PASSES: *** IR Dump After NoOpFunctionPass (function: f) omitted because no change ***
+
+; CHECK-CDIFF-FILTER-FUNC-PASSES: *** IR Dump After InstSimplifyPass (function: g) filtered out ***
+; CHECK-CDIFF-FILTER-FUNC-PASSES: *** IR Dump After NoOpFunctionPass (function: g) filtered out ***
+; CHECK-CDIFF-FILTER-FUNC-PASSES: *** IR Dump At Start: *** (function: f)
+; CHECK-CDIFF-FILTER-FUNC-PASSES: *** IR Dump After InstSimplifyPass *** (function: f)
+; CHECK-CDIFF-FILTER-FUNC-PASSES-NOT: ModuleID = {{.+}}
+; CHECK-CDIFF-FILTER-FUNC-PASSES: entry:
+; CHECK-CDIFF-FILTER-FUNC-PASSES:{{.\[31m-}}  %a = add i32 2, 3{{.\[0m}}
+; CHECK-CDIFF-FILTER-FUNC-PASSES:{{.\[31m-}}  ret i32 %a{{.\[0m}}
+; CHECK-CDIFF-FILTER-FUNC-PASSES:{{.\[32m\+}}  ret i32 5{{.\[0m}}
+; CHECK-CDIFF-FILTER-FUNC-PASSES: *** IR Dump After NoOpFunctionPass (function: f) omitted because no change ***
+
+; CHECK-CDIFF-MULT-PASSES-FILTER-FUNC: *** IR Dump At Start: ***
+; CHECK-CDIFF-MULT-PASSES-FILTER-FUNC: *** IR Dump After InstSimplifyPass (function: g) filtered out ***
+; CHECK-CDIFF-MULT-PASSES-FILTER-FUNC: *** IR Dump After InstSimplifyPass (function: g) filtered out ***
+; CHECK-CDIFF-MULT-PASSES-FILTER-FUNC: *** IR Dump After InstSimplifyPass *** (function: f)
+; CHECK-CDIFF-MULT-PASSES-FILTER-FUNC-NOT: ModuleID = {{.+}}
+; CHECK-CDIFF-MULT-PASSES-FILTER-FUNC: entry:
+; CHECK-CDIFF-MULT-PASSES-FILTER-FUNC:{{.\[31m-}}  %a = add i32 2, 3{{.\[0m}}
+; CHECK-CDIFF-MULT-PASSES-FILTER-FUNC:{{.\[31m-}}  ret i32 %a{{.\[0m}}
+; CHECK-CDIFF-MULT-PASSES-FILTER-FUNC:{{.\[32m\+}}  ret i32 5{{.\[0m}}
+; CHECK-CDIFF-MULT-PASSES-FILTER-FUNC: *** IR Dump After InstSimplifyPass (function: f) omitted because no change ***
+
+; CHECK-CDIFF-QUIET-SIMPLE-NOT: *** IR Dump {{.*(At Start:|no change|ignored|filtered out)}} ***
+; CHECK-CDIFF-QUIET-SIMPLE: *** IR Dump After InstSimplifyPass *** (function: g)
+; CHECK-CDIFF-QUIET-SIMPLE-NOT: ModuleID = {{.+}}
+; CHECK-CDIFF-QUIET-SIMPLE-NOT: *** IR{{.*}}
+; CHECK-CDIFF-QUIET-SIMPLE: entry:
+; CHECK-CDIFF-QUIET-SIMPLE-NEXT:{{.\[31m-}}  %a = add i32 2, 3{{.\[0m}}
+; CHECK-CDIFF-QUIET-SIMPLE-NEXT:{{.\[31m-}}  ret i32 %a{{.\[0m}}
+; CHECK-CDIFF-QUIET-SIMPLE-NEXT:{{.\[32m\+}}  ret i32 5{{.\[0m}}
+; CHECK-CDIFF-QUIET-SIMPLE-EMPTY:
+; CHECK-CDIFF-QUIET-SIMPLE-NEXT: *** IR Dump After InstSimplifyPass *** (function: f)
+; CHECK-CDIFF-QUIET-SIMPLE-NOT: ModuleID = {{.+}}
+; CHECK-CDIFF-QUIET-SIMPLE-NOT: *** IR{{.*}}
+; CHECK-CDIFF-QUIET-SIMPLE: entry:
+; CHECK-CDIFF-QUIET-SIMPLE-NEXT:{{.\[31m-}}  %a = add i32 2, 3{{.\[0m}}
+; CHECK-CDIFF-QUIET-SIMPLE-NEXT:{{.\[31m-}}  ret i32 %a{{.\[0m}}
+; CHECK-CDIFF-QUIET-SIMPLE-NEXT:{{.\[32m\+}}  ret i32 5{{.\[0m}}
+; CHECK-CDIFF-QUIET-SIMPLE-NOT: *** IR{{.*}}
+
+; CHECK-CDIFF-QUIET-FUNC-FILTER-NOT: *** IR Dump {{.*(At Start:|no change|ignored|filtered out)}} ***
+; CHECK-CDIFF-QUIET-FUNC-FILTER: *** IR Dump After InstSimplifyPass *** (function: f)
+; CHECK-CDIFF-QUIET-FUNC-FILTER-NOT: ModuleID = {{.+}}
+; CHECK-CDIFF-QUIET-FUNC-FILTER: entry:
+; CHECK-CDIFF-QUIET-FUNC-FILTER:{{.\[31m-}}  %a = add i32 2, 3{{.\[0m}}
+; CHECK-CDIFF-QUIET-FUNC-FILTER:{{.\[31m-}}  ret i32 %a{{.\[0m}}
+; CHECK-CDIFF-QUIET-FUNC-FILTER:{{.\[32m\+}}  ret i32 5{{.\[0m}}
+; CHECK-CDIFF-QUIET-FUNC-FILTER-NOT: *** IR{{.*}}
+
+; CHECK-CDIFF-QUIET-PRINT-MOD-SCOPE-NOT: *** IR Dump {{.*(At Start:|no change|ignored|filtered out)}} ***
+; CHECK-CDIFF-QUIET-PRINT-MOD-SCOPE: *** IR Dump After InstSimplifyPass *** (function: g)
+; CHECK-CDIFF-QUIET-PRINT-MOD-SCOPE-NOT: ModuleID = {{.+}}
+; CHECK-CDIFF-QUIET-PRINT-MOD-SCOPE: entry:
+; CHECK-CDIFF-QUIET-PRINT-MOD-SCOPE:{{.\[31m-}}  %a = add i32 2, 3{{.\[0m}}
+; CHECK-CDIFF-QUIET-PRINT-MOD-SCOPE:{{.\[31m-}}  ret i32 %a{{.\[0m}}
+; CHECK-CDIFF-QUIET-PRINT-MOD-SCOPE:{{.\[32m\+}}  ret i32 5{{.\[0m}}
+; CHECK-CDIFF-QUIET-PRINT-MOD-SCOPE-EMPTY:
+; CHECK-CDIFF-QUIET-PRINT-MOD-SCOPE-NEXT: *** IR Dump After InstSimplifyPass *** (function: f)
+; CHECK-CDIFF-QUIET-PRINT-MOD-SCOPE-NOT: ModuleID = {{.+}}
+; CHECK-CDIFF-QUIET-PRINT-MOD-SCOPE: entry:
+; CHECK-CDIFF-QUIET-PRINT-MOD-SCOPE:{{.\[31m-}}  %a = add i32 2, 3{{.\[0m}}
+; CHECK-CDIFF-QUIET-PRINT-MOD-SCOPE:{{.\[31m-}}  ret i32 %a{{.\[0m}}
+; CHECK-CDIFF-QUIET-PRINT-MOD-SCOPE:{{.\[32m\+}}  ret i32 5{{.\[0m}}
+; CHECK-CDIFF-QUIET-PRINT-MOD-SCOPE-NOT: *** IR{{.*}}
+
+; CHECK-CDIFF-QUIET-FILTER-MULT-FUNC-NOT: *** IR Dump {{.*(At Start:|no change|ignored|filtered out)}} ***
+; CHECK-CDIFF-QUIET-FILTER-MULT-FUNC: *** IR Dump After InstSimplifyPass *** (function: g)
+; CHECK-CDIFF-QUIET-FILTER-MULT-FUNC-NOT: ModuleID = {{.+}}
+; CHECK-CDIFF-QUIET-FILTER-MULT-FUNC: entry:
+; CHECK-CDIFF-QUIET-FILTER-MULT-FUNC:{{.\[31m-}}  %a = add i32 2, 3{{.\[0m}}
+; CHECK-CDIFF-QUIET-FILTER-MULT-FUNC:{{.\[31m-}}  ret i32 %a{{.\[0m}}
+; CHECK-CDIFF-QUIET-FILTER-MULT-FUNC:{{.\[32m\+}}  ret i32 5{{.\[0m}}
+; CHECK-CDIFF-QUIET-FILTER-MULT-FUNC-EMPTY:
+; CHECK-CDIFF-QUIET-FILTER-MULT-FUNC-NEXT: *** IR Dump After InstSimplifyPass *** (function: f)
+; CHECK-CDIFF-QUIET-FILTER-MULT-FUNC-NOT: ModuleID = {{.+}}
+; CHECK-CDIFF-QUIET-FILTER-MULT-FUNC: entry:
+; CHECK-CDIFF-QUIET-FILTER-MULT-FUNC:{{.\[31m-}}  %a = add i32 2, 3{{.\[0m}}
+; CHECK-CDIFF-QUIET-FILTER-MULT-FUNC:{{.\[31m-}}  ret i32 %a{{.\[0m}}
+; CHECK-CDIFF-QUIET-FILTER-MULT-FUNC:{{.\[32m\+}}  ret i32 5{{.\[0m}}
+; CHECK-CDIFF-QUIET-FILTER-MULT-FUNC-NOT: *** IR{{.*}}
+
+; CHECK-CDIFF-QUIET-FILTER-PASSES-NONE-NOT: *** IR
+
+; CHECK-CDIFF-QUIET-FILTER-MULT-PASSES-NOT: *** IR Dump {{.*(At Start:|no change|ignored|filtered out)}} ***
+; CHECK-CDIFF-QUIET-FILTER-MULT-PASSES: *** IR Dump After InstSimplifyPass *** (function: g)
+; CHECK-CDIFF-QUIET-FILTER-MULT-PASSES-NOT: ModuleID = {{.+}}
+; CHECK-CDIFF-QUIET-FILTER-MULT-PASSES: entry:
+; CHECK-CDIFF-QUIET-FILTER-MULT-PASSES:{{.\[31m-}}  %a = add i32 2, 3{{.\[0m}}
+; CHECK-CDIFF-QUIET-FILTER-MULT-PASSES:{{.\[31m-}}  ret i32 %a{{.\[0m}}
+; CHECK-CDIFF-QUIET-FILTER-MULT-PASSES:{{.\[32m\+}}  ret i32 5{{.\[0m}}
+; CHECK-CDIFF-QUIET-FILTER-MULT-PASSES-EMPTY:
+; CHECK-CDIFF-QUIET-FILTER-MULT-PASSES: *** IR Dump After InstSimplifyPass *** (function: f)
+; CHECK-CDIFF-QUIET-FILTER-MULT-PASSES-NOT: ModuleID = {{.+}}
+; CHECK-CDIFF-QUIET-FILTER-MULT-PASSES: entry:
+; CHECK-CDIFF-QUIET-FILTER-MULT-PASSES:{{.\[31m-}}  %a = add i32 2, 3{{.\[0m}}
+; CHECK-CDIFF-QUIET-FILTER-MULT-PASSES:{{.\[31m-}}  ret i32 %a{{.\[0m}}
+; CHECK-CDIFF-QUIET-FILTER-MULT-PASSES:{{.\[32m\+}}  ret i32 5{{.\[0m}}
+; CHECK-CDIFF-QUIET-FILTER-MULT-PASSES-NOT: *** IR
+
+; CHECK-CDIFF-QUIET-FILTER-FUNC-PASSES-NOT: *** IR Dump {{.*(At Start:|no change|ignored|filtered out)}} ***
+; CHECK-CDIFF-QUIET-FILTER-FUNC-PASSES: *** IR Dump After InstSimplifyPass *** (function: f)
+; CHECK-CDIFF-QUIET-FILTER-FUNC-PASSES-NOT: ModuleID = {{.+}}
+; CHECK-CDIFF-QUIET-FILTER-FUNC-PASSES: entry:
+; CHECK-CDIFF-QUIET-FILTER-FUNC-PASSES:{{.\[31m-}}  %a = add i32 2, 3{{.\[0m}}
+; CHECK-CDIFF-QUIET-FILTER-FUNC-PASSES:{{.\[31m-}}  ret i32 %a{{.\[0m}}
+; CHECK-CDIFF-QUIET-FILTER-FUNC-PASSES:{{.\[32m\+}}  ret i32 5{{.\[0m}}
+; CHECK-CDIFF-QUIET-FILTER-FUNC-PASSES-NOT: *** IR
+
+; CHECK-CDIFF-QUIET-MULT-PASSES-FILTER-FUNC-NOT: *** IR Dump {{.*(At Start:|no change|ignored|filtered out)}} ***
+; CHECK-CDIFF-QUIET-MULT-PASSES-FILTER-FUNC: *** IR Dump After InstSimplifyPass *** (function: f)
+; CHECK-CDIFF-QUIET-MULT-PASSES-FILTER-FUNC-NOT: ModuleID = {{.+}}
+; CHECK-CDIFF-QUIET-MULT-PASSES-FILTER-FUNC: entry:
+; CHECK-CDIFF-QUIET-MULT-PASSES-FILTER-FUNC:{{.\[31m-}}  %a = add i32 2, 3{{.\[0m}}
+; CHECK-CDIFF-QUIET-MULT-PASSES-FILTER-FUNC:{{.\[31m-}}  ret i32 %a{{.\[0m}}
+; CHECK-CDIFF-QUIET-MULT-PASSES-FILTER-FUNC:{{.\[32m\+}}  ret i32 5{{.\[0m}}
+; CHECK-CDIFF-QUIET-MULT-PASSES-FILTER-FUNC-NOT: *** IR