77702f1704
When we determine that a function only contains a single return statement and it is at the top level (i.e. not inside any scopes), there is no need to create a temporary variable and store the result expression into a variable. Instead, we can directly replace the function-call expression with the return-statement's expression. Unlike my previous solution, this does not require variable declarations to be rewritten. The no-scopes limitation makes it slightly less effective in theory, but in practice we still get almost all of the benefit. The no-scope limitation bites us on structures like @if (true) { return x; } else { return y; } Which will optimize away the if, but leave the scope: { return x; } However, this is not a big deal; the biggest wins are single-line helper functions like `guarded_divide` and `unpremul` which retain the full benefit. Change-Id: I7fbb725e65db021b9795c04c816819669815578f Reviewed-on: https://skia-review.googlesource.com/c/skia/+/345167 Commit-Queue: John Stiles <johnstiles@google.com> Auto-Submit: John Stiles <johnstiles@google.com> Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
20 lines
444 B
GLSL
20 lines
444 B
GLSL
|
|
out vec4 sk_FragColor;
|
|
void main() {
|
|
float _1_x = 1.0;
|
|
_1_x = length(1.0);
|
|
_1_x = distance(_1_x, 2.0);
|
|
_1_x = dot(_1_x, 2.0);
|
|
_1_x = normalize(_1_x);
|
|
float x = _1_x;
|
|
|
|
vec2 _3_x = vec2(1.0, 2.0);
|
|
_3_x = vec2(length(vec2(1.0, 2.0)));
|
|
_3_x = vec2(distance(_3_x, vec2(3.0, 4.0)));
|
|
_3_x = vec2(dot(_3_x, vec2(3.0, 4.0)));
|
|
_3_x = normalize(_3_x);
|
|
vec2 y = _3_x;
|
|
|
|
sk_FragColor = vec4(x, y, 1.0);
|
|
}
|