Skip to content

Commit 76ffef7

Browse files
authored
[SYCL] Disable createIndVarSimplifyPass for SPIR target in SYCL mode. (#2275)
1 parent 69e1ea8 commit 76ffef7

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4106,6 +4106,11 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
41064106
if (!Args.hasFlag(options::OPT_fsycl_std_optimizations,
41074107
options::OPT_fno_sycl_std_optimizations, true))
41084108
CmdArgs.push_back("-fno-sycl-std-optimizations");
4109+
else if (RawTriple.isSPIR()) {
4110+
// Set `sycl-opt` option to configure LLVM passes for SPIR target
4111+
CmdArgs.push_back("-mllvm");
4112+
CmdArgs.push_back("-sycl-opt");
4113+
}
41094114

41104115
// Pass the triple of host when doing SYCL
41114116
auto AuxT = llvm::Triple(llvm::sys::getProcessTriple());

llvm/lib/Transforms/IPO/PassManagerBuilder.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ static cl::opt<bool>
6868
RunLoopRerolling("reroll-loops", cl::Hidden,
6969
cl::desc("Run the loop rerolling pass"));
7070

71+
static cl::opt<bool>
72+
SYCLOptimizationMode("sycl-opt", cl::init(false), cl::Hidden,
73+
cl::desc("Enable SYCL optimization mode."));
74+
7175
static cl::opt<bool> RunNewGVN("enable-newgvn", cl::init(false), cl::Hidden,
7276
cl::desc("Run the NewGVN pass"));
7377

@@ -429,7 +433,12 @@ void PassManagerBuilder::addFunctionSimplificationPasses(
429433
MPM.add(createCFGSimplificationPass());
430434
MPM.add(createInstructionCombiningPass());
431435
// We resume loop passes creating a second loop pipeline here.
432-
MPM.add(createIndVarSimplifyPass()); // Canonicalize indvars
436+
// TODO: this pass hurts performance due to promotions of induction variables
437+
// from 32-bit value to 64-bit values. I assume it's because SPIR is a virtual
438+
// target with unlimited # of registers and pass doesn't take into account
439+
// that on real HW this promotion is not beneficial.
440+
if (!SYCLOptimizationMode)
441+
MPM.add(createIndVarSimplifyPass()); // Canonicalize indvars
433442
MPM.add(createLoopIdiomPass()); // Recognize idioms like memset.
434443
addExtensionsToPM(EP_LateLoopOptimizations, MPM);
435444
MPM.add(createLoopDeletionPass()); // Delete dead loops

0 commit comments

Comments
 (0)