Skip to content

Incorrect loop hoisting #293

@cardillan

Description

@cardillan

Loop hoisting may hoist assignments in front of the loop even when the loop is not guaranteed to run:

#set target = 8;

param a = 10;
b = a;
while rand(10) > 10 do
    b = 2 * a;
    print(b);
end;
print(b);

compiles to

    set a 10
    op mul :b 2 a
    op rand *tmp0 10 0
    jump label_7 lessThanEq *tmp0 10
label_4:
        print :b
    op rand *tmp0 10 0
    jump label_4 greaterThan *tmp0 10
    label_7:
    print :b

This loop doesn't execute (obviously), but the program prints 20.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingoptimizerRelated to the code optimizer

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions