<?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>150777</bug_id>
          
          <creation_ts>2015-11-01 11:40:45 -0800</creation_ts>
          <short_desc>Consider still matching an address expression even if B3 has already assigned a Tmp to it</short_desc>
          <delta_ts>2015-12-10 19:42:31 -0800</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>All</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          <blocked>152106</blocked>
    
    <blocked>150279</blocked>
          <everconfirmed>1</everconfirmed>
          <reporter name="Filip Pizlo">fpizlo</reporter>
          <assigned_to name="Filip Pizlo">fpizlo</assigned_to>
          <cc>barraclough</cc>
    
    <cc>benjamin</cc>
    
    <cc>commit-queue</cc>
    
    <cc>ggaren</cc>
    
    <cc>keith_miller</cc>
    
    <cc>mark.lam</cc>
    
    <cc>mhahnenb</cc>
    
    <cc>msaboff</cc>
    
    <cc>nrotem</cc>
    
    <cc>oliver</cc>
    
    <cc>saam</cc>
    
    <cc>sam</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1138335</commentid>
    <comment_count>0</comment_count>
    <who name="Filip Pizlo">fpizlo</who>
    <bug_when>2015-11-01 11:40:45 -0800</bug_when>
    <thetext>Probably if we want to do hoisting of address expressions, we should have some better heuristics for it.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1148215</commentid>
    <comment_count>1</comment_count>
      <attachid>267111</attachid>
    <who name="Filip Pizlo">fpizlo</who>
    <bug_when>2015-12-10 09:16:24 -0800</bug_when>
    <thetext>Created attachment 267111
the patch</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1148311</commentid>
    <comment_count>2</comment_count>
      <attachid>267111</attachid>
    <who name="Geoffrey Garen">ggaren</who>
    <bug_when>2015-12-10 15:34:51 -0800</bug_when>
    <thetext>Comment on attachment 267111
the patch

I would have guessed 2.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1148385</commentid>
    <comment_count>3</comment_count>
    <who name="Filip Pizlo">fpizlo</who>
    <bug_when>2015-12-10 18:44:29 -0800</bug_when>
    <thetext>(In reply to comment #2)
&gt; Comment on attachment 267111 [details]
&gt; the patch
&gt; 
&gt; I would have guessed 2.

Depends on the architecture and a lot of other things.

On Intel, any address expression takes 1 cycle, regardless of its complexity.  So if you do this:

mov (%rax), %rax

then you will spend 1 cycle deducing that the address is simply the thing in %rax.  And if you do this:

mov 42(%rcx,%rdx,4), %rax

then you will also spend 1 cycle deducing what the address is.  Therefore, if you had to pick between the following two snippets, you would pick the one with fewer instructions even though it computes the same address twice:

This is faster:
    mov 42(%rcx,%rdx,4), %rax
    mov 46(%rcx,%rdx,4), %rdi

than this:
    lea 42(%rcx,%rdx,4), %rsi
    mov (%rsi), %rax
    mov 4(%rsi), %rdi

This would still be true even if the address expressions were identical rather than the second one being offset by +4. The first version is faster because even though we recompute the same seemingly complex address expression, it&apos;s actually free to do so.

Hence, setting the threshold to 2 is probably not a good thing.  It&apos;s far too low.  The last time I wrote a compiler, I set the threshold to +Inf.  Later on, I learned through whispers in the wind that you want to have some kind of upper limit, though I never learned the reason.  I suspect that the reason is just registers.  It&apos;s possible that in the &quot;faster&quot; example above, keeping %rcx and %rdx alive causes too much register pressure.  You don&apos;t know if that&apos;s an issue at the time that you do instruction selection, and usually it won&apos;t be an issue.  But you can see how if you really had a lot of uses of the same address, then the second form may be better because it requires only one register to be alive for the memory access to compute the address.

So, 2 is probably too low because it adds instructions without reducing the amount of work, but +Inf is probably too high because at some point the register pressure of keeping all of the inputs to the address computation alive is a bigger issue than the cost of the &quot;lea&quot; instruction.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1148407</commentid>
    <comment_count>4</comment_count>
    <who name="Filip Pizlo">fpizlo</who>
    <bug_when>2015-12-10 19:42:31 -0800</bug_when>
    <thetext>Landed in http://trac.webkit.org/changeset/193941</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>267111</attachid>
            <date>2015-12-10 09:16:24 -0800</date>
            <delta_ts>2015-12-10 15:34:51 -0800</delta_ts>
            <desc>the patch</desc>
            <filename>blah.patch</filename>
            <type>text/plain</type>
            <size>2547</size>
            <attacher name="Filip Pizlo">fpizlo</attacher>
            
              <data encoding="base64">SW5kZXg6IFNvdXJjZS9KYXZhU2NyaXB0Q29yZS9DaGFuZ2VMb2cKPT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PQotLS0gU291
cmNlL0phdmFTY3JpcHRDb3JlL0NoYW5nZUxvZwkocmV2aXNpb24gMTkzOTA5KQorKysgU291cmNl
L0phdmFTY3JpcHRDb3JlL0NoYW5nZUxvZwkod29ya2luZyBjb3B5KQpAQCAtMSwzICsxLDI1IEBA
CisyMDE1LTEyLTEwICBGaWxpcCBQaXpsbyAgPGZwaXpsb0BhcHBsZS5jb20+CisKKyAgICAgICAg
Q29uc2lkZXIgc3RpbGwgbWF0Y2hpbmcgYW4gYWRkcmVzcyBleHByZXNzaW9uIGV2ZW4gaWYgQjMg
aGFzIGFscmVhZHkgYXNzaWduZWQgYSBUbXAgdG8gaXQKKyAgICAgICAgaHR0cHM6Ly9idWdzLndl
YmtpdC5vcmcvc2hvd19idWcuY2dpP2lkPTE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cgYW4gYWRkcmVzcyBleHBy
ZXNzaW9uIGV2ZW4gaWYgd2UndmUgYWxyZWFkeSBhc3NpZ25lZCBhCi0gICAgICAgIC8vIFRtcCB0
byBpdC4gaHR0cHM6Ly9idWdzLndlYmtpdC5vcmcvc2hvd19idWcuY2dpP2lkPTE1MDc3NwotICAg
ICAgICBpZiAobV92YWx1ZVRvVG1wW2FkZHJlc3NdKQorICAgICAgICBzdGF0aWMgY29uc3QgdW5z
aWduZWQgbG90c09mVXNlcyA9IDEwOyAvLyBUaGlzIGlzIGFyYml0cmFyeSBhbmQgd2Ugc2hvdWxk
IHR1bmUgaXQgZXZlbnR1YWxseS4KKyAgICAgICAgCisgICAgICAgIC8vIE9ubHkgbWF0Y2ggaWYg
dGhlIGFkZHJlc3MgdmFsdWUgaXNuJ3QgdXNlZCBpbiBzb21lIGxhcmdlIG51bWJlciBvZiBwbGFj
ZXMuCisgICAgICAgIGlmIChtX3VzZUNvdW50cy5udW1Vc2VzKGFkZHJlc3MpID4gbG90c09mVXNl
cykKICAgICAgICAgICAgIHJldHVybiBBcmc6OmFkZHIodG1wKGFkZHJlc3MpKTsKICAgICAgICAg
CiAgICAgICAgIHN3aXRjaCAoYWRkcmVzcy0+b3Bjb2RlKCkpIHsK
</data>
<flag name="review"
          id="292149"
          type_id="1"
          status="+"
          setter="ggaren"
    />
          </attachment>
      

    </bug>

</bugzilla>