8000 Simplify a+-b and a--b by laurentlb · Pull Request #354 · laurentlb/shader-minifier · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Simplify a+-b and a--b #354

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/rewriter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ module private RewriterImpl =
| FunCall(Op "-", [Int (i1, su)]) -> Int (-i1, su)
| FunCall(Op "-", [FunCall(Op "-", [e])]) -> e
| FunCall(Op "+", [e]) -> e
// e1 - - e2 -> e1 + e2
| FunCall(Op "-", [e1; FunCall(Op "-", [e2])]) ->
FunCall(Op "+", [e1; e2]) |> env.fExpr env
// e1 + - e2 -> e1 - e2
| FunCall(Op "+", [e1; FunCall(Op "-", [e2])]) ->
FunCall(Op "-", [e1; e2]) |> env.fExpr env

| FunCall(Op ",", [e1; FunCall(Op ",", [e2; e3])]) ->
FunCall(Op ",", [env.fExpr env (FunCall(Op ",", [e1; e2])); e3])
Expand Down
6 changes: 3 additions & 3 deletions tests/compression_results.log
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ controllable-machinery.frag 7708 => 1220.329
ed-209.frag 7766 => 1341.089
elevated.hlsl 3405 => 603.218
endeavour.frag 2605 => 534.116
from-the-seas-to-the-stars.frag 14292 => 2328.094
from-the-seas-to-the-stars.frag 14252 => 2317.681
frozen-wasteland.frag 4578 => 806.452
kinder_painter.frag 2865 => 445.014
leizex.frag 2298 => 510.191
Expand All @@ -17,8 +17,8 @@ orchard.frag 5537 => 1022.773
oscars_chair.frag 4651 => 986.364
robin.frag 6295 => 1052.336
slisesix.frag 4573 => 931.855
terrarium.frag 3624 => 745.827
terrarium.frag 3611 => 744.367
the_real_party_is_in_your_pocket.frag 12111 => 1794.687
valley_ball.glsl 4386 => 888.496
yx_long_way_from_home.frag 2947 => 606.406
Total: 135069 => 23627.076
Total: 135016 => 23615.203
3 changes: 2 additions & 1 deletion tests/unit/simplify.expected
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#version 330

int i;
float bar(float x)
{
float a=6.;
Expand All @@ -19,7 +20,7 @@ float baz(float a)
b+=sin(a);
float c=b+5.;
c+=sin(b);
return-c+-c+c;
return-c-c+c;
}
out vec3 output;
void notMain(float x)
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/simplify.frag
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#version 330

int i;

float bar(float x)
{
float a = x;
Expand Down
0