Skip to content

Commit 1c5858b

Browse files
pchintalapudivchuravy
authored andcommitted
Adjust simplifycfg options
1 parent 5fb9b6f commit 1c5858b

File tree

1 file changed

+24
-16
lines changed

1 file changed

+24
-16
lines changed

src/aotcompile.cpp

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,19 @@ void addOptimizationPasses(legacy::PassManagerBase *PM, int opt_level,
631631
// to merge allocations and sometimes eliminate them,
632632
// since AllocOpt does not handle PhiNodes.
633633
// Enable this instruction hoisting because of this and Union benchmarks.
634-
auto simplifyCFGOptions = SimplifyCFGOptions().hoistCommonInsts(true);
634+
auto basicSimplifyCFGOptions = SimplifyCFGOptions()
635+
.convertSwitchRangeToICmp(true)
636+
.convertSwitchToLookupTable(true)
637+
.forwardSwitchCondToPhi(true);
638+
auto aggressiveSimplifyCFGOptions = SimplifyCFGOptions()
639+
.convertSwitchRangeToICmp(true)
640+
.convertSwitchToLookupTable(true)
641+
.forwardSwitchCondToPhi(true)
642+
//These mess with loop rotation, so only do them after that
643+
.hoistCommonInsts(true)
644+
// Causes an SRET assertion error in late-gc-lowering
645+
// .sinkCommonInsts(true)
646+
;
635647
#ifdef JL_DEBUG_BUILD
636648
PM->add(createGCInvariantVerifierPass(true));
637649
PM->add(createVerifierPass());
@@ -646,7 +658,7 @@ void addOptimizationPasses(legacy::PassManagerBase *PM, int opt_level,
646658
if (opt_level == 1)
647659
PM->add(createInstSimplifyLegacyPass());
648660
}
649-
PM->add(createCFGSimplificationPass(simplifyCFGOptions));
661+
PM->add(createCFGSimplificationPass(basicSimplifyCFGOptions));
650662
if (opt_level == 1) {
651663
PM->add(createSROAPass());
652664
PM->add(createInstructionCombiningPass());
@@ -676,7 +688,7 @@ void addOptimizationPasses(legacy::PassManagerBase *PM, int opt_level,
676688
// minimal clean-up to get rid of CPU feature checks
677689
if (opt_level == 1) {
678690
PM->add(createInstSimplifyLegacyPass());
679-
PM->add(createCFGSimplificationPass(simplifyCFGOptions));
691+
PM->add(createCFGSimplificationPass(basicSimplifyCFGOptions));
680692
}
681693
}
682694
#if defined(_COMPILER_ASAN_ENABLED_)
@@ -697,7 +709,7 @@ void addOptimizationPasses(legacy::PassManagerBase *PM, int opt_level,
697709
PM->add(createBasicAAWrapperPass());
698710
}
699711

700-
PM->add(createCFGSimplificationPass(simplifyCFGOptions));
712+
PM->add(createCFGSimplificationPass(basicSimplifyCFGOptions));
701713
PM->add(createDeadCodeEliminationPass());
702714
PM->add(createSROAPass());
703715

@@ -711,7 +723,7 @@ void addOptimizationPasses(legacy::PassManagerBase *PM, int opt_level,
711723
PM->add(createAllocOptPass());
712724
// consider AggressiveInstCombinePass at optlevel > 2
713725
PM->add(createInstructionCombiningPass());
714-
PM->add(createCFGSimplificationPass(simplifyCFGOptions));
726+
PM->add(createCFGSimplificationPass(basicSimplifyCFGOptions));
715727
if (dump_native)
716728
PM->add(createMultiVersioningPass(external_use));
717729
PM->add(createCPUFeaturesPass());
@@ -781,27 +793,23 @@ void addOptimizationPasses(legacy::PassManagerBase *PM, int opt_level,
781793
PM->add(createGVNPass()); // Must come after JumpThreading and before LoopVectorize
782794
}
783795
PM->add(createDeadStoreEliminationPass());
796+
// see if all of the constant folding has exposed more loops
797+
// to simplification and deletion
798+
// this helps significantly with cleaning up iteration
799+
PM->add(createCFGSimplificationPass(aggressiveSimplifyCFGOptions));
784800

785801
// More dead allocation (store) deletion before loop optimization
786802
// consider removing this:
803+
// Moving this after aggressive CFG simplification helps deallocate when allocations are hoisted
787804
PM->add(createAllocOptPass());
788-
// see if all of the constant folding has exposed more loops
789-
// to simplification and deletion
790-
// this helps significantly with cleaning up iteration
791-
PM->add(createCFGSimplificationPass()); // See note above, don't hoist instructions before LV
792805
PM->add(createLoopDeletionPass());
793806
PM->add(createInstructionCombiningPass());
794807
PM->add(createLoopVectorizePass());
795808
PM->add(createLoopLoadEliminationPass());
796809
// Cleanup after LV pass
797810
PM->add(createInstructionCombiningPass());
798811
PM->add(createCFGSimplificationPass( // Aggressive CFG simplification
799-
SimplifyCFGOptions()
800-
.forwardSwitchCondToPhi(true)
801-
.convertSwitchToLookupTable(true)
802-
.needCanonicalLoops(false)
803-
.hoistCommonInsts(true)
804-
// .sinkCommonInsts(true) // FIXME: Causes assertion in llvm-late-lowering
812+
aggressiveSimplifyCFGOptions
805813
));
806814
PM->add(createSLPVectorizerPass());
807815
// might need this after LLVM 11:
@@ -812,7 +820,7 @@ void addOptimizationPasses(legacy::PassManagerBase *PM, int opt_level,
812820
if (lower_intrinsics) {
813821
// LowerPTLS removes an indirect call. As a result, it is likely to trigger
814822
// LLVM's devirtualization heuristics, which would result in the entire
815-
// pass pipeline being re-exectuted. Prevent this by inserting a barrier.
823+
// pass pipeline being re-executed. Prevent this by inserting a barrier.
816824
PM->add(createBarrierNoopPass());
817825
PM->add(createLowerExcHandlersPass());
818826
PM->add(createGCInvariantVerifierPass(false));

0 commit comments

Comments
 (0)