mlogjs icon indicating copy to clipboard operation
mlogjs copied to clipboard

Useless jumps with nested if

Open hsaturn opened this issue 11 months ago • 1 comments

Hello

Some useless jumps are generated with nested if. Here is the smallest code I've found, but with large code, I saw a bunch of 7 useless jumps !!

var c;
if (c < 10) {
    if (c < 5)
        c = 5;
    else
        c = 10;
}
else
    c = 23;

The generated code is

0 jump 6 greaterThanEq c:1:4 10
1 jump 4 greaterThanEq c:1:4 5
2 set c:1:4 5
3 jump 5 always  --> JUMP TO 5
4 set c:1:4 10
5 jump 7 always --> THEN JUMP TO 7 !
6 set c:1:4 23
7 end

As we can see, the jump at line 3 goes to line 5 wich jumps then to line 7. I think this is easy to add a pass to optimize this, without having to remove a line (which could cause some issue with indirect jumps such as those made with @counter (arrays etc..))

Best regards, MLogJs is so great !

hsaturn avatar Mar 13 '24 23:03 hsaturn

Hi, thanks for filing an issue. This problem will be fixed by #222.

JeanJPNM avatar Mar 14 '24 11:03 JeanJPNM