<?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>125430</bug_id>
          
          <creation_ts>2013-12-08 14:35:02 -0800</creation_ts>
          <short_desc>CSE should work in SSA</short_desc>
          <delta_ts>2013-12-10 09:54:45 -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>528+ (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>112840</blocked>
    
    <blocked>125429</blocked>
          <everconfirmed>1</everconfirmed>
          <reporter name="Filip Pizlo">fpizlo</reporter>
          <assigned_to name="Filip Pizlo">fpizlo</assigned_to>
          <cc>barraclough</cc>
    
    <cc>ggaren</cc>
    
    <cc>mark.lam</cc>
    
    <cc>mhahnenberg</cc>
    
    <cc>msaboff</cc>
    
    <cc>nrotem</cc>
    
    <cc>oliver</cc>
    
    <cc>sam</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>957718</commentid>
    <comment_count>0</comment_count>
    <who name="Filip Pizlo">fpizlo</who>
    <bug_when>2013-12-08 14:35:02 -0800</bug_when>
    <thetext>Patch forthcoming.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>957719</commentid>
    <comment_count>1</comment_count>
    <who name="Filip Pizlo">fpizlo</who>
    <bug_when>2013-12-08 14:35:12 -0800</bug_when>
    <thetext>This is actually non-trivial.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>957724</commentid>
    <comment_count>2</comment_count>
      <attachid>218717</attachid>
    <who name="Filip Pizlo">fpizlo</who>
    <bug_when>2013-12-08 15:37:44 -0800</bug_when>
    <thetext>Created attachment 218717
the patch</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>957736</commentid>
    <comment_count>3</comment_count>
    <who name="Nadav Rotem">nrotem</who>
    <bug_when>2013-12-08 19:00:39 -0800</bug_when>
    <thetext>&gt;&gt; m_graph.getBlocksInDepthFirstOrder(depthFirst);

Why are you scanning the code in DFS?  Is this a preparation for the multi-block CSE support? If it is then I have some code for that.  Also, I think that I need some help with my CSE patch. It boosts one of the sun spider benchmarks by 30%, but I had a crash I could not debug when I was refactoring the code to use the DoesReadOrWrite API.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>957737</commentid>
    <comment_count>4</comment_count>
    <who name="Filip Pizlo">fpizlo</who>
    <bug_when>2013-12-08 19:06:31 -0800</bug_when>
    <thetext>(In reply to comment #3)
&gt; &gt;&gt; m_graph.getBlocksInDepthFirstOrder(depthFirst);
&gt; 
&gt; Why are you scanning the code in DFS?

It guarantees that if A dominates B then I visit A before B.  Essentially, CSE is doing a RAUW even though DFG doesn&apos;t have pointers from a node to its users.  So even though I don&apos;t find global redundancies, I may have a basic block with:

x: ValueAdd(@a, @b)
y: ValueAdd(@a, @b)

And @y gets used in some basic blocks dominated by this block.  CSE is responsible for finding all of the uses of @y and replacing them with @x.  That&apos;s why we do DFS order.

&gt; Is this a preparation for the multi-block CSE support? If it is then I have some code for that.  Also, I think that I need some help with my CSE patch. It boosts one of the sun spider benchmarks by 30%, but I had a crash I could not debug when I was refactoring the code to use the DoesReadOrWrite API.

OK - we should chat this week!</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>957748</commentid>
    <comment_count>5</comment_count>
    <who name="Nadav Rotem">nrotem</who>
    <bug_when>2013-12-08 20:18:51 -0800</bug_when>
    <thetext>(In reply to comment #4)
&gt; (In reply to comment #3)
&gt; &gt; &gt;&gt; m_graph.getBlocksInDepthFirstOrder(depthFirst);
&gt; &gt; 
&gt; &gt; Why are you scanning the code in DFS?
&gt; 
&gt; It guarantees that if A dominates B then I visit A before B.  Essentially, CSE is doing a RAUW even though DFG doesn&apos;t have pointers from a node to its users.  So even though I don&apos;t find global redundancies, I may have a basic block with:
&gt; 
&gt; x: ValueAdd(@a, @b)
&gt; y: ValueAdd(@a, @b)
&gt; 
&gt; And @y gets used in some basic blocks dominated by this block.  CSE is responsible for finding all of the uses of @y and replacing them with @x.  That&apos;s why we do DFS order.
&gt; 

I know how dominator based value numbering works :) I was wondering why you are implementing it this way. My understanding is that this patch will not change anything since the code still does intra block cse. You will still need to support the non SSA dfg phase with the same code base, so I am not sure how you want to implement the multi block cse. The block scan order is the least of my worries. 

&gt; &gt; Is this a preparation for the multi-block CSE support? If it is then I have some code for that.  Also, I think that I need some help with my CSE patch. It boosts one of the sun spider benchmarks by 30%, but I had a crash I could not debug when I was refactoring the code to use the DoesReadOrWrite API.
&gt; 
&gt; OK - we should chat this week!</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>957750</commentid>
    <comment_count>6</comment_count>
    <who name="Filip Pizlo">fpizlo</who>
    <bug_when>2013-12-08 20:38:13 -0800</bug_when>
    <thetext>(In reply to comment #5)
&gt; (In reply to comment #4)
&gt; &gt; (In reply to comment #3)
&gt; &gt; &gt; &gt;&gt; m_graph.getBlocksInDepthFirstOrder(depthFirst);
&gt; &gt; &gt; 
&gt; &gt; &gt; Why are you scanning the code in DFS?
&gt; &gt; 
&gt; &gt; It guarantees that if A dominates B then I visit A before B.  Essentially, CSE is doing a RAUW even though DFG doesn&apos;t have pointers from a node to its users.  So even though I don&apos;t find global redundancies, I may have a basic block with:
&gt; &gt; 
&gt; &gt; x: ValueAdd(@a, @b)
&gt; &gt; y: ValueAdd(@a, @b)
&gt; &gt; 
&gt; &gt; And @y gets used in some basic blocks dominated by this block.  CSE is responsible for finding all of the uses of @y and replacing them with @x.  That&apos;s why we do DFS order.
&gt; &gt; 
&gt; 
&gt; I know how dominator based value numbering works :) I was wondering why you are implementing it this way.

That&apos;s the thing - this isn&apos;t meant to be dominator-based value numbering.  This is still doing block-local CSE.  The only thing global about it is propagating node-&gt;misc.replacement, which is like a bulk version of RAUW.

I think we&apos;re in violent agreement over the fact that this isn&apos;t dominator based value numbering.  It&apos;s not meant to be.  This patch is just a bugfix to make it legal to run the current CSE phase in SSA mode.  Previously doing so would either assert or corrupt the IR.

&gt; My understanding is that this patch will not change anything since the code still does intra block cse. 

Correct, for now.  This work:

https://bugs.webkit.org/show_bug.cgi?id=125253

will eventually benefit from it, since it&apos;s doing a lowering that happens after SSAification.

The long-term idea is to do some DFG-&gt;DFG lowerings only along the FTL path.  Then it makes sense to do some extra CSE along the FTL path, as well.

&gt; You will still need to support the non SSA dfg phase with the same code base, so I am not sure how you want to implement the multi block cse. The block scan order is the least of my worries. 

I&apos;m not implementing multi-block CSE.  This patch isn&apos;t intended to make multi-block CSE easier to implement.  I&apos;m just making it so that it is possible to run the existing CSE phase when in SSA form.

Prior to this patch, if you needed to do *any* CSE - even the stupid block-local one - over SSA, you&apos;d crash because the block-local CSE would either assert or corrupt the IR.  I think that this patch is mainly interesting from the standpoint of just making all tests pass when CSE is run over SSA.

Ultimately, I want all optimization phases to be runnable in SSA and to have some way of testing that they do, so that we have the option of doing SSAification prior to the optimization fixpoint in FTL mode.  I suspect that if nothing else, this ought to reduce compile times.  But it should also make the CFA and the folder more precise.

On the topic of multi-block CSE, I&apos;m not sure how much the DFG CSE is going to end up buying us, in FTL mode.  It certainly finds *some* things that LLVM&apos;s GVN won&apos;t find (in case of nodes that call C functions that do write some memory but don&apos;t clobber the node being eliminated), but for *most* things, LLVM GVN+TBAA is likely to be strictly better.  Maybe then the DFG CSE would serve a similar purpose to LLVM&apos;s EarlyCSE, which as I understand it, has more to do with compile times than anything else?

&gt; 
&gt; &gt; &gt; Is this a preparation for the multi-block CSE support? If it is then I have some code for that.  Also, I think that I need some help with my CSE patch. It boosts one of the sun spider benchmarks by 30%, but I had a crash I could not debug when I was refactoring the code to use the DoesReadOrWrite API.
&gt; &gt; 
&gt; &gt; OK - we should chat this week!</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>958399</commentid>
    <comment_count>7</comment_count>
    <who name="Filip Pizlo">fpizlo</who>
    <bug_when>2013-12-10 09:54:45 -0800</bug_when>
    <thetext>Landed in http://trac.webkit.org/changeset/160328</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>218717</attachid>
            <date>2013-12-08 15:37:44 -0800</date>
            <delta_ts>2013-12-09 08:58:40 -0800</delta_ts>
            <desc>the patch</desc>
            <filename>blah.patch</filename>
            <type>text/plain</type>
            <size>3276</size>
            <attacher name="Filip Pizlo">fpizlo</attacher>
            
              <data encoding="base64">SW5kZXg6IFNvdXJjZS9KYXZhU2NyaXB0Q29yZS9DaGFuZ2VMb2cKPT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PQotLS0gU291
cmNlL0phdmFTY3JpcHRDb3JlL0NoYW5nZUxvZwkocmV2aXNpb24gMTYwMjkzKQorKysgU291cmNl
L0phdmFTY3JpcHRDb3JlL0NoYW5nZUxvZwkod29ya2luZyBjb3B5KQpAQCAtMSwzICsxLDE2IEBA
CisyMDEzLTEyLTA4ICBGaWxpcCBQaXpsbyAgPGZwaXpsb0BhcHBsZS5jb20+CisKKyAgICAgICAg
Q1NFIHNob3VsZCB3b3JrIGluIFNTQQorICAgICAgICBodHRwczovL2J1Z3Mud2Via2l0Lm9yZy9z
aG93X2J1Zy5jZ2k/aWQ9MTI1NDMwCisKKyAgICAgICAgUmV2aWV3ZWQgYnkgTk9CT0RZIChPT1BT
ISkuCisKKyAgICAgICAgKiBkZmcvREZHQ1NFUGhhc2UuY3BwOg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AgICAgICAgQVNTRVJUKG5vZGUtPm9wKCkg
IT0gWm9tYmllSGludCk7CiAgICAgICAgICAgICBub2RlLT5jaGlsZDEoKS0+bWVyZ2VGbGFncyhO
b2RlUmVsZXZhbnRUb09TUik7CisgICAgICAgIH0KICAgICAgICAgCiAgICAgICAgIHN3aXRjaCAo
bm9kZS0+b3AoKSkgewogICAgICAgICAKQEAgLTExMDUsNiArMTExMywxMSBAQCBwcml2YXRlOgog
ICAgICAgICB9CiAgICAgICAgICAgICAKICAgICAgICAgY2FzZSBGbHVzaDogeworICAgICAgICAg
ICAgaWYgKG1fZ3JhcGgubV9mb3JtID09IFNTQSkgeworICAgICAgICAgICAgICAgIC8vIEZJWE1F
OiBFbmFibGUgRmx1c2ggc3RvcmUgZWxpbWluYXRpb24gaW4gU1NBIGZvcm0uCisgICAgICAgICAg
ICAgICAgLy8gaHR0cHM6Ly9idWdzLndlYmtpdC5vcmcvc2hvd19idWcuY2dpP2lkPTEyNTQyOQor
ICAgICAgICAgICAgICAgIGJyZWFrOworICAgICAgICAgICAgfQogICAgICAgICAgICAgVmFyaWFi
bGVBY2Nlc3NEYXRhKiB2YXJpYWJsZUFjY2Vzc0RhdGEgPSBub2RlLT52YXJpYWJsZUFjY2Vzc0Rh
dGEoKTsKICAgICAgICAgICAgIFZpcnR1YWxSZWdpc3RlciBsb2NhbCA9IHZhcmlhYmxlQWNjZXNz
RGF0YS0+bG9jYWwoKTsKICAgICAgICAgICAgIE5vZGUqIHJlcGxhY2VtZW50ID0gbm9kZS0+Y2hp
bGQxKCkubm9kZSgpOwpJbmRleDogU291cmNlL0phdmFTY3JpcHRDb3JlL2RmZy9ERkdQbGFuLmNw
cAo9PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09Ci0tLSBTb3VyY2UvSmF2YVNjcmlwdENvcmUvZGZnL0RGR1BsYW4uY3BwCShy
ZXZpc2lvbiAxNjAyOTMpCisrKyBTb3VyY2UvSmF2YVNjcmlwdENvcmUvZGZnL0RGR1BsYW4uY3Bw
CSh3b3JraW5nIGNvcHkpCkBAIC0yNjksNiArMjY5LDcgQEAgUGxhbjo6Q29tcGlsYXRpb25QYXRo
IFBsYW46OmNvbXBpbGVJblRocgogICAgICAgICBwZXJmb3JtTGl2ZW5lc3NBbmFseXNpcyhkZmcp
OwogICAgICAgICBwZXJmb3JtQ0ZBKGRmZyk7CiAgICAgICAgIHBlcmZvcm1MSUNNKGRmZyk7Cisg
ICAgICAgIHBlcmZvcm1DU0UoZGZnKTsKICAgICAgICAgcGVyZm9ybUxpdmVuZXNzQW5hbHlzaXMo
ZGZnKTsKICAgICAgICAgcGVyZm9ybUNGQShkZmcpOwogICAgICAgICBpZiAoT3B0aW9uczo6dmFs
aWRhdGVGVExPU1JFeGl0TGl2ZW5lc3MoKSkK
</data>
<flag name="review"
          id="242206"
          type_id="1"
          status="+"
          setter="oliver"
    />
          </attachment>
      

    </bug>

</bugzilla>