Skip to content

Commit 9350eb0

Browse files
committed
[SYCL] Disable loop unrolling and vectorization
Loop unrolling in "SYCL optimization mode" uses default heuristic, which is tuned for CPU and might not be profitable for other devices.
1 parent f253851 commit 9350eb0

File tree

1 file changed

+26
-20
lines changed

1 file changed

+26
-20
lines changed

llvm/lib/Transforms/IPO/PassManagerBuilder.cpp

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -447,8 +447,9 @@ void PassManagerBuilder::addFunctionSimplificationPasses(
447447
MPM.add(createLoopInterchangePass()); // Interchange loops
448448

449449
// Unroll small loops
450-
MPM.add(createSimpleLoopUnrollPass(OptLevel, DisableUnrollLoops,
451-
ForgetAllSCEVInLoopUnroll));
450+
if (!SYCLOptimizationMode) // TODO: disable the whole loop pass pipeline?
451+
MPM.add(createSimpleLoopUnrollPass(OptLevel, DisableUnrollLoops,
452+
ForgetAllSCEVInLoopUnroll));
452453
addExtensionsToPM(EP_LoopOptimizerEnd, MPM);
453454
// This ends the loop pass pipelines.
454455

@@ -819,19 +820,21 @@ void PassManagerBuilder::populateModulePassManager(
819820
MPM.add(createLoopUnrollAndJamPass(OptLevel));
820821
}
821822

822-
// Unroll small loops
823-
MPM.add(createLoopUnrollPass(OptLevel, DisableUnrollLoops,
824-
ForgetAllSCEVInLoopUnroll));
823+
if (!SYCLOptimizationMode) {
824+
// Unroll small loops
825+
MPM.add(createLoopUnrollPass(OptLevel, DisableUnrollLoops,
826+
ForgetAllSCEVInLoopUnroll));
825827

826-
if (!DisableUnrollLoops) {
827-
// LoopUnroll may generate some redundency to cleanup.
828-
MPM.add(createInstructionCombiningPass());
828+
if (!DisableUnrollLoops) {
829+
// LoopUnroll may generate some redundency to cleanup.
830+
MPM.add(createInstructionCombiningPass());
829831

830-
// Runtime unrolling will introduce runtime check in loop prologue. If the
831-
// unrolled loop is a inner loop, then the prologue will be inside the
832-
// outer loop. LICM pass can help to promote the runtime check out if the
833-
// checked value is loop invariant.
834-
MPM.add(createLICMPass(LicmMssaOptCap, LicmMssaNoAccForPromotionCap));
832+
// Runtime unrolling will introduce runtime check in loop prologue. If the
833+
// unrolled loop is a inner loop, then the prologue will be inside the
834+
// outer loop. LICM pass can help to promote the runtime check out if the
835+
// checked value is loop invariant.
836+
MPM.add(createLICMPass(LicmMssaOptCap, LicmMssaNoAccForPromotionCap));
837+
}
835838
}
836839

837840
MPM.add(createWarnMissedTransformationsPass());
@@ -1034,13 +1037,16 @@ void PassManagerBuilder::addLTOOptimizationPasses(legacy::PassManagerBase &PM) {
10341037
if (EnableLoopInterchange)
10351038
PM.add(createLoopInterchangePass());
10361039

1037-
// Unroll small loops
1038-
PM.add(createSimpleLoopUnrollPass(OptLevel, DisableUnrollLoops,
1039-
ForgetAllSCEVInLoopUnroll));
1040-
PM.add(createLoopVectorizePass(true, !LoopVectorize));
1041-
// The vectorizer may have significantly shortened a loop body; unroll again.
1042-
PM.add(createLoopUnrollPass(OptLevel, DisableUnrollLoops,
1043-
ForgetAllSCEVInLoopUnroll));
1040+
if (!SYCLOptimizationMode) {
1041+
// Unroll small loops
1042+
PM.add(createSimpleLoopUnrollPass(OptLevel, DisableUnrollLoops,
1043+
ForgetAllSCEVInLoopUnroll));
1044+
PM.add(createLoopVectorizePass(true, !LoopVectorize));
1045+
// The vectorizer may have significantly shortened a loop body; unroll
1046+
// again.
1047+
PM.add(createLoopUnrollPass(OptLevel, DisableUnrollLoops,
1048+
ForgetAllSCEVInLoopUnroll));
1049+
}
10441050

10451051
PM.add(createWarnMissedTransformationsPass());
10461052

0 commit comments

Comments
 (0)