@@ -599,19 +599,51 @@ void EmitAssemblyHelper::CreatePasses(legacy::PassManager &MPM,
599
599
CodeGenOpts.PrepareForThinLTO ));
600
600
}
601
601
602
- PMBuilder.OptLevel = CodeGenOpts.OptimizationLevel ;
603
- PMBuilder.SizeLevel = CodeGenOpts.OptimizeSize ;
604
- PMBuilder.SLPVectorize = CodeGenOpts.VectorizeSLP ;
605
- PMBuilder.LoopVectorize = CodeGenOpts.VectorizeLoop ;
606
-
607
- PMBuilder.DisableUnrollLoops = !CodeGenOpts.UnrollLoops ;
608
- // Loop interleaving in the loop vectorizer has historically been set to be
609
- // enabled when loop unrolling is enabled.
610
- PMBuilder.LoopsInterleaved = CodeGenOpts.UnrollLoops ;
611
- PMBuilder.MergeFunctions = CodeGenOpts.MergeFunctions ;
612
- PMBuilder.PrepareForThinLTO = CodeGenOpts.PrepareForThinLTO ;
613
- PMBuilder.PrepareForLTO = CodeGenOpts.PrepareForLTO ;
614
- PMBuilder.RerollLoops = CodeGenOpts.RerollLoops ;
602
+ // FIXME: This code is a workaround for a number of problems with optimized
603
+ // SYCL code for the SPIR target. This change trying to balance between doing
604
+ // too few and too many optimizations. The current approach is to disable as
605
+ // much as possible just to keep the compiler functional. Eventually we can
606
+ // consider allowing -On option to configure the optimization set for the FE
607
+ // device compiler as well, but before that we must fix all the functional and
608
+ // performance issues caused by LLVM transformantions.
609
+ // E.g. LLVM optimizations make use of llvm intrinsics, instructions, data
610
+ // types, etc., which are not supported by the SPIR-V translator (current
611
+ // "back-end" for SYCL device compiler).
612
+ // NOTE: We use "normal" inliner (i.e. from O2/O3), but limit the rest of
613
+ // optimization pipeline. Inliner is a must for enabling size reduction
614
+ // optimizations.
615
+ if (LangOpts.SYCLIsDevice && TargetTriple.isSPIR ()) {
616
+ PMBuilder.OptLevel = 1 ;
617
+ PMBuilder.SizeLevel = 2 ;
618
+ PMBuilder.SLPVectorize = false ;
619
+ PMBuilder.LoopVectorize = false ;
620
+ PMBuilder.DivergentTarget = true ;
621
+ PMBuilder.DisableGVNLoadPRE = true ;
622
+ PMBuilder.ForgetAllSCEVInLoopUnroll = true ;
623
+
624
+ PMBuilder.DisableUnrollLoops = true ;
625
+ // Loop interleaving in the loop vectorizer has historically been set to be
626
+ // enabled when loop unrolling is enabled.
627
+ PMBuilder.LoopsInterleaved = false ;
628
+ PMBuilder.MergeFunctions = false ;
629
+ PMBuilder.PrepareForThinLTO = false ;
630
+ PMBuilder.PrepareForLTO = false ;
631
+ PMBuilder.RerollLoops = false ;
632
+ } else {
633
+ PMBuilder.OptLevel = CodeGenOpts.OptimizationLevel ;
634
+ PMBuilder.SizeLevel = CodeGenOpts.OptimizeSize ;
635
+ PMBuilder.SLPVectorize = CodeGenOpts.VectorizeSLP ;
636
+ PMBuilder.LoopVectorize = CodeGenOpts.VectorizeLoop ;
637
+
638
+ PMBuilder.DisableUnrollLoops = !CodeGenOpts.UnrollLoops ;
639
+ // Loop interleaving in the loop vectorizer has historically been set to be
640
+ // enabled when loop unrolling is enabled.
641
+ PMBuilder.LoopsInterleaved = CodeGenOpts.UnrollLoops ;
642
+ PMBuilder.MergeFunctions = CodeGenOpts.MergeFunctions ;
643
+ PMBuilder.PrepareForThinLTO = CodeGenOpts.PrepareForThinLTO ;
644
+ PMBuilder.PrepareForLTO = CodeGenOpts.PrepareForLTO ;
645
+ PMBuilder.RerollLoops = CodeGenOpts.RerollLoops ;
646
+ }
615
647
616
648
MPM.add (new TargetLibraryInfoWrapperPass (*TLII));
617
649
@@ -865,14 +897,15 @@ void EmitAssemblyHelper::EmitAssembly(BackendAction Action,
865
897
866
898
std::unique_ptr<llvm::ToolOutputFile> ThinLinkOS, DwoOS;
867
899
900
+ // Clean-up SYCL device code if LLVM passes are disabled
901
+ if (LangOpts.SYCLIsDevice && CodeGenOpts.DisableLLVMPasses )
902
+ PerModulePasses.add (createDeadCodeEliminationPass ());
903
+
868
904
switch (Action) {
869
905
case Backend_EmitNothing:
870
906
break ;
871
907
872
908
case Backend_EmitBC:
873
- if (LangOpts.SYCLIsDevice ) {
874
- PerModulePasses.add (createDeadCodeEliminationPass ());
875
- }
876
909
if (CodeGenOpts.PrepareForThinLTO && !CodeGenOpts.DisableLLVMPasses ) {
877
910
if (!CodeGenOpts.ThinLinkBitcodeFile .empty ()) {
878
911
ThinLinkOS = openOutputFile (CodeGenOpts.ThinLinkBitcodeFile );
@@ -1346,9 +1379,6 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager(
1346
1379
break ;
1347
1380
1348
1381
case Backend_EmitBC:
1349
- if (LangOpts.SYCLIsDevice ) {
1350
- CodeGenPasses.add (createDeadCodeEliminationPass ());
1351
- }
1352
1382
if (CodeGenOpts.PrepareForThinLTO && !CodeGenOpts.DisableLLVMPasses ) {
1353
1383
if (!CodeGenOpts.ThinLinkBitcodeFile .empty ()) {
1354
1384
ThinLinkOS = openOutputFile (CodeGenOpts.ThinLinkBitcodeFile );
0 commit comments