Added test.
}
void AggressiveDCEPass::InitializeModuleScopeLiveInstructions() {
+ // Keep all execution modes.
for (auto& exec : get_module()->execution_modes()) {
AddToWorklist(&exec);
}
+ // Keep all entry points.
for (auto& entry : get_module()->entry_points()) {
AddToWorklist(&entry);
}
+ // Keep workgroup size.
+ for (auto& anno : get_module()->annotations()) {
+ if (anno.opcode() == SpvOpDecorate) {
+ if (anno.GetSingleWordInOperand(1u) == SpvDecorationBuiltIn &&
+ anno.GetSingleWordInOperand(2u) == SpvBuiltInWorkgroupSize) {
+ AddToWorklist(&anno);
+ }
+ }
+ }
}
Pass::Status AggressiveDCEPass::ProcessImpl() {
// Returns true if |inst| is dead.
bool IsDead(ir::Instruction* inst);
- // Adds entry points and execution modes to the worklist for processing with
- // the first function.
+ // Adds entry points, execution modes and workgroup size decorations to the
+ // worklist for processing with the first function.
void InitializeModuleScopeLiveInstructions();
// Add |inst| to worklist_ and live_insts_.
SinglePassRunAndMatch<opt::AggressiveDCEPass>(text, true);
}
+
+// Test for #1404
+TEST_F(AggressiveDCETest, DontRemoveWorkgroupSize) {
+ const std::string text = R"(
+; CHECK: OpDecorate [[wgs:%\w+]] BuiltIn WorkgroupSize
+; CHECK: [[wgs]] = OpSpecConstantComposite
+OpCapability Shader
+OpMemoryModel Logical GLSL450
+OpEntryPoint GLCompute %func "func"
+OpExecutionMode %func LocalSize 1 1 1
+OpDecorate %1 BuiltIn WorkgroupSize
+%void = OpTypeVoid
+%int = OpTypeInt 32 0
+%functy = OpTypeFunction %void
+%v3int = OpTypeVector %int 3
+%2 = OpSpecConstant %int 1
+%1 = OpSpecConstantComposite %v3int %2 %2 %2
+%func = OpFunction %void None %functy
+%3 = OpLabel
+OpReturn
+OpFunctionEnd
+)";
+
+ SinglePassRunAndMatch<opt::AggressiveDCEPass>(text, true);
+}
#endif // SPIRV_EFFCEE
// Test for #1214