Closed Bug 1122723 Opened 9 years ago Closed 9 years ago

IonMonkey: Fold MConcat with the empty string

Categories

(Core :: JavaScript Engine, defect)

x86_64
Linux
defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla38

People

(Reporter: sstangl, Assigned: sstangl)

Details

Attachments

(1 file)

Super-simple patch. Shumway occasionally uses ""+x to induce ToString(x). This eliminates the concat operation.
Attached patch patchSplinter Review
Attachment #8550491 - Flags: review?(hv1989)
Comment on attachment 8550491 [details] [diff] [review]
patch

Review of attachment 8550491 [details] [diff] [review]:
-----------------------------------------------------------------

Good find.
Attachment #8550491 - Flags: review?(hv1989) → review+
> Good find.

Indeed. It's also surprising we didn't encounter this in other hot code: it's one of the standard ways of coercing to string in JS, after all.
> Shumway occasionally uses ""+x to induce ToString(x).

The two operations are not identical when |x| is an object without the default "valueOf" function property.  I skimmed the JITs a bit -- do we "handle" this by making MConcat use ConvertToStringPolicy, which boxes objects into values, then having it bail if the resulting value is ever an object at runtime?  That's desperately unclear from cursory examination of the code -- could we add comments "somewhere" to clarify string concatenation as being safe to use ToString, even tho according to spec it's not?
(In reply to Jeff Walden [:Waldo] (remove +bmo to email) from comment #5)
> I skimmed the JITs a bit -- do we "handle" this by making MConcat use
> ConvertToStringPolicy, which boxes objects into values, then having it bail
> if the resulting value is ever an object at runtime?

MConcat uses ConvertToStringPolicy for both arguments (MIR.h:6086), which wraps non-MIRType_String inputs with MToString (TypePolicy.cpp:398).

MToString uses a ToStringPolicy. ToStringPolicy::staticAdjustInputs() replaces incoming MIRType_Object inputs with MBox(MIRType_Object) (TypePolicy.cpp:687).
 
visitToString() then lowers MIRType_Value input to LValueToString. visitValueToString() then emits bail code for the MIRType_Object case (CodeGenerator.cpp:929).

Yeah comments would probably be nice.
https://hg.mozilla.org/mozilla-central/rev/65151ac03846
Assignee: nobody → sstangl
Status: NEW → RESOLVED
Closed: 9 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla38
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: