@@ -390,12 +390,6 @@ inline void AddLegalizationPasses(CodeGenContext &ctx, const CShaderProgram::Ker
390
390
mpm.add (llvm::createLoopSimplifyPass ());
391
391
}
392
392
393
- if (isOptDisabled)
394
- {
395
- // Since we don't support switch statements, switch lowering is needed.
396
- // But when optimizations are disabled, the pass doesn't run as a part of OptimizeIR.
397
- mpm.add (llvm::createLowerSwitchPass ());
398
- }
399
393
400
394
// Lower/Resolve OCL inlined constants.
401
395
if (ctx.m_DriverInfo .NeedLoweringInlinedConstants ()) {
@@ -497,10 +491,9 @@ inline void AddLegalizationPasses(CodeGenContext &ctx, const CShaderProgram::Ker
497
491
mpm.add (createConstantPropagationPass ());
498
492
mpm.add (createDeadCodeEliminationPass ());
499
493
mpm.add (createCFGSimplificationPass ());
500
- // CFG simplification can create switch statement we don't support
501
- mpm.add (createLowerSwitchPass ());
502
-
503
- }
494
+ }
495
+ // Since we don't support switch statements, switch lowering is needed after the last CFG simplication
496
+ mpm.add (llvm::createLowerSwitchPass ());
504
497
505
498
// Split big vector & 3-element load/store, etc.
506
499
mpm.add (createVectorPreProcessPass ());
@@ -1227,7 +1220,6 @@ void OptimizeIR(CodeGenContext* pContext)
1227
1220
{
1228
1221
mpm.add (createSROAPass ());
1229
1222
}
1230
- mpm.add (llvm::createInstructionCombiningPass ());
1231
1223
}
1232
1224
1233
1225
if (pContext->m_shaderHasLoadStore )
@@ -1291,7 +1283,11 @@ void OptimizeIR(CodeGenContext* pContext)
1291
1283
mpm.add (llvm::createLowerSwitchPass ());
1292
1284
// After lowering 'switch', run jump threading to remove redundant jumps.
1293
1285
mpm.add (llvm::createJumpThreadingPass ());
1286
+
1287
+ // run instruction combining to clean up the code after CFG optimizations
1288
+ mpm.add (createInstructionCombiningPass ());
1294
1289
mpm.add (llvm::createDeadCodeEliminationPass ());
1290
+ mpm.add (llvm::createEarlyCSEPass ());
1295
1291
1296
1292
if (pContext->type == ShaderType::PIXEL_SHADER)
1297
1293
{
0 commit comments