jasmin icon indicating copy to clipboard operation
jasmin copied to clipboard

protect prevents unspill

Open Rixxc opened this issue 1 year ago • 1 comments

Hello, I have the following (boiled down) example code:

export fn main() -> reg u64 {
    reg u64 t t2;
    reg u64 msf;
    reg bool c;

    msf = #init_msf();

    () = #spill(t);

    c = t == 0;
    if (c) {
        msf = #update_msf(c, msf);
        t = #protect(t, msf);
        t2 = (u64)[t];
    }

    () = #unspill(t);

    reg u64 ret;
    ret = 0;
    return ret;
}

This fails with the following error:

"test.jazz", line 17 (4-21):
compilation error in function main:
lower spilling instructions:
The variable t (defined at "test.jazz", line 2 (12-13))
needs to be spilled before (maybe the variable has been written since the last spill)

This is caused by the assignment due to the #protect expression.

I think there should be an exception for assignments with #protect, since they do not change the contents of the variable, to allow this code to compile.

Rixxc avatar Oct 18 '24 11:10 Rixxc

First, your program is unsafe : you use t before initialising it. Second the if set the value of t (invalidating its spilled value). This explain the error (and it is exactly said in the error message)

bgregoir avatar Oct 18 '24 12:10 bgregoir

Closing this as the discussion seems to have reached its conclusion.

vbgl avatar Aug 22 '25 08:08 vbgl