RESOLVED FIXED 151164
[JSC] Support Doubles with B3's Add
https://bugs.webkit.org/show_bug.cgi?id=151164
Summary [JSC] Support Doubles with B3's Add
Benjamin Poulain
Reported 2015-11-11 16:25:41 PST
[JSC] Support Doubles with B3's Add
Attachments
Patch (8.53 KB, patch)
2015-11-11 16:27 PST, Benjamin Poulain
no flags
Patch (10.12 KB, patch)
2015-11-11 18:43 PST, Benjamin Poulain
fpizlo: review+
Benjamin Poulain
Comment 1 2015-11-11 16:27:16 PST
Geoffrey Garen
Comment 2 2015-11-11 16:32:58 PST
Comment on attachment 265333 [details] Patch r=me
Filip Pizlo
Comment 3 2015-11-11 16:58:25 PST
Comment on attachment 265333 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=265333&action=review > Source/JavaScriptCore/b3/B3ReduceStrength.cpp:172 > + if (m_value->child(1)->isLikeZero()) { Does this do the right thing for -0?
Benjamin Poulain
Comment 4 2015-11-11 17:06:24 PST
(In reply to comment #3) > Comment on attachment 265333 [details] > Patch > > View in context: > https://bugs.webkit.org/attachment.cgi?id=265333&action=review > > > Source/JavaScriptCore/b3/B3ReduceStrength.cpp:172 > > + if (m_value->child(1)->isLikeZero()) { > > Does this do the right thing for -0? Yep :)
Filip Pizlo
Comment 5 2015-11-11 17:08:58 PST
(In reply to comment #4) > (In reply to comment #3) > > Comment on attachment 265333 [details] > > Patch > > > > View in context: > > https://bugs.webkit.org/attachment.cgi?id=265333&action=review > > > > > Source/JavaScriptCore/b3/B3ReduceStrength.cpp:172 > > > + if (m_value->child(1)->isLikeZero()) { > > > > Does this do the right thing for -0? > > Yep :) Can you add a comment about why? :-) For example, does isLikeZero return true for -0? Even if this was documented on the method, it would help to say this here. If it does work for -0, then it would be worth explaining why this handles both -0 and 0 as the other value. A table or something that explains this would help for example if we wanted to try to expand this optimization with some more sophisticated algebra.
Benjamin Poulain
Comment 6 2015-11-11 17:33:11 PST
(In reply to comment #5) > Can you add a comment about why? :-) > > For example, does isLikeZero return true for -0? Even if this was > documented on the method, it would help to say this here. If it does work > for -0, then it would be worth explaining why this handles both -0 and 0 as > the other value. A table or something that explains this would help for > example if we wanted to try to expand this optimization with some more > sophisticated algebra. If you prefer something more explicit, what do you think of: bool isZero() bool isZeroOrMinusZero() on Value?
Filip Pizlo
Comment 7 2015-11-11 17:40:12 PST
(In reply to comment #6) > (In reply to comment #5) > > Can you add a comment about why? :-) > > > > For example, does isLikeZero return true for -0? Even if this was > > documented on the method, it would help to say this here. If it does work > > for -0, then it would be worth explaining why this handles both -0 and 0 as > > the other value. A table or something that explains this would help for > > example if we wanted to try to expand this optimization with some more > > sophisticated algebra. > > If you prefer something more explicit, what do you think of: > bool isZero() > bool isZeroOrMinusZero() > on Value? I think that isLikeZero() essentially means -0, and I'm fine with the name. I believe that your optimization assumes that the following is true: 0 + 0 = 0 0 + -0 = 0 -0 + 0 = -0 -0 + -0 = -0 But I don't think that this is true. Here's what I found, in both jsc and lldb: 0 + 0 = 0 0 + -0 = 0 -0 + 0 = 0 -0 + -0 = -0 In other words, when child(1) is 0, this operation acts as a -0 clean-up filter, which is not the same as identity. When child(1) is -0 then it appears that this is indeed an identity. So, either your optimization is wrong, or you need some comments to describe why it's right. That comment should start with pointing out that this optimization applies to both 0 and -0, and you should explain why it behaves like identity in both cases.
Filip Pizlo
Comment 8 2015-11-11 17:40:38 PST
(In reply to comment #7) > (In reply to comment #6) > > (In reply to comment #5) > > > Can you add a comment about why? :-) > > > > > > For example, does isLikeZero return true for -0? Even if this was > > > documented on the method, it would help to say this here. If it does work > > > for -0, then it would be worth explaining why this handles both -0 and 0 as > > > the other value. A table or something that explains this would help for > > > example if we wanted to try to expand this optimization with some more > > > sophisticated algebra. > > > > If you prefer something more explicit, what do you think of: > > bool isZero() > > bool isZeroOrMinusZero() > > on Value? > > I think that isLikeZero() essentially means -0, and I'm fine with the name. *essentially means 0 or -0.
Benjamin Poulain
Comment 9 2015-11-11 17:57:07 PST
Comment on attachment 265333 [details] Patch Yeah, looks like I got that wrong. I just trusted the tests without much thinking.
Benjamin Poulain
Comment 10 2015-11-11 18:43:25 PST
Filip Pizlo
Comment 11 2015-11-11 18:46:22 PST
Comment on attachment 265345 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=265345&action=review > Source/JavaScriptCore/b3/B3ReduceStrength.cpp:172 > // Turn this: Add(value, zero) > // Into an Identity. > - if (m_value->child(1)->isInt(0)) { > + if (m_value->child(1)->isInt(0) || m_value->child(1)->isNegativeZero()) { It would be great to say in the comment why this only works for -0, so that somebody doesn't just assume this is a bug.
Benjamin Poulain
Comment 12 2015-11-11 21:12:17 PST
Note You need to log in before you can comment on or make changes to this bug.