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

Spilling mutable reg ptr arguments is hard #850

Open
eponier opened this issue Jun 26, 2024 · 1 comment
Open

Spilling mutable reg ptr arguments is hard #850

eponier opened this issue Jun 26, 2024 · 1 comment

Comments

@eponier
Copy link
Contributor

eponier commented Jun 26, 2024

I have a function fn f (reg ptr u8[N] r) -> reg ptr u8[N] that uses a lot of registers, so I want to spill the argument before the call and unspill it after the call.

stack ptr u8[N] s;
s = r;
r = f(r);
r = s;

But in this code, the region associated to variable s, and then to variable r is partial. I have to copy back r into s after the call. This spurious assignment will be removed by stack alloc, there is code dedicated to it.

stack ptr u8[N] s;
s = r;
r = f(r);
s = r; // new line
r = s;

This is accepted by the compiler, but does not do what I want at all. The first s = r is removed, since s is dead. Here is a solution.

stack ptr u8[N] s;
s = r;
r = f(r);
s[0:N] = r; // s is updated, not overwritten, so "s = r" will not be removed
r = s;

This works as expected, but is not so natural.

@eponier
Copy link
Contributor Author

eponier commented Jun 26, 2024

Note that there is a file testing this feature, namely tests/success/pointers/x86-64/test_spill_loop.jazz and it does not need the trick of using a subarray, but I think it is because of the while loop. The stack ptr is not dead and thus not removed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant