Closed Bug 1028910 Opened 10 years ago Closed 10 years ago

IonMonkey: Improve type information at branches with MIsObject

Categories

(Core :: JavaScript Engine: JIT, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla33

People

(Reporter: h4writer, Assigned: eternalsushant)

References

Details

Attachments

(1 file, 2 obsolete files)

During IonBuilder we can improve type information at branches (very limited). Now we want to do this for "MIsObject". This is often/only used in selfhosting code, but quite important. Since in selfhosting the following code is used a lot:

if (IsObject(foo)) {
   // do something with foo
}

Currently TI will see all types of "foo" in the branch. We want to adjust it, so IonMonkey knows it will only see "objects" in the branch.

In bug 953164 there was some small framework landed to allow this for:
if (foo) {

}
Which filters undefined/null.

The idea is to use the same techniques to do this for MIsObject.
Depends on: 1021739
Assignee: nobody → eternalsushant
Till, what would be the best way to add tests for this? We want to be able to test JS code like:

if (IsObject(foo)) {
   // assertSomething
}

But the intrinsic IsObject is only defined in selfhosting code.
Flags: needinfo?(till)
You can get at functions defined in the self-hosting compartment by using `getSelfHostedValue` in the shell. I don't see a reason for not using that in tests.
Flags: needinfo?(till)
Attachment #8450012 - Flags: review?(hv1989)
Comment on attachment 8450012 [details] [diff] [review]
Improve type information for branching at MIsObject

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

Looks good. Most changes are only cosmetic.

::: js/src/jit/IonBuilder.cpp
@@ +3078,5 @@
> +    // then setTypeToObject is true. Similarly, if the instruction is !IsObject and
> +    // we're not in true branch.
> +    MDefinition *ins = test->getOperand(0);
> +    if (ins->isIsObject()) {
> +        if (trueBranch) {

You can move the "trueBranch" test also in the ins->isIsObject() test.

@@ +3084,5 @@
> +            subject = ins->getOperand(0);
> +        }
> +    }
> +    else if (!trueBranch && ins->isNot()) {
> +        if (ins->toNot()->getOperand(0)->isIsObject()) {

filtersUndefinedOrNull also has a ins->isNot() check. This will now not get executed.

So move the ...->isIsObject() into the "else if".

@@ +3103,5 @@
>  
>      // Only do this optimization if the typeset does contains null or undefined.
>      if ((!(removeUndefined && subject->resultTypeSet()->hasType(types::Type::UndefinedType())) &&
> +         !(removeNull && subject->resultTypeSet()->hasType(types::Type::NullType()))) &&
> +            (!setTypeToObject))

Remove the () around the setTypeToObject and remove some spaces to let it start at the same place as "if ((". So with the second "("  )

::: js/src/jsinfer.cpp
@@ +675,5 @@
>      return res;
>  }
>  
> +TemporaryTypeSet *
> +TypeSet::setToObject(LifoAlloc *alloc)

s/setToObject/cloneObjectsOnly/
Attachment #8450012 - Flags: review?(hv1989)
Attachment #8450012 - Attachment is obsolete: true
Attachment #8450032 - Flags: review?(hv1989)
Comment on attachment 8450032 [details] [diff] [review]
Improve type information for branching at MIsObject

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

::: js/src/jit/IonBuilder.cpp
@@ +3096,5 @@
>      // There is no TypeSet that can get filtered.
>      if (!subject->resultTypeSet() || subject->resultTypeSet()->unknown())
>          return true;
>  
>      // Only do this optimization if the typeset does contains null or undefined.

Oh I forgot this. Please update comment.
Attachment #8450032 - Flags: review?(hv1989) → review+
Attachment #8450032 - Attachment is obsolete: true
Attachment #8450043 - Flags: review?(hv1989)
Attachment #8450043 - Attachment is patch: true
Comment on attachment 8450043 [details] [diff] [review]
Improve type information for branching at MIsObject

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

::: js/src/jit/IonBuilder.cpp
@@ +3081,5 @@
> +    if (ins->isIsObject() && trueBranch) {
> +        setTypeToObject = true;
> +        subject = ins->getOperand(0);
> +    }
> +    else if (!trueBranch && ins->isNot() && ins->toNot()->getOperand(0)->isIsObject()) {

} else if () {
(so on the same line)

@@ +3086,5 @@
> +        setTypeToObject = true;
> +        subject = ins->getOperand(0)->getOperand(0);
> +    }
> +    else
> +        test->filtersUndefinedOrNull(trueBranch, &subject, &removeUndefined, &removeNull);

Or there are no {} or we add it to all cases. So this else case should have {}.

@@ +3097,5 @@
>      if (!subject->resultTypeSet() || subject->resultTypeSet()->unknown())
>          return true;
>  
> +    // Only do this optimization if the typeset does contains null or undefined
> +    // or if we're looking at an object(setTypeToObject is true).

Updated comment a bit.

@@ +3102,3 @@
>      if ((!(removeUndefined && subject->resultTypeSet()->hasType(types::Type::UndefinedType())) &&
> +         !(removeNull && subject->resultTypeSet()->hasType(types::Type::NullType()))) &&
> +        !setTypeToObject)

Only do this optimization when subject type isn't already MIRType_Object.
Attachment #8450043 - Flags: review?(hv1989) → review+
Addressed comments myself, so this could already land:
https://hg.mozilla.org/integration/mozilla-inbound/rev/3a3f72171ac4
https://hg.mozilla.org/mozilla-central/rev/3a3f72171ac4
Status: NEW → RESOLVED
Closed: 10 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla33
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: