Last Comment Bug 780052 - IonMonkey: Handle some multi-type comparisons without CompareV.
: IonMonkey: Handle some multi-type comparisons without CompareV.
Status: RESOLVED FIXED
[ion:t]
:
Product: Core
Classification: Components
Component: JavaScript Engine (show other bugs)
: unspecified
: All All
: -- normal (vote)
: ---
Assigned To: general
:
Mentors:
Depends on:
Blocks: 777583 796114
  Show dependency treegraph
 
Reported: 2012-08-02 17:54 PDT by Sean Stangl [:sstangl]
Modified: 2012-10-01 13:45 PDT (History)
2 users (show)
See Also:
Crash Signature:
(edit)
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---


Attachments
patch (2.52 KB, patch)
2012-08-06 17:05 PDT, Sean Stangl [:sstangl]
jdemooij: review+
Details | Diff | Splinter Review

Description Sean Stangl [:sstangl] 2012-08-02 17:54:22 PDT
In 3d-raytrace, Triangle.prototype.intersect() and Scene.prototype.intersect() both take arguments that are double|undefined and used only in comparisons. The latter function calls the former in a tight loop, and then includes more such comparisons on top.

We should at least be able to handle (Double, Value) comparisons with the TypeSet case of a single (matching?) type and Undefined.

`perf` shows about 10% of execution in the expanded benchmark from Bug 777583 is spent in ion::GreaterThan and ion::LessThan.
Comment 1 Sean Stangl [:sstangl] 2012-08-06 17:05:30 PDT
Created attachment 649483 [details] [diff] [review]
patch

Handles the (Double, Double|Undefined) case by coercing the Undefined to NaN. This is more work than propagating false based on a typecheck, but easier to implement.

On x86_64, the raytrace benchmark from Bug 777583 goes from 800 -> 600ms.
The actual raytrace benchmark goes from about 28 -> 27ms; the difference is small but noticeable.
Comment 2 David Anderson [:dvander] 2012-08-06 18:36:06 PDT
Comment on attachment 649483 [details] [diff] [review]
patch

Flipping review to Jan since I think he's more familiar with the comparison path now.
Comment 3 Jan de Mooij [:jandem] 2012-08-07 11:10:14 PDT
Comment on attachment 649483 [details] [diff] [review]
patch

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

::: js/src/ion/MIR.cpp
@@ +981,5 @@
>      }
> +
> +    // Handle double comparisons against something that safely coerces to double.
> +    if (jsop() != JSOP_STRICTEQ && jsop() != JSOP_STRICTNE && lhs == MIRType_Double) {
> +        types::TypeFlags flags = b.rhsTypes->baseFlags();

Nit: JS_ASSERT(jsop() == JSOP_EQ || jsop() == JSOP_NE);

@@ +984,5 @@
> +    if (jsop() != JSOP_STRICTEQ && jsop() != JSOP_STRICTNE && lhs == MIRType_Double) {
> +        types::TypeFlags flags = b.rhsTypes->baseFlags();
> +
> +        // Strings are unhandled -- visitToDouble() doesn't support them yet.
> +        types::TypeFlags converts = types::TYPE_FLAG_NULL  | types::TYPE_FLAG_UNDEFINED |

ToDouble(null) is 0, but "0 == null" should be false.

@@ +988,5 @@
> +        types::TypeFlags converts = types::TYPE_FLAG_NULL  | types::TYPE_FLAG_UNDEFINED |
> +                                    types::TYPE_FLAG_INT32 | types::TYPE_FLAG_BOOLEAN |
> +                                    types::TYPE_FLAG_DOUBLE;
> +
> +        // If rhs can be safely coerced to a Double.

Can we factor this check out to a helper function and also handle the rhs == MIRType_Double case? The RHS is often constant (x == 1.2) so it could help to support mixed lhs types there too.
Comment 4 Sean Stangl [:sstangl] 2012-08-07 14:24:34 PDT
http://hg.mozilla.org/projects/ionmonkey/rev/f5c5445e826b

Note You need to log in before you can comment on or make changes to this bug.