// module. The values of each OpConstant declaration is the identity
// assignment (i.e., each constant is its own value).
for (const auto& inst : context()->module()->GetConstants()) {
- values_[inst->result_id()] = inst->result_id();
+ // Skip specialization constants.
+ if (inst->IsConstant()) {
+ values_[inst->result_id()] = inst->result_id();
+ }
}
}
bool Instruction::IsAtomicOp() const { return spvOpcodeIsAtomicOp(opcode()); }
-bool Instruction::IsConstant() const { return IsConstantInst(opcode()); }
+bool Instruction::IsConstant() const {
+ return IsCompileTimeConstantInst(opcode());
+}
} // namespace ir
} // namespace spvtools
auto res = SinglePassRunToBinary<opt::CCPPass>(spv_asm, true);
EXPECT_EQ(std::get<1>(res), opt::Pass::Status::SuccessWithoutChange);
}
+
+TEST_F(CCPTest, SkipSpecConstantInstrucitons) {
+ const std::string spv_asm = R"(
+ OpCapability Shader
+ %1 = OpExtInstImport "GLSL.std.450"
+ OpMemoryModel Logical GLSL450
+ OpEntryPoint Fragment %main "main"
+ OpExecutionMode %main OriginUpperLeft
+ OpSource HLSL 500
+ OpName %main "main"
+ %void = OpTypeVoid
+ %4 = OpTypeFunction %void
+ %bool = OpTypeBool
+ %10 = OpSpecConstantFalse %bool
+ %main = OpFunction %void None %4
+ %11 = OpLabel
+ %12 = OpBranchConditional %10 %l1 %l2
+ %l1 = OpLabel
+ OpReturn
+ %l2 = OpLabel
+ OpReturn
+ OpFunctionEnd
+ )";
+
+ auto res = SinglePassRunToBinary<opt::CCPPass>(spv_asm, true);
+ EXPECT_EQ(std::get<1>(res), opt::Pass::Status::SuccessWithoutChange);
+}
#endif
} // namespace