<?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>151297</bug_id>
          
          <creation_ts>2015-11-15 12:05:17 -0800</creation_ts>
          <short_desc>64-bit in the DFG: non tail Calls unnecessarily store the argument count twice on the callee frame and tails calls unnecessarily store it once</short_desc>
          <delta_ts>2015-11-15 23:42:44 -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>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></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Saam Barati">saam</reporter>
          <assigned_to name="Saam Barati">saam</assigned_to>
          <cc>benjamin</cc>
    
    <cc>commit-queue</cc>
    
    <cc>fpizlo</cc>
    
    <cc>ggaren</cc>
    
    <cc>gskachkov</cc>
    
    <cc>keith_miller</cc>
    
    <cc>mark.lam</cc>
    
    <cc>msaboff</cc>
    
    <cc>oliver</cc>
    
    <cc>sukolsak</cc>
    
    <cc>ysuzuki</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1142127</commentid>
    <comment_count>0</comment_count>
    <who name="Saam Barati">saam</who>
    <bug_when>2015-11-15 12:05:17 -0800</bug_when>
    <thetext>We end up producing code like this:

      45:&lt;!1:loc6&gt;	Call(@42, @36, JS|MustGen|VarArgs|PureInt, Other, R:World, W:Heap, ExitsForExceptions, ClobbersExit, bc#33)  predicting Other
          0x24ab9c3ffd2c: mov $0x1, 0x10(%rsp)
          0x24ab9c3ffd34: mov $0x1, 0x10(%rsp)

Which is stupid.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1142128</commentid>
    <comment_count>1</comment_count>
      <attachid>265560</attachid>
    <who name="Saam Barati">saam</who>
    <bug_when>2015-11-15 12:36:35 -0800</bug_when>
    <thetext>Created attachment 265560
patch</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1142140</commentid>
    <comment_count>2</comment_count>
      <attachid>265560</attachid>
    <who name="Geoffrey Garen">ggaren</who>
    <bug_when>2015-11-15 15:31:47 -0800</bug_when>
    <thetext>Comment on attachment 265560
patch

r=me</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1142142</commentid>
    <comment_count>3</comment_count>
    <who name="Michael Saboff">msaboff</who>
    <bug_when>2015-11-15 16:20:34 -0800</bug_when>
    <thetext>This patch fixed the issue of setting the argument count twice.

We also needs to set the argument count when making a tail call.  If we aren&apos;t, then file a bug.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1142144</commentid>
    <comment_count>4</comment_count>
    <who name="Saam Barati">saam</who>
    <bug_when>2015-11-15 17:05:19 -0800</bug_when>
    <thetext>(In reply to comment #3)
&gt; This patch fixed the issue of setting the argument count twice.
&gt; 
&gt; We also needs to set the argument count when making a tail call.  If we
&gt; aren&apos;t, then file a bug.

We should be setting it on the caller&apos;s call frame, right?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1142145</commentid>
    <comment_count>5</comment_count>
    <who name="Saam Barati">saam</who>
    <bug_when>2015-11-15 17:15:36 -0800</bug_when>
    <thetext>It looks like it&apos;s being set:
```      49:&lt;!0:-&gt;	TailCall(@28, @23, @31, @34, @37, @40, @43, MustGen|VarArgs, R:World, W:SideState, Exits, bc#36)
          0x2268c3e00287: mov $0x10d4685b0, %rcx
          0x2268c3e00291: mov $0x0, 0x24(%rbp)
          0x2268c3e00298: mov $0x0, %r11
          0x2268c3e002a2: cmp %r11, %rcx
          0x2268c3e002a5: jnz 0x2268c3e00362
          0x2268c3e002ab: mov 0x20(%rbp), %edi
          0x2268c3e002ae: cmp $0x4, %edi
          0x2268c3e002b1: jbe 0x2268c3e002c8
          0x2268c3e002b7: add $0x6, %edi
          0x2268c3e002ba: and $0xfffffffe, %edi
          0x2268c3e002bd: imul $0x8, %edi, %edi
          0x2268c3e002c3: jmp 0x2268c3e002cd
          0x2268c3e002c8: mov $0x50, %edi
          0x2268c3e002cd: add %rbp, %rdi
          0x2268c3e002d0: sub $0x58, %rdi
          0x2268c3e002d4: mov 0x0(%rbp), %rbp
          0x2268c3e002d8: mov $0x10d43f700, %r11
          0x2268c3e002e2: mov %r11, 0x20(%rdi)
          0x2268c3e002e6: mov %rax, 0x28(%rdi)
          0x2268c3e002ea: mov %rsi, 0x30(%rdi)
          0x2268c3e002ee: mov %rdx, 0x38(%rdi)
          0x2268c3e002f2: mov $0xffff00000000001e, %r11
          0x2268c3e002fc: mov %r11, 0x40(%rdi)
          0x2268c3e00300: mov $0xffff000000000028, %r11
          0x2268c3e0030a: mov %r11, 0x48(%rdi)
          0x2268c3e0030e: movsd 0xb8(%rsp), %xmm0
          0x2268c3e00317: mov %rcx, 0x10(%rdi)
          0x2268c3e0031b: mov 0xa8(%rsp), %r15
          0x2268c3e00323: movsd %xmm0, (%rdi)
          0x2268c3e00327: mov 0x88(%rsp), %rbx
          0x2268c3e0032f: mov 0x90(%rsp), %r12
          0x2268c3e00337: mov 0x98(%rsp), %r13
          0x2268c3e0033f: mov 0xa0(%rsp), %r14
          0x2268c3e00347: mov $0x0, 0x1c(%rdi)
          0x2268c3e0034e: mov $0x6, 0x18(%rdi)
          0x2268c3e00355: mov %rdi, %rsp
          0x2268c3e00358: jmp 0x2268c3e0035d
          0x2268c3e0035d: jmp 0x2268c3e003d9
          0x2268c3e00362: mov $0x10d43f700, %r11
          0x2268c3e0036c: mov %r11, 0x18(%rsp)
          0x2268c3e00371: mov %rax, 0x20(%rsp)
          0x2268c3e00376: mov %rsi, 0x28(%rsp)
          0x2268c3e0037b: mov %rdx, 0x30(%rsp)
          0x2268c3e00380: mov $0xffff00000000001e, %r11
          0x2268c3e0038a: mov %r11, 0x38(%rsp)
          0x2268c3e0038f: mov $0xffff000000000028, %r11
          0x2268c3e00399: mov %r11, 0x40(%rsp)
          0x2268c3e0039e: mov %rcx, 0x8(%rsp)
          0x2268c3e003a3: mov -0x28(%rbp), %rbx
          0x2268c3e003a7: mov -0x20(%rbp), %r12
          0x2268c3e003ab: mov -0x18(%rbp), %r13
          0x2268c3e003af: mov -0x10(%rbp), %r14
          0x2268c3e003b3: mov -0x8(%rbp), %r15
          0x2268c3e003b7: mov $0x0, 0x14(%rsp)
          0x2268c3e003bf: mov $0x6, 0x10(%rsp)
          0x2268c3e003c7: mov %rcx, %rax
          0x2268c3e003ca: mov $0x10d7c7f80, %rdx
          0x2268c3e003d4: call 0x226883e01c60
          0x2268c3e003d9: mov $0xed, %r11d
          0x2268c3e003df: int3 
```
which is from this program:
```
&quot;use strict&quot;;

function bar() {}
noInline(bar);

function foo(a, b, c) {
    return bar(a, b, c, 30, 40);
}
noInline(foo);
for (let i = 0; i &lt; 1000; i++)
    foo(true, true, 10);
```

Maybe the call frame shuffler takes care of setting the argument count?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1142146</commentid>
    <comment_count>6</comment_count>
    <who name="Saam Barati">saam</who>
    <bug_when>2015-11-15 17:16:40 -0800</bug_when>
    <thetext>To clarify what I mean in the bug title:
When I say tail calls don&apos;t need to set the argument count,
I mean they don&apos;t need to set it for a &quot;callee&quot; they&apos;re setting up,
tail calls need to set it on the frame they&apos;re reusing.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1142170</commentid>
    <comment_count>7</comment_count>
      <attachid>265560</attachid>
    <who name="WebKit Commit Bot">commit-queue</who>
    <bug_when>2015-11-15 23:42:39 -0800</bug_when>
    <thetext>Comment on attachment 265560
patch

Clearing flags on attachment: 265560

Committed r192465: &lt;http://trac.webkit.org/changeset/192465&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1142171</commentid>
    <comment_count>8</comment_count>
    <who name="WebKit Commit Bot">commit-queue</who>
    <bug_when>2015-11-15 23:42:44 -0800</bug_when>
    <thetext>All reviewed patches have been landed.  Closing bug.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>265560</attachid>
            <date>2015-11-15 12:36:35 -0800</date>
            <delta_ts>2015-11-15 23:42:39 -0800</delta_ts>
            <desc>patch</desc>
            <filename>a-backup.diff</filename>
            <type>text/plain</type>
            <size>1683</size>
            <attacher name="Saam Barati">saam</attacher>
            
              <data encoding="base64">SW5kZXg6IFNvdXJjZS9KYXZhU2NyaXB0Q29yZS9DaGFuZ2VMb2cKPT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PQotLS0gU291
cmNlL0phdmFTY3JpcHRDb3JlL0NoYW5nZUxvZwkocmV2aXNpb24gMTkyNDYzKQorKysgU291cmNl
L0phdmFTY3JpcHRDb3JlL0NoYW5nZUxvZwkod29ya2luZyBjb3B5KQpAQCAtMSwzICsxLDE3IEBA
CisyMDE1LTExLTE1ICBTYWFtIGJhcmF0aSAgPHNiYXJhdGlAYXBwbGUuY29tPgorCisgICAgICAg
IDY0LWJpdCBpbiB0aGUgREZHOiBub24gdGFpbCBDYWxscyB1bm5lY2Vzc2FyaWx5IHN0b3JlIHRo
ZSBhcmd1bWVudCBjb3VudCB0d2ljZSBvbiB0aGUgY2FsbGVlIGZyYW1lIGFuZCB0YWlscyBjYWxs
cyB1bm5lY2Vzc2FyaWx5IHN0b3JlIGl0IG9uY2UKKyAgICAgICAgaHR0cHM6Ly9idWdzLndlYmtp
dC5vcmcvc2hvd19idWcuY2dpP2lkPTE1MTI5N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2FsbChOb2Rl
KiBub2RlCiAgICAgICAgIC8vIGFyZ3VtZW50cy4KICAgICAgICAgaW50IG51bVBhc3NlZEFyZ3Mg
PSBub2RlLT5udW1DaGlsZHJlbigpIC0gMTsKIAotICAgICAgICBtX2ppdC5zdG9yZTMyKE1hY3Jv
QXNzZW1ibGVyOjpUcnVzdGVkSW1tMzIobnVtUGFzc2VkQXJncyksIEpJVENvbXBpbGVyOjpjYWxs
ZWVGcmFtZVBheWxvYWRTbG90KEpTU3RhY2s6OkFyZ3VtZW50Q291bnQpKTsKLQogICAgICAgICBp
ZiAobm9kZS0+b3AoKSA9PSBUYWlsQ2FsbCkgewogICAgICAgICAgICAgRWRnZSBjYWxsZWVFZGdl
ID0gbV9qaXQuZ3JhcGgoKS5jaGlsZChub2RlLCAwKTsKICAgICAgICAgICAgIEpTVmFsdWVPcGVy
YW5kIGNhbGxlZSh0aGlzLCBjYWxsZWVFZGdlKTsK
</data>

          </attachment>
      

    </bug>

</bugzilla>