@@ -662,15 +662,16 @@ exports.main = function main(argv, options, callback) {
662662 add ( "remove-unused-brs" ) ;
663663 add ( "remove-unused-names" ) ;
664664 add ( "optimize-instructions" ) ;
665- if ( optimizeLevel >= 2 || shrinkLevel >= 2 ) {
665+ if ( optimizeLevel >= 2 || shrinkLevel >= 1 ) {
666666 add ( "pick-load-signs" ) ;
667+ add ( "simplify-globals-optimizing" ) ; // differs
667668 }
668669 if ( optimizeLevel >= 3 || shrinkLevel >= 2 ) {
669670 add ( "precompute-propagate" ) ;
670671 } else {
671672 add ( "precompute" ) ;
672673 }
673- // this will be done later
674+ // this will be done later (1)
674675 // if (optimizeLevel >= 2 || shrinkLevel >= 2) {
675676 // add("code-pushing");
676677 // }
@@ -691,15 +692,19 @@ exports.main = function main(argv, options, callback) {
691692 if ( optimizeLevel >= 3 || shrinkLevel >= 1 ) {
692693 add ( "code-folding" ) ;
693694 }
695+ if ( optimizeLevel >= 2 || shrinkLevel >= 1 ) { // differs
696+ add ( "simplify-globals-optimizing" ) ;
697+ }
694698 add ( "merge-blocks" ) ;
695699 add ( "remove-unused-brs" ) ;
696700 add ( "remove-unused-names" ) ;
697701 add ( "merge-blocks" ) ;
698- if ( optimizeLevel >= 3 || shrinkLevel >= 2 ) {
699- add ( "precompute-propagate" ) ;
700- } else {
701- add ( "precompute" ) ;
702- }
702+ // make this later & move to (2)
703+ // if (optimizeLevel >= 3 || shrinkLevel >= 2) {
704+ // add("precompute-propagate");
705+ // } else {
706+ // add("precompute");
707+ // }
703708 add ( "optimize-instructions" ) ;
704709 if ( optimizeLevel >= 2 || shrinkLevel >= 1 ) {
705710 add ( "rse" ) ;
@@ -720,6 +725,13 @@ exports.main = function main(argv, options, callback) {
720725 } else {
721726 add ( "simplify-globals" ) ;
722727 }
728+ // moved from (2)
729+ // it works better after globals optimizations like simplify-globals, inlining-optimizing and etc
730+ if ( optimizeLevel >= 2 || shrinkLevel >= 1 ) { // differs
731+ add ( "precompute-propagate" ) ;
732+ } else {
733+ add ( "precompute" ) ;
734+ }
723735 // replace indirect calls with direct, reduce arity and
724736 // inline this calls if possible
725737 add ( "directize" ) ; // differs
@@ -731,40 +743,44 @@ exports.main = function main(argv, options, callback) {
731743 }
732744 if ( optimizeLevel >= 2 || shrinkLevel >= 1 ) { // differs
733745 add ( "rse" ) ;
734- add ( "vacuum" ) ;
735-
736746 // rearrange / reduce switch cases again
737747 add ( "remove-unused-brs" ) ;
738- add ( "remove-unused-names" ) ;
739- add ( "merge-blocks" ) ;
740748 add ( "vacuum" ) ;
741749
742750 // replace indirect calls with direct and inline if possible again.
743751 add ( "directize" ) ;
744752 add ( "inlining-optimizing" ) ;
745753 // move some code after early return which potentially could reduce computations
746754 // do this after CFG cleanup (originally it was done before)
755+ // moved from (1)
747756 add ( "code-pushing" ) ;
748757
749758 // this quite expensive so do this only for highest opt level
759+ add ( "simplify-globals-optimizing" ) ;
750760 if ( optimizeLevel >= 3 ) {
751761 add ( "simplify-locals-nostructure" ) ;
752- add ( "reorder-locals" ) ;
753762 add ( "vacuum" ) ;
763+
764+ add ( "precompute-propagate" ) ;
765+ add ( "simplify-locals-nostructure" ) ;
766+ add ( "vacuum" ) ;
767+
768+ add ( "reorder-locals" ) ;
769+ } else {
770+ add ( "simplify-globals-optimizing" ) ;
754771 }
755- // finally optimize all remaining peepholes
756- add ( "simplify-globals-optimizing" ) ;
757772 add ( "optimize-instructions" ) ;
758773 }
759774 // remove unused elements of table and pack / reduce memory
760775 add ( "duplicate-function-elimination" ) ; // differs
761776 add ( "remove-unused-nonfunction-module-elements" ) ; // differs
762777 add ( "memory-packing" ) ;
763778 add ( "remove-unused-module-elements" ) ; // differs
764- if ( optimizeLevel >= 3 || shrinkLevel >= 1 ) { // differs. was optimizeLevel >= 2
765- add ( "generate-stack-ir" ) ;
766- add ( "optimize-stack-ir" ) ;
767- }
779+ // It seems stack-ir unuseful for our needs.
780+ // if (optimizeLevel >= 3 || shrinkLevel >= 1) { // differs. was optimizeLevel >= 2
781+ // add("generate-stack-ir");
782+ // add("optimize-stack-ir");
783+ // }
768784 }
769785
770786 // Append additional passes if requested and execute
0 commit comments