<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>198253</bug_id>
          
          <creation_ts>2019-05-25 20:30:02 -0700</creation_ts>
          <short_desc>[JSC] ResultType implementation is wrong for bit ops, and ends up making ArithDiv take the DFG Int32 fast path even if Baseline constantly produces Double result</short_desc>
          <delta_ts>2019-09-10 15:08:18 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>JavaScriptCore</component>
          <version>WebKit Nightly Build</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Yusuke Suzuki">ysuzuki</reporter>
          <assigned_to name="Yusuke Suzuki">ysuzuki</assigned_to>
          <cc>ews-watchlist</cc>
    
    <cc>keith_miller</cc>
    
    <cc>mark.lam</cc>
    
    <cc>msaboff</cc>
    
    <cc>saam</cc>
    
    <cc>tzagallo</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1539238</commentid>
    <comment_count>0</comment_count>
    <who name="Yusuke Suzuki">ysuzuki</who>
    <bug_when>2019-05-25 20:30:02 -0700</bug_when>
    <thetext>It causes unnecessary OSRExit in async-fs Math.random code.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1569488</commentid>
    <comment_count>1</comment_count>
      <attachid>378452</attachid>
    <who name="Yusuke Suzuki">ysuzuki</who>
    <bug_when>2019-09-10 03:30:57 -0700</bug_when>
    <thetext>Created attachment 378452
Patch</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1569524</commentid>
    <comment_count>2</comment_count>
      <attachid>378452</attachid>
    <who name="Mark Lam">mark.lam</who>
    <bug_when>2019-09-10 07:04:31 -0700</bug_when>
    <thetext>Comment on attachment 378452
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=378452&amp;action=review

I think this is the wrong place to do this fix.  This method says bigIntOrInt32Type().  It&apos;s misleading to have it also return TypeMaybeNumber.  The real issue is in forBitOp(), which happens to be the only client of this method.  I think we should just do the fix in forBitOp() and remove bigIntOrInt32Type().  Alternatively, rename bigIntOrInt32Type() to bigIntOrInt32TypeOrNumber() if you think there will be other clients of it coing soon.

&gt; Source/JavaScriptCore/ChangeLog:3
&gt; +        [JSC] ResultType implementation is wrong for bit ops, and ends up making ArithDiv in DFG Int32 fast path even if Baseline constantly produces Double result

I suggest rephrasing as &quot;making ArithDiv take the DFG Int32 fast path&quot;.

&gt; Source/JavaScriptCore/ChangeLog:8
&gt; +        ResultType of bitwise operation needs including TypeMaybeNumber. TypeInt32 is something like a flag indicating the number looks like a int32.

I suggest rephrasing as &quot;needs to include TypeMaybeNumber&quot;.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1569586</commentid>
    <comment_count>3</comment_count>
    <who name="Yusuke Suzuki">ysuzuki</who>
    <bug_when>2019-09-10 10:40:04 -0700</bug_when>
    <thetext>(In reply to Mark Lam from comment #2)
&gt; Comment on attachment 378452 [details]
&gt; Patch
&gt; 
&gt; View in context:
&gt; https://bugs.webkit.org/attachment.cgi?id=378452&amp;action=review
&gt; 
&gt; I think this is the wrong place to do this fix.  This method says
&gt; bigIntOrInt32Type().  It&apos;s misleading to have it also return
&gt; TypeMaybeNumber.  The real issue is in forBitOp(), which happens to be the
&gt; only client of this method.  I think we should just do the fix in forBitOp()
&gt; and remove bigIntOrInt32Type().  Alternatively, rename bigIntOrInt32Type()
&gt; to bigIntOrInt32TypeOrNumber() if you think there will be other clients of
&gt; it coing soon.

The name of flags in ResultType is misleading, but TypeInt32 and the other flags are not the same meaning. And TypeInt32 is not even in a type&apos;s set. We can see the definition of TypeBits does not include TypeInt32.

static constexpr Type TypeBits = TypeMaybeNumber | TypeMaybeString | TypeMaybeBigInt | TypeMaybeNull | TypeMaybeBool | TypeMaybeOther;

This is because TypeInt32 is a bit special boolean flag while other ones are entry of type set. So logically, ResultType is something like this.

struct ResultType {
    bool m_looksInt32;
    Set&lt;Type&gt; m_maybeTypes;
};

We are using bit set just to encode ResultType in bytecode as an int.
So, bigIntOrInt32Type definition right now is wrong since it is saying,

&quot;It is definitely BigInt, and looks Int32&quot;.

This patch adds TypeMaybeNumber to this type set to correct the maybe-types of Bitwise operations.

&gt; 
&gt; &gt; Source/JavaScriptCore/ChangeLog:3
&gt; &gt; +        [JSC] ResultType implementation is wrong for bit ops, and ends up making ArithDiv in DFG Int32 fast path even if Baseline constantly produces Double result
&gt; 
&gt; I suggest rephrasing as &quot;making ArithDiv take the DFG Int32 fast path&quot;.
&gt; 
&gt; &gt; Source/JavaScriptCore/ChangeLog:8
&gt; &gt; +        ResultType of bitwise operation needs including TypeMaybeNumber. TypeInt32 is something like a flag indicating the number looks like a int32.
&gt; 
&gt; I suggest rephrasing as &quot;needs to include TypeMaybeNumber&quot;.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1569680</commentid>
    <comment_count>4</comment_count>
    <who name="Mark Lam">mark.lam</who>
    <bug_when>2019-09-10 14:53:03 -0700</bug_when>
    <thetext>(In reply to Yusuke Suzuki from comment #3)
&gt; (In reply to Mark Lam from comment #2)
&gt; &gt; Comment on attachment 378452 [details]
&gt; &gt; Patch
&gt; &gt; 
&gt; &gt; View in context:
&gt; &gt; https://bugs.webkit.org/attachment.cgi?id=378452&amp;action=review
&gt; &gt; 
&gt; &gt; I think this is the wrong place to do this fix.  This method says
&gt; &gt; bigIntOrInt32Type().  It&apos;s misleading to have it also return
&gt; &gt; TypeMaybeNumber.  The real issue is in forBitOp(), which happens to be the
&gt; &gt; only client of this method.  I think we should just do the fix in forBitOp()
&gt; &gt; and remove bigIntOrInt32Type().  Alternatively, rename bigIntOrInt32Type()
&gt; &gt; to bigIntOrInt32TypeOrNumber() if you think there will be other clients of
&gt; &gt; it coing soon.
&gt; 
&gt; The name of flags in ResultType is misleading, but TypeInt32 and the other
&gt; flags are not the same meaning. And TypeInt32 is not even in a type&apos;s set.
&gt; We can see the definition of TypeBits does not include TypeInt32.
&gt; 
&gt; static constexpr Type TypeBits = TypeMaybeNumber | TypeMaybeString |
&gt; TypeMaybeBigInt | TypeMaybeNull | TypeMaybeBool | TypeMaybeOther;
&gt; 
&gt; This is because TypeInt32 is a bit special boolean flag while other ones are
&gt; entry of type set. So logically, ResultType is something like this.
&gt; 
&gt; struct ResultType {
&gt;     bool m_looksInt32;
&gt;     Set&lt;Type&gt; m_maybeTypes;
&gt; };
&gt; 
&gt; We are using bit set just to encode ResultType in bytecode as an int.
&gt; So, bigIntOrInt32Type definition right now is wrong since it is saying,
&gt; 
&gt; &quot;It is definitely BigInt, and looks Int32&quot;.
&gt; 
&gt; This patch adds TypeMaybeNumber to this type set to correct the maybe-types
&gt; of Bitwise operations.

So hokey.  Thanks for explaining it.  We should probably do some renaming here, or maybe rethink how to express these concepts.  Using an enum class would be improvement too for grepability.  But all that can be done later.  I&apos;ll r+ this patch.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1569681</commentid>
    <comment_count>5</comment_count>
      <attachid>378452</attachid>
    <who name="Mark Lam">mark.lam</who>
    <bug_when>2019-09-10 14:53:55 -0700</bug_when>
    <thetext>Comment on attachment 378452
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=378452&amp;action=review

r=me

&gt; Source/JavaScriptCore/parser/ResultType.h:151
&gt; +            return ResultType(TypeMaybeBigInt | TypeInt32 | TypeMaybeNumber);

Should we remove the TypeInt32 since it&apos;s not needed, and it&apos;s suggesting the wrong idea here?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1569686</commentid>
    <comment_count>6</comment_count>
      <attachid>378452</attachid>
    <who name="Yusuke Suzuki">ysuzuki</who>
    <bug_when>2019-09-10 15:04:08 -0700</bug_when>
    <thetext>Comment on attachment 378452
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=378452&amp;action=review

&gt;&gt;&gt; Source/JavaScriptCore/ChangeLog:3
&gt;&gt;&gt; +        [JSC] ResultType implementation is wrong for bit ops, and ends up making ArithDiv in DFG Int32 fast path even if Baseline constantly produces Double result
&gt;&gt; 
&gt;&gt; I suggest rephrasing as &quot;making ArithDiv take the DFG Int32 fast path&quot;.
&gt; 
&gt; 

Fixed.

&gt;&gt; Source/JavaScriptCore/ChangeLog:8
&gt;&gt; +        ResultType of bitwise operation needs including TypeMaybeNumber. TypeInt32 is something like a flag indicating the number looks like a int32.
&gt; 
&gt; I suggest rephrasing as &quot;needs to include TypeMaybeNumber&quot;.

Fixed.

&gt;&gt; Source/JavaScriptCore/parser/ResultType.h:151
&gt;&gt; +            return ResultType(TypeMaybeBigInt | TypeInt32 | TypeMaybeNumber);
&gt; 
&gt; Should we remove the TypeInt32 since it&apos;s not needed, and it&apos;s suggesting the wrong idea here?

I think currently some code is using this TypeInt32 for preference of Int32 in Number representations.
I would like to consider this in a separate patch, and make this patch just a performance bug fix.
https://bugs.webkit.org/show_bug.cgi?id=201659 Filed.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1569687</commentid>
    <comment_count>7</comment_count>
    <who name="Yusuke Suzuki">ysuzuki</who>
    <bug_when>2019-09-10 15:07:17 -0700</bug_when>
    <thetext>Committed r249736: &lt;https://trac.webkit.org/changeset/249736&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1569688</commentid>
    <comment_count>8</comment_count>
      <attachid>378452</attachid>
    <who name="Mark Lam">mark.lam</who>
    <bug_when>2019-09-10 15:07:33 -0700</bug_when>
    <thetext>Comment on attachment 378452
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=378452&amp;action=review

&gt;&gt;&gt; Source/JavaScriptCore/parser/ResultType.h:151
&gt;&gt;&gt; +            return ResultType(TypeMaybeBigInt | TypeInt32 | TypeMaybeNumber);
&gt;&gt; 
&gt;&gt; Should we remove the TypeInt32 since it&apos;s not needed, and it&apos;s suggesting the wrong idea here?
&gt; 
&gt; I think currently some code is using this TypeInt32 for preference of Int32 in Number representations.
&gt; I would like to consider this in a separate patch, and make this patch just a performance bug fix.
&gt; https://bugs.webkit.org/show_bug.cgi?id=201659 Filed.

Sorry, I misread the encoding for TypeInt32.  It&apos;s 1.  I misread it as 0.  Yeah, I agree we can&apos;t remove it.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1569689</commentid>
    <comment_count>9</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2019-09-10 15:08:18 -0700</bug_when>
    <thetext>&lt;rdar://problem/55238761&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1569690</commentid>
    <comment_count>10</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2019-09-10 15:08:18 -0700</bug_when>
    <thetext>&lt;rdar://problem/55238760&gt;</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>378452</attachid>
            <date>2019-09-10 03:30:57 -0700</date>
            <delta_ts>2019-09-10 14:53:55 -0700</delta_ts>
            <desc>Patch</desc>
            <filename>bug-198253-20190910033056.patch</filename>
            <type>text/plain</type>
            <size>1963</size>
            <attacher name="Yusuke Suzuki">ysuzuki</attacher>
            
              <data encoding="base64">U3VidmVyc2lvbiBSZXZpc2lvbjogMjQ5NzA2CmRpZmYgLS1naXQgYS9Tb3VyY2UvSmF2YVNjcmlw
dENvcmUvQ2hhbmdlTG9nIGIvU291cmNlL0phdmFTY3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gQEAgbmFtZXNwYWNlIEpTQyB7CiAgICAgICAgIAogICAgICAgICBzdGF0aWMgY29u
c3RleHByIFJlc3VsdFR5cGUgYmlnSW50T3JJbnQzMlR5cGUoKQogICAgICAgICB7Ci0gICAgICAg
ICAgICByZXR1cm4gUmVzdWx0VHlwZShUeXBlTWF5YmVCaWdJbnQgfCBUeXBlSW50MzIpOworICAg
ICAgICAgICAgcmV0dXJuIFJlc3VsdFR5cGUoVHlwZU1heWJlQmlnSW50IHwgVHlwZUludDMyIHwg
VHlwZU1heWJlTnVtYmVyKTsKICAgICAgICAgfQogCiAgICAgICAgIHN0YXRpYyBjb25zdGV4cHIg
UmVzdWx0VHlwZSB1bmtub3duVHlwZSgpCg==
</data>
<flag name="review"
          id="394076"
          type_id="1"
          status="+"
          setter="mark.lam"
    />
          </attachment>
      

    </bug>

</bugzilla>