[cfe-commits] [PATCH] [msan] Run more optimization after MemorySanitizer pass

Evgeniy Stepanov eugenis at google.com
Thu Dec 6 22:22:12 PST 2012


Hi kcc, chandlerc,

This change makes something like 20-30% speed improvement.

MSan generates very complex instrumentation, nearly mirroring the original code logic, but with many inputs replaced by constant values. This leave huge optimization opportunities.

This change also puts additional stress on MSan pass. As things are now, MSan is the last pass in the optimization chain, and, as such, can get away with generating somewhat broken code (ex. messed up readonly function attributes; also see the recent change that translate memcpy instrinsic into  __msan_memcpy; there are more pending changes that have no effect without this).

I'm adding new optimizations under -O2 AND fsanitize=memory, without another flag.

Do you think we should to empirically minimize this set of optimizations? I'm not sure if we've got good enough all-round benchmark suite, and we could miss something important.

This code adds ~20% compilation time (only with msan and -O2), and ~30% runtime perf.

http://llvm-reviews.chandlerc.com/D189

Files:
  llvm/tools/clang/lib/CodeGen/BackendUtil.cpp

Index: llvm/tools/clang/lib/CodeGen/BackendUtil.cpp
===================================================================
--- llvm/tools/clang/lib/CodeGen/BackendUtil.cpp
+++ llvm/tools/clang/lib/CodeGen/BackendUtil.cpp
@@ -188,6 +188,34 @@
 static void addMemorySanitizerPass(const PassManagerBuilder &Builder,
                                    PassManagerBase &PM) {
   PM.add(createMemorySanitizerPass());
+  if (Builder.OptLevel > 1) {
+    PM.add(createEarlyCSEPass());              // Catch trivial redundancies
+    PM.add(createJumpThreadingPass());         // Thread jumps.
+    PM.add(createCorrelatedValuePropagationPass()); // Propagate conditionals
+    PM.add(createCFGSimplificationPass());     // Merge & remove BBs
+    PM.add(createInstructionCombiningPass());  // Combine silly seq's
+
+    PM.add(createTailCallEliminationPass());   // Eliminate tail calls
+    PM.add(createCFGSimplificationPass());     // Merge & remove BBs
+    PM.add(createReassociatePass());           // Reassociate expressions
+    PM.add(createLoopRotatePass());            // Rotate Loop
+    PM.add(createLICMPass());                  // Hoist loop invariants
+    PM.add(createInstructionCombiningPass());
+    PM.add(createIndVarSimplifyPass());        // Canonicalize indvars
+    PM.add(createLoopIdiomPass());             // Recognize idioms like memset.
+    PM.add(createLoopDeletionPass());          // Delete dead loops
+
+    PM.add(createGVNPass());                 // Remove redundancies
+    PM.add(createMemCpyOptPass());             // Remove memcpy / form memset
+    PM.add(createSCCPPass());                  // Constant prop with SCCP
+
+    // Run instcombine after redundancy elimination to exploit opportunities
+    // opened up by them.
+    PM.add(createInstructionCombiningPass());
+    PM.add(createJumpThreadingPass());         // Thread jumps
+    PM.add(createCorrelatedValuePropagationPass());
+    PM.add(createDeadStoreEliminationPass());  // Delete dead stores
+  }
 }
 
 static void addThreadSanitizerPass(const PassManagerBuilder &Builder,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D189.1.patch
Type: text/x-patch
Size: 2074 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20121206/45c830bc/attachment.bin>


More information about the cfe-commits mailing list