Skip to content

Commit

Permalink
Adjust simplifycfg options
Browse files Browse the repository at this point in the history
  • Loading branch information
pchintalapudi authored and vchuravy committed Jun 12, 2022
1 parent 5fb9b6f commit 1c5858b
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 additions & 16 deletions src/aotcompile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,19 @@ void addOptimizationPasses(legacy::PassManagerBase *PM, int opt_level,
// to merge allocations and sometimes eliminate them,
// since AllocOpt does not handle PhiNodes.
// Enable this instruction hoisting because of this and Union benchmarks.
auto simplifyCFGOptions = SimplifyCFGOptions().hoistCommonInsts(true);
auto basicSimplifyCFGOptions = SimplifyCFGOptions()
.convertSwitchRangeToICmp(true)
.convertSwitchToLookupTable(true)
.forwardSwitchCondToPhi(true);
auto aggressiveSimplifyCFGOptions = SimplifyCFGOptions()
.convertSwitchRangeToICmp(true)
.convertSwitchToLookupTable(true)
.forwardSwitchCondToPhi(true)
//These mess with loop rotation, so only do them after that
.hoistCommonInsts(true)
// Causes an SRET assertion error in late-gc-lowering
// .sinkCommonInsts(true)
;
#ifdef JL_DEBUG_BUILD
PM->add(createGCInvariantVerifierPass(true));
PM->add(createVerifierPass());
Expand All @@ -646,7 +658,7 @@ void addOptimizationPasses(legacy::PassManagerBase *PM, int opt_level,
if (opt_level == 1)
PM->add(createInstSimplifyLegacyPass());
}
PM->add(createCFGSimplificationPass(simplifyCFGOptions));
PM->add(createCFGSimplificationPass(basicSimplifyCFGOptions));
if (opt_level == 1) {
PM->add(createSROAPass());
PM->add(createInstructionCombiningPass());
Expand Down Expand Up @@ -676,7 +688,7 @@ void addOptimizationPasses(legacy::PassManagerBase *PM, int opt_level,
// minimal clean-up to get rid of CPU feature checks
if (opt_level == 1) {
PM->add(createInstSimplifyLegacyPass());
PM->add(createCFGSimplificationPass(simplifyCFGOptions));
PM->add(createCFGSimplificationPass(basicSimplifyCFGOptions));
}
}
#if defined(_COMPILER_ASAN_ENABLED_)
Expand All @@ -697,7 +709,7 @@ void addOptimizationPasses(legacy::PassManagerBase *PM, int opt_level,
PM->add(createBasicAAWrapperPass());
}

PM->add(createCFGSimplificationPass(simplifyCFGOptions));
PM->add(createCFGSimplificationPass(basicSimplifyCFGOptions));
PM->add(createDeadCodeEliminationPass());
PM->add(createSROAPass());

Expand All @@ -711,7 +723,7 @@ void addOptimizationPasses(legacy::PassManagerBase *PM, int opt_level,
PM->add(createAllocOptPass());
// consider AggressiveInstCombinePass at optlevel > 2
PM->add(createInstructionCombiningPass());
PM->add(createCFGSimplificationPass(simplifyCFGOptions));
PM->add(createCFGSimplificationPass(basicSimplifyCFGOptions));
if (dump_native)
PM->add(createMultiVersioningPass(external_use));
PM->add(createCPUFeaturesPass());
Expand Down Expand Up @@ -781,27 +793,23 @@ void addOptimizationPasses(legacy::PassManagerBase *PM, int opt_level,
PM->add(createGVNPass()); // Must come after JumpThreading and before LoopVectorize
}
PM->add(createDeadStoreEliminationPass());
// see if all of the constant folding has exposed more loops
// to simplification and deletion
// this helps significantly with cleaning up iteration
PM->add(createCFGSimplificationPass(aggressiveSimplifyCFGOptions));

// More dead allocation (store) deletion before loop optimization
// consider removing this:
// Moving this after aggressive CFG simplification helps deallocate when allocations are hoisted
PM->add(createAllocOptPass());
// see if all of the constant folding has exposed more loops
// to simplification and deletion
// this helps significantly with cleaning up iteration
PM->add(createCFGSimplificationPass()); // See note above, don't hoist instructions before LV
PM->add(createLoopDeletionPass());
PM->add(createInstructionCombiningPass());
PM->add(createLoopVectorizePass());
PM->add(createLoopLoadEliminationPass());
// Cleanup after LV pass
PM->add(createInstructionCombiningPass());
PM->add(createCFGSimplificationPass( // Aggressive CFG simplification
SimplifyCFGOptions()
.forwardSwitchCondToPhi(true)
.convertSwitchToLookupTable(true)
.needCanonicalLoops(false)
.hoistCommonInsts(true)
// .sinkCommonInsts(true) // FIXME: Causes assertion in llvm-late-lowering
aggressiveSimplifyCFGOptions
));
PM->add(createSLPVectorizerPass());
// might need this after LLVM 11:
Expand All @@ -812,7 +820,7 @@ void addOptimizationPasses(legacy::PassManagerBase *PM, int opt_level,
if (lower_intrinsics) {
// LowerPTLS removes an indirect call. As a result, it is likely to trigger
// LLVM's devirtualization heuristics, which would result in the entire
// pass pipeline being re-exectuted. Prevent this by inserting a barrier.
// pass pipeline being re-executed. Prevent this by inserting a barrier.
PM->add(createBarrierNoopPass());
PM->add(createLowerExcHandlersPass());
PM->add(createGCInvariantVerifierPass(false));
Expand Down

0 comments on commit 1c5858b

Please sign in to comment.