You are browsing as a guest. Sign up (or log in) to start making projects!

5h 46m 36s logged

Source code of the image:

on GreenFlag {
    if(a() == 5) {
        looks::say("yo!");
    }
    int index = 0;
    index = index + 1;
    rgb(index, 5, 5);
    index = 5;
    while(true) {
        pen::eraseAll();
        render();
    }
}

The image is of the entire flow working perfectly:
The index variable had their value propagated to “1” by the Sequential constant propagation optimization
The variable got its uses removed by Inline single-use assignments
Then the variable got fully removed by Dead store elimination
The rgb function got inlined.
Then while it was inlined, because the rgb function’s return wasn’t being used, it got fully removed(the inlining preserves side effects while removing its return value, but because it didn’t have any side effects it got fully removed)

Same with the a() function:
It got inlined
Then the if statement became

if(5 == 5) { looks::say("yo!"); }

Then Constant folding turned 5 == 5 into true
Then Dead code elimination turned if(true) into just the then block

I know most optimizations look like they aren’t that powerful, but when combined with other optimizations and ran in a loop, they can pile up and actually optimize code

Optimizations

Simplify boolean equality: Simplifies x == true to x, simplifies x == false to !x
Simplify double negation: Simplifies !!x to x, simplifies --x to x
Constant folding: Simplifies true == true to true, simplifies 5 + 5 to 10
Repeat to While: Converts repeat(amount) to a while loop
Dead code elimination: Removes provably unreachable code blocks, eg: if(true) { ... } else { .. } turns into ..., removing the if and the else block entirely

Now the big ones

Sequential constant propagation: Analyzes the control flow of your program, removing useless variable assignments and inlining their expressions
Inline single use assignment: Self explanatory
Dead store elimination: Removes useless “set variable to x” blocks that don’t get used afterwards
Function inlining: The compiler evaluates a cost for every function call is inside a function, if that total cost is less than 10,000, it gets inlined inside that function, removing call overhead and allowing for further optimization

Other misc stuff:

Fixed the while bug (if you called a function inside a while statement, it would only get called once)
Made function lowering not allocate a stack slot if we’re ignoring return
Made the OptimizeToGlobals optimization be called last to allow variable optimizations to happen first

0
2

Comments 0

No comments yet. Be the first!