Author: Vitaly Buka Date: 2022-09-09T00:33:04-07:00 New Revision: 7dc0734567217236a61fa2ed3b3909ac25925ce5
URL: https://github.com/llvm/llvm-project/commit/7dc0734567217236a61fa2ed3b3909ac25925ce5 DIFF: https://github.com/llvm/llvm-project/commit/7dc0734567217236a61fa2ed3b3909ac25925ce5.diff LOG: [msan] Insert simplification passes after instrumentation This resolves TODO from D96406. InstCombine issue is fixed with D133394. Save 4.5% of .text on CTMark. Added: Modified: clang/lib/CodeGen/BackendUtil.cpp Removed: ################################################################################ diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp index 64b21ef608bb1..f4a4f1cd22ab9 100644 --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -19,6 +19,7 @@ #include "llvm/ADT/StringSwitch.h" #include "llvm/ADT/Triple.h" #include "llvm/Analysis/AliasAnalysis.h" +#include "llvm/Analysis/GlobalsModRef.h" #include "llvm/Analysis/StackSafetyAnalysis.h" #include "llvm/Analysis/TargetLibraryInfo.h" #include "llvm/Analysis/TargetTransformInfo.h" @@ -72,14 +73,16 @@ #include "llvm/Transforms/Instrumentation/InstrProfiling.h" #include "llvm/Transforms/Instrumentation/MemProfiler.h" #include "llvm/Transforms/Instrumentation/MemorySanitizer.h" -#include "llvm/Transforms/Instrumentation/SanitizerCoverage.h" #include "llvm/Transforms/Instrumentation/SanitizerBinaryMetadata.h" +#include "llvm/Transforms/Instrumentation/SanitizerCoverage.h" #include "llvm/Transforms/Instrumentation/ThreadSanitizer.h" #include "llvm/Transforms/ObjCARC.h" #include "llvm/Transforms/Scalar.h" #include "llvm/Transforms/Scalar/EarlyCSE.h" #include "llvm/Transforms/Scalar/GVN.h" +#include "llvm/Transforms/Scalar/JumpThreading.h" #include "llvm/Transforms/Scalar/LowerMatrixIntrinsics.h" +#include "llvm/Transforms/Scalar/NewGVN.h" #include "llvm/Transforms/Utils.h" #include "llvm/Transforms/Utils/CanonicalizeAliases.h" #include "llvm/Transforms/Utils/Debugify.h" @@ -97,6 +100,7 @@ using namespace llvm; namespace llvm { extern cl::opt<bool> DebugInfoCorrelate; +extern cl::opt<bool> RunNewGVN; // Experiment to move sanitizers earlier. static cl::opt<bool> ClSanitizeOnOptimizerEarlyEP( @@ -661,16 +665,21 @@ static void addSanitizers(const Triple &TargetTriple, CodeGenOpts.SanitizeMemoryParamRetval); MPM.addPass(MemorySanitizerPass(options)); if (Level != OptimizationLevel::O0) { - // MemorySanitizer inserts complex instrumentation that mostly - // follows the logic of the original code, but operates on - // "shadow" values. It can benefit from re-running some - // general purpose optimization passes. - MPM.addPass(createModuleToFunctionPassAdaptor(EarlyCSEPass())); - // TODO: Consider add more passes like in - // addGeneralOptsForMemorySanitizer. EarlyCSEPass makes visible - // diff erence on size. It's not clear if the rest is still - // usefull. InstCombinePass breakes - // compiler-rt/test/msan/select_origin.cpp. + // MemorySanitizer inserts complex instrumentation that mostly follows + // the logic of the original code, but operates on "shadow" values. It + // can benefit from re-running some general purpose optimization + // passes. + MPM.addPass(RecomputeGlobalsAAPass()); + FunctionPassManager FPM; + FPM.addPass(EarlyCSEPass(true /* Enable mem-ssa. */)); + FPM.addPass(InstCombinePass()); + FPM.addPass(JumpThreadingPass()); + if (RunNewGVN) + FPM.addPass(NewGVNPass()); + else + FPM.addPass(GVNPass()); + FPM.addPass(InstCombinePass()); + MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM))); } } }; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits