skia2/tests/sksl/folding/AssignmentOps.glsl
John Stiles 34c098d7f8 Add SkSL test demonstrating missed optimization with +=.
Currently, SkSL is able to constant-propagate `x = x + constant` into
`x = constant` when the starting value of x is known. However, it is not
able to do the same optimization for `x += constant`. This test
demonstrates that once += is encountered, we lose track of x's value and
can no longer propagate its value.

(This is equally true of all the op-assignment operators, += -=
*= /= etc.)

Change-Id: I3523e96baf9a73982cf3b09f0d23b95adacf106b
Bug: skia:11192
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/368248
Auto-Submit: John Stiles <johnstiles@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
2021-02-09 19:17:26 +00:00

34 lines
516 B
GLSL

out vec4 sk_FragColor;
uniform vec4 colorRed;
uniform vec4 colorGreen;
vec4 main() {
bool ok = true;
int a = 1;
a = 2;
a += a;
a = a + a;
a += a;
a = a + a;
ok = a == 32;
int b = 10;
b = 8;
b -= 2;
b = b - 1;
b -= 3;
ok = ok && b == 2;
int c = 2;
c = 4;
c *= c;
c = c * 4;
c *= 2;
ok = ok && c == 128;
int d = 256;
d = 128;
d /= 2;
d = d / 4;
d /= 4;
ok = ok && d == 4;
return ok ? colorGreen : colorRed;
}