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

Fix RLSRA for intervals of length 1 #53

Merged
merged 3 commits into from
Aug 16, 2024

Conversation

janvrany
Copy link
Owner

This commit fixes edge but entirely valid case of register live intervals of lenght 1 - for deeper explanation see a1b97f0.

Luckily this bug was caught by failing assertions. Lessons learned are: (i) always assert that all invariants you think hold actually hold and (ii) there's never enough assertions :-)

This commit changes the behavior of `TRILBuilder` w.r.t building calls.
Since calls (`icall`, `acall` and so on) are not treetops, they were
not added to the block. Therefore if the result of the call (return
value) was not used, the call was elided from built IL. This is wrong,
call may have side-effects so they must not be elided.

This commit changes the behavior of `TRILBuilder` so that each call is
automatically anchored using `treetop`. For example, following:

   builder istore: {
     builder icall: { 'get_some_int' } .
     'temp' }

used to produce:

   N002 istore 'temp'
   N001   icall 'get_some_int'

With this commit, it produces:

   N002 treetop
   N001   icall 'get_some_int'
   N003 istore 'temp'
   N001   ==> icall 'get_some_int'

If ever we really want to elide unnecessary calls (whateber that means)
it should be implemented as an optimization pass.
This strengthen invariant checking before proceeding to actual
allocation, namely:

 * checks that each virtual register is at least once defined
   (assigned) and
 * checks that each virtual register is used only after it is defined
   or not used at all.
Consider following - somewhat pathological - TRIL fragment:

    N...
    N004 treetop
    N003   iadd
    N001     iload 'x'
    N002     iload 'y'
    N...

such that the value of the `iadd` node (`N003`) is never used. The iadd
node is compiled to (say) something like:

    addi {vr003}, {vr001}, {vr002}

This instruction defines (assigns) a virtual register `{vr003}` but
since its value is never used, the interval for `{vr003}` of length 1
and such interval was *not* created by interval splitting.

Now consider even trickier example:

    N...
    N004 treetop
    N003   icall 'some_func'
    N...

such that value of the icall node (`N003`) is never used just like in
previous example (in other words: the code calls a function `some_func`
but does not use its return value - an entirely valid, if not common,
situation).
Here, the call instruction does define (say) virtual register `{vr003}`
by having a dependency of linkage-defined return register on `{vr003}`.
But since value of `{vr003}` is never used, there's no need to generate
register move from linkage-defined return register to `{vr003}`.

This commit fixes RLSRA for cases like these.
@janvrany janvrany merged commit 5562067 into master Aug 16, 2024
2 checks passed
@janvrany janvrany deleted the pr/fix-rlsra-for-intervals-of-length-1 branch August 16, 2024 10:48
@janvrany janvrany restored the pr/fix-rlsra-for-intervals-of-length-1 branch August 16, 2024 10:48
@janvrany janvrany deleted the pr/fix-rlsra-for-intervals-of-length-1 branch August 16, 2024 10:48
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

Successfully merging this pull request may close these issues.

1 participant