@@ -350,7 +350,9 @@ void addFunctionPasses(SILPassPipelinePlan &P,
350350 if (P.getOptions ().EnableOSSAModules ) {
351351 // We earlier eliminated ownership if we are not compiling the stdlib. Now
352352 // handle the stdlib functions, re-simplifying, eliminating ARC as we do.
353- P.addCopyPropagation ();
353+ if (!P.getOptions ().DisableCopyPropagation ) {
354+ P.addCopyPropagation ();
355+ }
354356 P.addSemanticARCOpts ();
355357 }
356358
@@ -372,7 +374,9 @@ void addFunctionPasses(SILPassPipelinePlan &P,
372374
373375 // Clean up Semantic ARC before we perform additional post-inliner opts.
374376 if (P.getOptions ().EnableOSSAModules ) {
375- P.addCopyPropagation ();
377+ if (!P.getOptions ().DisableCopyPropagation ) {
378+ P.addCopyPropagation ();
379+ }
376380 P.addSemanticARCOpts ();
377381 }
378382
@@ -437,7 +441,9 @@ void addFunctionPasses(SILPassPipelinePlan &P,
437441
438442 // Run a final round of ARC opts when ownership is enabled.
439443 if (P.getOptions ().EnableOSSAModules ) {
440- P.addCopyPropagation ();
444+ if (!P.getOptions ().DisableCopyPropagation ) {
445+ P.addCopyPropagation ();
446+ }
441447 P.addSemanticARCOpts ();
442448 }
443449}
@@ -471,7 +477,9 @@ static void addPerfEarlyModulePassPipeline(SILPassPipelinePlan &P) {
471477 // Cleanup after SILGen: remove trivial copies to temporaries.
472478 P.addTempRValueOpt ();
473479 // Cleanup after SILGen: remove unneeded borrows/copies.
474- P.addCopyPropagation ();
480+ if (!P.getOptions ().DisableCopyPropagation ) {
481+ P.addCopyPropagation ();
482+ }
475483 P.addSemanticARCOpts ();
476484
477485 // Devirtualizes differentiability witnesses into functions that reference them.
@@ -785,7 +793,9 @@ SILPassPipelinePlan::getPerformancePassPipeline(const SILOptions &Options) {
785793 // Run one last copy propagation/semantic arc opts run before serialization/us
786794 // lowering ownership.
787795 if (P.getOptions ().EnableOSSAModules ) {
788- P.addCopyPropagation ();
796+ if (!P.getOptions ().DisableCopyPropagation ) {
797+ P.addCopyPropagation ();
798+ }
789799 P.addSemanticARCOpts ();
790800 }
791801
@@ -835,7 +845,13 @@ SILPassPipelinePlan::getOnonePassPipeline(const SILOptions &Options) {
835845 P.startPipeline (" non-Diagnostic Enabling Mandatory Optimizations" );
836846 P.addForEachLoopUnroll ();
837847 P.addMandatoryCombine ();
838- P.addGuaranteedARCOpts ();
848+ if (P.getOptions ().EnableCopyPropagation ) {
849+ // MandatoryCopyPropagation should only be run at -Onone, not -O.
850+ P.addMandatoryCopyPropagation ();
851+ }
852+ // TODO: MandatoryARCOpts should be subsumed by CopyPropagation. There should
853+ // be no need to run another analysis of copies at -Onone.
854+ P.addMandatoryARCOpts ();
839855
840856 // First serialize the SIL if we are asked to.
841857 P.startPipeline (" Serialization" );
0 commit comments