@@ -685,30 +685,6 @@ static void AddLegalizationPasses(CodeGenContext& ctx, IGCPassManager& mpm, PSSi
685685 mpm.add (llvm::createGlobalDCEPass ());
686686 mpm.add (new PurgeMetaDataUtils ());
687687 mpm.add (createGenXCodeGenModulePass ());
688-
689- // Light cleanup for subroutines after cloning. Note that the constant
690- // propogation order is reversed, compared to the opt sequence in
691- // OptimizeIR. There is a substantial gain with CFG simplification after
692- // interprocedural constant propagation.
693- if (!isOptDisabled)
694- {
695- mpm.add (createPruneUnusedArgumentsPass ());
696- #if LLVM_VERSION_MAJOR >= 12
697- mpm.add (createIPSCCPPass ());
698- #else
699- if (!ctx.m_hasStackCalls )
700- {
701- // Don't run IPConstantProp when stackcalls are present.
702- // Let global constants be relocated inside stack funcs.
703- // We cannot process SLM constants inside stackcalls, so don't propagate them.
704- mpm.add (createIPConstantPropagationPass ());
705- }
706- mpm.add (createConstantPropagationPass ());
707- #endif
708- mpm.add (createDeadCodeEliminationPass ());
709- mpm.add (createCFGSimplificationPass ());
710- mpm.add (createIGCInstructionCombiningPass ());
711- }
712688 }
713689
714690 // Remove all uses of implicit arg instrinsics after inlining by lowering them to kernel args
@@ -817,6 +793,30 @@ static void AddLegalizationPasses(CodeGenContext& ctx, IGCPassManager& mpm, PSSi
817793 mpm.add (new StatelessToStateful (hasBufOff));
818794 }
819795
796+ // Light cleanup for subroutines after cloning. Note that the constant
797+ // propogation order is reversed, compared to the opt sequence in
798+ // OptimizeIR. There is a substantial gain with CFG simplification after
799+ // interprocedural constant propagation.
800+ if (ctx.m_enableSubroutine && !isOptDisabled)
801+ {
802+ mpm.add (createPruneUnusedArgumentsPass ());
803+
804+ #if LLVM_VERSION_MAJOR >= 12
805+ mpm.add (createIPSCCPPass ());
806+ #else
807+ if (!ctx.m_hasStackCalls )
808+ {
809+ // Don't run IPConstantProp when stackcalls are present.
810+ // Let global constants be relocated inside stack funcs.
811+ // We cannot process SLM constants inside stackcalls, so don't propagate them.
812+ mpm.add (createIPConstantPropagationPass ());
813+ }
814+ mpm.add (createConstantPropagationPass ());
815+ #endif
816+
817+ mpm.add (createDeadCodeEliminationPass ());
818+ mpm.add (createCFGSimplificationPass ());
819+ }
820820 // Since we don't support switch statements, switch lowering is needed after the last CFG simplication
821821 mpm.add (llvm::createLowerSwitchPass ());
822822
0 commit comments