aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source/opt/ccp_pass.cpp3
-rw-r--r--test/opt/ccp_test.cpp29
2 files changed, 31 insertions, 1 deletions
diff --git a/source/opt/ccp_pass.cpp b/source/opt/ccp_pass.cpp
index 5099b477..5f855027 100644
--- a/source/opt/ccp_pass.cpp
+++ b/source/opt/ccp_pass.cpp
@@ -172,7 +172,8 @@ SSAPropagator::PropStatus CCPPass::VisitAssignment(Instruction* instr) {
if (folded_inst != nullptr) {
// We do not want to change the body of the function by adding new
// instructions. When folding we can only generate new constants.
- assert(folded_inst->IsConstant() &&
+ assert((folded_inst->IsConstant() ||
+ IsSpecConstantInst(folded_inst->opcode())) &&
"CCP is only interested in constant values.");
uint32_t new_val = ComputeLatticeMeet(instr, folded_inst->result_id());
values_[instr->result_id()] = new_val;
diff --git a/test/opt/ccp_test.cpp b/test/opt/ccp_test.cpp
index ae7043b9..f0f24362 100644
--- a/test/opt/ccp_test.cpp
+++ b/test/opt/ccp_test.cpp
@@ -582,6 +582,35 @@ TEST_F(CCPTest, SkipSpecConstantInstrucitons) {
EXPECT_EQ(std::get<1>(res), Pass::Status::SuccessWithoutChange);
}
+TEST_F(CCPTest, FoldConstantCompositeInstrucitonsWithSpecConst) {
+ const std::string spv_asm = R"(
+ OpCapability Shader
+ OpMemoryModel Logical GLSL450
+ OpEntryPoint Fragment %1 "main"
+ OpExecutionMode %1 OriginUpperLeft
+ %void = OpTypeVoid
+ %4 = OpTypeFunction %void
+ %bool = OpTypeBool
+ %v3bool = OpTypeVector %bool 3
+ %_struct_8 = OpTypeStruct %v3bool
+ %true = OpConstantTrue %bool
+; CHECK: [[spec_const:%\w+]] = OpSpecConstantComposite %v3bool
+ %11 = OpSpecConstantComposite %v3bool %true %true %true
+ %12 = OpConstantComposite %_struct_8 %11
+; CHECK: OpFunction
+ %1 = OpFunction %void None %4
+ %29 = OpLabel
+ %31 = OpCompositeExtract %v3bool %12 0
+; CHECK: OpCompositeExtract %bool [[spec_const]] 0
+ %32 = OpCompositeExtract %bool %31 0
+ OpReturn
+ OpFunctionEnd
+ )";
+
+ auto result = SinglePassRunAndMatch<CCPPass>(spv_asm, true);
+ EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithChange);
+}
+
TEST_F(CCPTest, UpdateSubsequentPhisToVarying) {
const std::string text = R"(
OpCapability Shader