Removing decorations when doing constant propagation. (#2444)

In constant propagation, decoration are transfered from the original
expression to the constant that will replace it.  This can be wrong
because there are no decorations that apply to constants.  We choose to
simply delete the decorations.

Fixes #2441
This commit is contained in:
Steven Perron 2019-03-13 10:40:49 -04:00 committed by GitHub
parent b75f4362f0
commit 9d29c37ac5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 0 deletions

View File

@ -271,6 +271,7 @@ bool CCPPass::ReplaceValues() {
uint32_t id = it.first;
uint32_t cst_id = it.second;
if (!IsVaryingValue(cst_id) && id != cst_id) {
context()->KillNamesAndDecorates(id);
retval |= context()->ReplaceAllUsesWith(id, cst_id);
}
}

View File

@ -896,6 +896,35 @@ OpFunctionEnd
SinglePassRunAndMatch<CCPPass>(text, true);
}
TEST_F(CCPTest, FoldWithDecoration) {
const std::string text = R"(
; CHECK: OpCapability
; CHECK-NOT: OpDecorate
; CHECK: OpFunctionEnd
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %2 "main"
OpExecutionMode %2 OriginUpperLeft
OpSource ESSL 310
OpDecorate %3 RelaxedPrecision
%void = OpTypeVoid
%5 = OpTypeFunction %void
%float = OpTypeFloat 32
%v3float = OpTypeVector %float 3
%float_0 = OpConstant %float 0
%v4float = OpTypeVector %float 4
%10 = OpConstantComposite %v4float %float_0 %float_0 %float_0 %float_0
%2 = OpFunction %void None %5
%11 = OpLabel
%3 = OpVectorShuffle %v3float %10 %10 0 1 2
OpReturn
OpFunctionEnd
)";
SinglePassRunAndMatch<CCPPass>(text, true);
}
} // namespace
} // namespace opt
} // namespace spvtools