diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp index 51f7f640108cf..5da80084fd1f9 100644 --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -1028,7 +1028,7 @@ void EmitAssemblyHelper::RunOptimizationPipeline( // configure the pipeline. OptimizationLevel Level = mapToLevel(CodeGenOpts); - if (LangOpts.SYCLIsDevice) + if (LangOpts.SYCLIsDevice) { PB.registerPipelineStartEPCallback([&](ModulePassManager &MPM, OptimizationLevel Level) { MPM.addPass(SYCLVirtualFunctionsAnalysisPass()); @@ -1043,7 +1043,16 @@ void EmitAssemblyHelper::RunOptimizationPipeline( /*ExcludeAspects=*/{"fp64"})); MPM.addPass(SYCLPropagateJointMatrixUsagePass()); }); - else if (LangOpts.SYCLIsHost && !LangOpts.SYCLESIMDBuildHostCode) + PB.registerOptimizerEarlyEPCallback([](ModulePassManager &MPM, + OptimizationLevel Level, + ThinOrFullLTOPhase) { + // Lowers __sycl_allocateLocalMemory and + // __sycl_dynamicLocalMemoryPlaceholder builtin calls. + // It is required by design to run SYCLLowerWGLocalMemoryPass after + // AlwaysInliner. + MPM.addPass(SYCLLowerWGLocalMemoryPass()); + }); + } else if (LangOpts.SYCLIsHost && !LangOpts.SYCLESIMDBuildHostCode) PB.registerPipelineStartEPCallback( [&](ModulePassManager &MPM, OptimizationLevel Level) { MPM.addPass(ESIMDRemoveHostCodePass()); @@ -1191,10 +1200,6 @@ void EmitAssemblyHelper::RunOptimizationPipeline( MPM.addPass(SPIRITTAnnotationsPass()); } - // Allocate static local memory in SYCL kernel scope for each allocation - // call. - MPM.addPass(SYCLLowerWGLocalMemoryPass()); - // Process properties and annotations MPM.addPass(CompileTimePropertiesPass());