glslang/Test/spv.controlFlowAttributes.frag
David Neto 8c3d5b4b6c SPIR-V: Aggressively prune unreachable merge, continue target
More aggressively prune unreachable code as follows.
When no control flow edges reach a merge block or continue target:
- delete their contents so that:
  - a merge block becomes OpLabel, then OpUnreachable
  - a continue target becomes OpLabel, then an OpBranch back to the
    loop header
- any basic block which is dominated by such a merge block or continue
  target is removed as well.
- decorations targeting the removed instructions are removed.

Enables the SPIR-V builder post-processing step the GLSLANG_WEB case.
2019-10-29 15:33:54 -04:00

47 lines
1.5 KiB
JavaScript

#version 450
#extension GL_EXT_control_flow_attributes : enable
bool cond;
void f0() {
[[loop]] for (;;) { }
}
void f1() {
[[dont_unroll]] while(true) { }
}
void main()
{
[[unroll]] for (int i = 0; i < 8; ++i) { }
f0();
[[dependency_infinite]] do { } while(true);
[[dependency_length(1+3)]] for (int i = 0; i < 8; ++i) { }
[[flatten]] if (cond) { } else { }
[[branch]] if (cond) cond = false;
[[dont_flatten]] switch(3) { } // dropped
[[dont_flatten]] switch(3) { case 3: break; }
// warnings on all these
[[unroll(2)]] for (int i = 0; i < 8; ++i) { }
[[dont_unroll(-2)]] while(true) { }
[[dependency_infinite(3)]] do { } while(true);
[[dependency_length]] for (int i = 0; i < 8; ++i) { }
[[flatten(3)]] if (cond) { } else { }
[[branch(5.2)]] if (cond) cond = false;
[[dont_flatten(3 + 7)]] switch(3) { case 3: break; }
// other valid uses
[[ unroll, dont_unroll, dependency_length(2) ]] while(cond) { }
[ [ dont_flatten , branch ] ] switch(3) { case 3: break; }
[
// attribute
[
// here
flatten
]
] if (cond) { } else { }
[[ dependency_length(2), dependency_infinite ]] while(cond) { }
}