-
Notifications
You must be signed in to change notification settings - Fork 396
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
base: main
Are you sure you want to change the base?
Conversation
c527a00
to
256a2f4
Compare
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. |
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 |
I have managed to fix the execution tests: the claim that we never do an I have not figured out yet what causes long literals to be stack allocated rather than inlined like before. |
Discovered while working on scala-js#5077. This allows to remove unnecessary unboxes and unlocks more inlining.
```diff --- baseline.js 2025-06-07 09:56:18.846667192 +0200 +++ pre-trans-cast.js 2025-06-08 14:20:11.704783221 +0200 @@ -17540,8 +17540,7 @@ var logException = ((!$n($thiz.Lorg_scalajs_junit_Reporter__f_settings).Lorg_scalajs_junit_RunSettings__f_notLogExceptionClass) && ($n($thiz.Lorg_scalajs_junit_Reporter__f_settings).Lorg_scalajs_junit_RunSettings__f_logAssert || (!(t instanceof $c_jl_AssertionError)))); if (logException) { var this$1 = $n(t); - var this$2 = $objectGetClass(this$1); - var fmtName = ($p_Lorg_scalajs_junit_Reporter__formatClass__T__T__T($thiz, this$2.data.name, "\u001b[31m") + ": "); + var fmtName = ($p_Lorg_scalajs_junit_Reporter__formatClass__T__T__T($thiz, $objectClassName(this$1), "\u001b[31m") + ": "); } else { var fmtName = ""; } ```
No diff. Related: 6fd9322
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 constant folding of IsInstance nodes. ``` def incrementExact;J;J(a: long): long = { if ((a !=[long] 9223372036854775807L)) { (a +[long] ((long)1)) } else { throw new java.lang.ArithmeticException().<init>;Ljava.lang.String;V("Long overflow") } } ``` After this commit `(long)1` gets stack allocated.
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.
The first two commits are not strictly necessary. However, I felt they significantly help understanding of what the optimizer is doing.