Skip to content

Commit 44cf554

Browse files
luciechois-perron
andauthored
spirv-opt: Suppress assertion error for 16 bit integer extended instructions in CCP pass (KhronosGroup#6287)
* Suppress assertion error for 16 bit extended instructions in CCP pass * Update comment Co-authored-by: Steven Perron <[email protected]> --------- Co-authored-by: Steven Perron <[email protected]>
1 parent 466b5ec commit 44cf554

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

source/opt/ccp_pass.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,13 @@ void CCPPass::Initialize() {
360360
}
361361
}
362362

363+
// Mark the extended instruction imports as `kVarying`. We know they
364+
// will not be constants, and will be used by `OpExtInst` instructions.
365+
// This allows those instructions to be fully processed.
366+
for (const auto& inst : get_module()->ext_inst_imports()) {
367+
values_[inst.result_id()] = kVaryingSSAId;
368+
}
369+
363370
original_id_bound_ = context()->module()->IdBound();
364371
}
365372

test/opt/ccp_test.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,6 +1237,34 @@ TEST_F(CCPTest, CCPNoChangeFailureWithUnfoldableInstr) {
12371237
EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithChange);
12381238
}
12391239

1240+
TEST_F(CCPTest, CCPSuccessWithNoCCPOnExtendedInstruction) {
1241+
// We don't expect to have Constant Propagation on certain
1242+
// extended instructions with 16 bit integers. This is to
1243+
// test that this stage doesn't throw errors. If we add support
1244+
// for 16 bit integers, this test should change.
1245+
1246+
const std::string text = R"(OpCapability Shader
1247+
OpCapability Float16
1248+
%1 = OpExtInstImport "GLSL.std.450"
1249+
OpMemoryModel Logical GLSL450
1250+
OpEntryPoint Fragment %main "main"
1251+
OpExecutionMode %main OriginUpperLeft
1252+
OpSource GLSL 140
1253+
OpName %main "main"
1254+
%void = OpTypeVoid
1255+
%half = OpTypeFloat 16
1256+
%half_0x1p_0 = OpConstant %half 0x1p+0
1257+
%6 = OpTypeFunction %void
1258+
%main = OpFunction %void None %6
1259+
%7 = OpLabel
1260+
%8 = OpExtInst %half %1 Cos %half_0x1p_0
1261+
OpReturn
1262+
OpFunctionEnd
1263+
)";
1264+
1265+
SinglePassRunAndCheck<CCPPass>(text, text, false);
1266+
}
1267+
12401268
TEST_F(CCPTest, FunctionDeclaration) {
12411269
// Make sure the pass works with a function declaration that is called.
12421270
const std::string text = R"(OpCapability Addresses

0 commit comments

Comments
 (0)