skia2/resources/sksl/folding/AssignmentOps.sksl
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

38 lines
635 B
Plaintext

uniform half4 colorRed, colorGreen;
half4 main() {
bool ok = true;
int a = 1;
a = a + a; // 2
a += a; // 4
a = a + a; // 8
a += a; // 16
a = a + a; // 32
ok = ok && (a == 32);
int b = 10;
b = b - 2; // 8
b -= 2; // 6
b = b - 1; // 5
b -= 3; // 2
ok = ok && (b == 2);
int c = 2;
c = c * c; // 4
c *= c; // 16
c = c * 4; // 64
c *= 2; // 128
ok = ok && (c == 128);
int d = 256;
d = d / 2; // 128
d /= 2; // 64
d = d / 4; // 16
d /= 4; // 4
ok = ok && (d == 4);
return ok ? colorGreen : colorRed;
}