summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source/slang/slang-ir-spirv-legalize.cpp18
-rw-r--r--tests/spirv/infinite-loop.slang17
2 files changed, 23 insertions, 12 deletions
diff --git a/source/slang/slang-ir-spirv-legalize.cpp b/source/slang/slang-ir-spirv-legalize.cpp
index 965d6dc9b..97649f4ad 100644
--- a/source/slang/slang-ir-spirv-legalize.cpp
+++ b/source/slang/slang-ir-spirv-legalize.cpp
@@ -184,13 +184,7 @@ struct SPIRVLegalizationContext : public SourceEmitterBase
//
OrderedHashSet<IRInst*> workList;
- void addToWorkList(IRInst* inst)
- {
- if (workList.add(inst))
- {
- addUsersToWorkList(inst);
- }
- }
+ void addToWorkList(IRInst* inst) { workList.add(inst); }
void addUsersToWorkList(IRInst* inst)
{
@@ -1692,8 +1686,6 @@ struct SPIRVLegalizationContext : public SourceEmitterBase
}
};
- void processBranch(IRInst* branch) { addToWorkList(branch->getOperand(0)); }
-
void processPtrLit(IRInst* inst)
{
IRBuilder builder(inst);
@@ -1844,9 +1836,11 @@ struct SPIRVLegalizationContext : public SourceEmitterBase
case kIROp_PtrLit:
processPtrLit(inst);
break;
- case kIROp_UnconditionalBranch:
- processBranch(inst);
- break;
+ // kIROp_UnconditionalBranch is handled in default case that only
+ // adds children inst and not target inst to work list.
+ // Branch target should be added to work list via its parent,
+ // to avoid cycle when branch target block has branch to the block
+ // that's parent of this branch inst.
case kIROp_SPIRVAsm:
processSPIRVAsm(as<IRSPIRVAsm>(inst));
break;
diff --git a/tests/spirv/infinite-loop.slang b/tests/spirv/infinite-loop.slang
new file mode 100644
index 000000000..1562f7334
--- /dev/null
+++ b/tests/spirv/infinite-loop.slang
@@ -0,0 +1,17 @@
+// Simple regression test for SPIRV compilation hang when there is cycle between unconditional branch and block.
+// The -g was necessary to reproduce the hang prior to fix for https://github.com/shader-slang/slang/issues/8669
+
+//TEST:SIMPLE(filecheck=CHECK): -target spirv -stage fragment -entry main -g
+//CHECK: main
+//CHECK: OpBranch
+//CHECK: OpUnreachable
+
+layout(location = 0) out float4 output_color;
+[shader("fragment")]
+void main()
+{
+ while (true) {
+ int i = 0;
+ }
+ output_color = float4(1, 2, 3, 4);
+}