From 453f143dba3fea76bc777b7d6d933c4017f7e4e8 Mon Sep 17 00:00:00 2001 From: John Stiles Date: Thu, 25 Feb 2021 16:58:04 -0500 Subject: [PATCH] Improve dead-code elimination check in SPIR-V. The dead-code elimination pass only occurs when three separate flags are all enabled: optimize, control-flow analysis, dead-code elimination. Previously the code checked just the dead-code elimination flag, not the other two. Change-Id: I1e7e356432c4398f6b072d472fe4d1ec5dac107e Reviewed-on: https://skia-review.googlesource.com/c/skia/+/376178 Auto-Submit: John Stiles Commit-Queue: Brian Osman Reviewed-by: Brian Osman --- src/sksl/SkSLSPIRVCodeGenerator.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/sksl/SkSLSPIRVCodeGenerator.cpp b/src/sksl/SkSLSPIRVCodeGenerator.cpp index 0768254bfa..3bd700e029 100644 --- a/src/sksl/SkSLSPIRVCodeGenerator.cpp +++ b/src/sksl/SkSLSPIRVCodeGenerator.cpp @@ -236,18 +236,21 @@ void SPIRVCodeGenerator::writeOpCode(SpvOp_ opCode, int length, OutputStream& ou case SpvOpMemberDecorate: break; default: - if (!fProgram.fConfig->fSettings.fDeadCodeElimination) { + if (fProgram.fConfig->fSettings.fOptimize && + fProgram.fConfig->fSettings.fControlFlowAnalysis && + fProgram.fConfig->fSettings.fDeadCodeElimination) { + // When dead-code elimination is enabled, all code should be reachable and an + // associated block should already exist. + SkASSERT(fCurrentBlock); + } else { // When dead-code elimination is disabled, we may find ourselves with instructions // that don't have an associated block. This should be a rare event, but if it // happens, synthesize a label; this is necessary to satisfy the validator. if (fCurrentBlock == 0) { this->writeLabel(this->nextId(), out); } - } else { - // When dead-code elimination is enabled, all code should be reachable and an - // associated block should already exist. - SkASSERT(fCurrentBlock); } + break; } this->writeWord((length << 16) | opCode, out); }