mirror of
https://github.com/KhronosGroup/SPIRV-Tools
synced 2024-11-22 11:40:05 +00:00
Generalize assert in ccp (#4735)
CCP does not want to fold an instruction unless it folds to a constant. There is an asser to check for this. The question if a spec constant counts as a constant. The constant folder considers a spec constant a constand, but CCP does not. I've fixed the assert in CCP to match what the folder does. It should not require any new changes to CCP.
This commit is contained in:
parent
196f638d73
commit
4fa1a6f9b4
@ -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;
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user