-
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.
Going foward, we want to cast pre transformed records (for longs). So we need PreTransCast to avoid eagerly transforming the record. As a nice side effect, we see better receiver variable allocation: ```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 = ""; } ```
Since we have PreTransCast now, we do not need to push down casts to preserve aliases. No diff. Related: 6fd9322
This will become relevant, as we introduce casts for RuntimeLong. No diff (TODO: re-check)
This allows us to enable the IRChecker.
The first two commits are not strictly necessary. However, I felt they significantly help understanding of what the optimizer is doing.