8000 Enable the IR checker post optimizer with RT longs by gzm0 · Pull Request #5077 · scala-js/scala-js · GitHub
[go: up one dir, main page]

Skip to content

Enable the IR checker post optimizer with RT longs #5077

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

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

gzm0
Copy link
Contributor
@gzm0 gzm0 commented Nov 17, 2024

The first two commits are not strictly necessary. However, I felt they significantly help understanding of what the optimizer is doing.

@gzm0 gzm0 force-pushed the ir-check-long branch 2 times, most recently from c527a00 to 256a2f4 Compare November 24, 2024 09:26
@gzm0
Copy link
Contributor Author
gzm0 commented Nov 24, 2024

It looks like the change in subtyping checks (3rd commit) causes long literals to become allocated as RT long:

 $c_jl_Math$.prototype.multiplyExact__J__J__J = (function(a, b) {
   var ahi = b.RTLong__f_hi;
   if (((ahi === 0) ? (b.RTLong__f_lo !== 0) : (ahi > 0))) {
-    var this$1 = $m_RTLong$();
-    var lo = this$1.divideImpl__I__I__I__I__I((-1), 2147483647, b.RTLong__f_lo, b.RTLong__f_hi);
-    var hi = this$1.RTLong$__f_org$scalajs$linker$runtime$RuntimeLong$$hiReturn;
+    var this$1 = new $c_RTLong((-1), 2147483647);
+    var this$2 = $m_RTLong$();
+    var lo = this$2.divideImpl__I__I__I__I__I(this$1.RTLong__f_lo, this$1.RTLong__f_hi, b.RTLong__f_lo, b.RTLong__f_hi);
+    var hi = this$2.RTLong$__f_org$scalajs$linker$runtime$RuntimeLong$$hiReturn;
     var ahi$1 = a.RTLong__f_hi;
     if (((ahi$1 === hi) ? (((-2147483648) ^ a.RTLong__f_lo) > ((-2147483648) ^ lo)) : (ahi$1 > hi))) {
       var overflow = true;

I'm trying to identify where the "offending" subtyping check is in the optimizer.

@gzm0
Copy link
Contributor Author
gzm0 commented Nov 30, 2024

I have not gotten to a conclusion here yet. But it seems the issue is due to casts inserted on the receiver when inlining method calls: We need these when, say, calling + on a literal long for the IR to be correctly typed. OTOH, inserting them (which is what the 3rd commit causes) prevents farther inlining and folding of runtime long methods.

gzm0 added 4 commits January 19, 2025 15:24
To enable the IRChecker, we only want to consider RuntimeLong
equivalent to BoxedLong when we'll end up removing that type
information from the IR. In practice, this is during instance checks.
To keep the IR checker happy, we insert casts at method boundaries
that cast RuntimeLongs back to LongType.

The first two commits in this PR are not strictly necessary. However,
I felt they significantly help understanding of what the optimizer is
doing.
@gzm0
Copy link
Contributor Author
gzm0 commented Jan 19, 2025

I have managed to fix the execution tests: the claim that we never do an isInstance check on RT long was wrong: RT long itself does one in its equals method. As a result, when inlining x.equals(y) with longs, the compiler generated wrong folded constants.

I have not figured out yet what causes long literals to be stack allocated rather than inlined like before.

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
0