skia2/resources/sksl/shared/StaticSwitchWithContinue.sksl
John Stiles 04ca41acf3 Fix switch optimization pass.
The optimizer now properly recognizes all types of exits from a switch
statement. Break, continue and return are all potential exits and need
to be considered when determining the exit path from the switch.

Previously, dead code elimination was hiding the effects of this bug
from us, but it meant that an optimized switch had the potential to
generate lots of worthless IR nodes which then needed to be detected and
eliminated by the CFG. In particular, this affected the enum form of
blend, causing a catastrophic amount of extra work to be done.

Change-Id: If857e38cadfc016884624ea4db25a273ad3dce5b
Bug: skia:11352
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/372958
Commit-Queue: John Stiles <johnstiles@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
2021-02-23 15:38:24 +00:00

25 lines
787 B
Plaintext

/*#pragma settings NoDeadCodeElimination*/
// A continue inside a switch (where permitted) prevents fallthrough to the next case block, just
// like a break statement would.
// Make sure that we properly dead-strip code following `continue` in a switch.
// This is particularly relevant because our inliner replaces return statements with continue.
uniform half4 colorGreen, colorRed;
half4 main() {
// A looping construct is required for continue.
float result = 0;
for (int x=0; x<=1; x++) {
@switch (2) {
case 1: result = abs(1); continue;
case 2: result = abs(2); continue;
case 3: result = abs(3); continue;
case 4: result = abs(4); continue;
}
}
return result == 2 ? colorGreen : colorRed;
}