mc-imperial / spirv-control-flow

Formal modelling of SPIR-V control flow using Alloy
Apache License 2.0
2 stars 0 forks source link

Selection must be structured #36

Open vili-1 opened 3 years ago

vili-1 commented 3 years ago

This is generated as valid by Alloy; the spirv-val says:

error: line 24: Selection must be structured OpBranchConditional %true %15 %16

We have a rule which allows %14 to have multiple successors if %14 is a continue block. In the spec the definition of continue block is:

Continue Block: A block containing a branch to an OpLoopMerge instruction’s Continue Target..

So we our model is in line with this definition, but I guess the intention in the spec is that the loop construct in question should contain the continue block; what do you think @afd cfg_1

Archive.zip

afd commented 3 years ago

Interesting example! Nothing gets past Alloy :)

Yes: the issue here is that 14 is technically a break block, because of the edge 14->16 and because 16 is a loop merge (by the same logic, 14 is also a continue block). But the block 16 is one of those weird single-block loops.

Now that we have rules for exits, I think we can replace our rule that allows a non-header to have multiple successors only under certain conditions with the following rule:

By this, I mean that B is in some construct, and at least one of the edges B->C, B->D leaves the construct according to the various legal rules for structured exits that we have been discussing.

That would exclude this example, because neither 14->15 nor 14->16 is an exit edge.

How does that sound? Could you try modelling it?