Skip to content
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

Bug: wrong jump threading optimization in out-of-line functions #177

Open
cardillan opened this issue Nov 16, 2024 · 0 comments
Open

Bug: wrong jump threading optimization in out-of-line functions #177

cardillan opened this issue Nov 16, 2024 · 0 comments
Assignees
Labels
bug Something isn't working optimizer Related to the code optimizer

Comments

@cardillan
Copy link
Owner

Jump Threading optimizer is supposed to replace an unconditional jump to the function return instruction with the return instruction itself. There's a but that results in replacing conditional jump with the return instruction too. The bug only manifests in a non-inlined function that has several exit points, for example:

noinline def median(x1, x2, x3, x4, x5)
    y1 = min(x1, x2);
    y2 = max(x1, x2);
    y4 = min(x4, x5);
    y5 = max(x4, x5);

    if y4 < y1 then
        swap(out y1, out y4);
        swap(out y2, out y5);
    end;

    if x3 > y2 then
        y2 < y4 ? min(x3, y4) : min(y2, y5);
    else
        x3 > y4 ? min(x3, y5) : min(y2, y4);
    end;
end;

inline def swap(in out a, in out b)
    t = a; a = b; b = t;
end;

print(median(1,2,3,4,5));

This prints 2 instead of 3.

The bug probably doesn't manifest itself very often: the function needs to be non-inlined and sufficiently complex for the bug to occur.

As a workaround, setting Jump Threading to basic fixes the issue:

#set jump-threading=basic;

It might be better to keep it set until the fix is ready.

@cardillan cardillan added bug Something isn't working optimizer Related to the code optimizer labels Nov 16, 2024
@cardillan cardillan self-assigned this Nov 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working optimizer Related to the code optimizer
Projects
None yet
Development

No branches or pull requests

1 participant