New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.
Starred by 1 user

Issue metadata

Status: Archived
Owner:
Last visit > 30 days ago
Closed: Nov 2015
Cc:
HW: ----
NextAction: ----
OS: ----
Priority: 2
Type: Bug



Sign in to add a comment

Sink spill stores out of loop when possible

Project Member Reported by vegorov@chromium.org, Dec 14 2012 Back to list

Issue description

Currently we schedule spill stores eagerly (value is immediately stored into the spill slot after it is produced).

This negatively impacts code quality for the tight loops that are followed by code with a high register pressure (e.g. calls).

For example:

function test() {
  var sum = 0;
  var start = Date.now();
  for (var i = 0; i < 1000; i++) {
    sum += i;
  }
  var end = Date.now();
  return { result: sum, time: (end - start) };
}

test();
test();
%OptimizeFunctionOnNextCall(test);
test();

will result in the following code emitted for the loop:

                  ;;; B2 - LOOP entry
0x3e52bda3    99  8955e4         mov [ebp+0xe4],edx
0x3e52bda6   102  894de8         mov [ebp+0xe8],ecx
                  ;;; @27: gap.
                  ;;; @28: gap.
                  ;;; @29: cmp-id-and-branch. <#29>
0x3e52bda9   105  81f9e8030000   cmp ecx,0x3e8
0x3e52bdaf   111  0f8d1d000000   jnl 146  (0x3e52bdd2)
                  ;;; @34: label. <#36>
                  ;;; B4
                  ;;; @35: gap.
                  ;;; @36: stack-check. <#38>
0x3e52bdb5   117  3b2554e7410a   cmp esp,[0xa41e754]
0x3e52bdbb   123  0f82be010000   jc 575  (0x3e52bf7f)
                  ;;; @37: gap.
0x3e52bdc1   129  89d3           mov ebx,edx
                  ;;; @38: add-i. <#39>
0x3e52bdc3   131  03d9           add ebx,ecx
0x3e52bdc5   133  0f8071c26a15   jo 0x53bd803c               ;; deoptimization bailout 6
                  ;;; @39: gap.
                  ;;; @40: add-i. <#42>
0x3e52bdcb   139  83c101         add ecx,0x1
                  ;;; @41: gap.
                  ;;; @42: gap.
0x3e52bdce   142  89da           mov edx,ebx
                  ;;; @43: goto. <#44>
0x3e52bdd0   144  ebd1           jmp 99  (0x3e52bda3)

Notice unnecessary spill stores for the phis that are generated at the loop entry. Value is actually never restored from the spill slot inside the loop body itself. Such spill stores should be sunk down to the loop exit.
 
Cc: danno@chromium.org
Proposed improvement for register allocator: https://codereview.chromium.org/11575030

With it we generate:

                  ;;; B2 - LOOP entry
                  ;;; @27: gap.
                  ;;; @28: gap.
                  ;;; @29: cmp-id-and-branch. <#29>
0x3282bda3    99  81f9e8030000   cmp ecx,0x3e8
0x3282bda9   105  0f8d1d000000   jnl 140  (0x3282bdcc)
                  ;;; @34: label. <#36>
                  ;;; B4
                  ;;; @35: gap.
                  ;;; @36: stack-check. <#38>
0x3282bdaf   111  3b2554878c08   cmp esp,[0x88c8754]
0x3282bdb5   117  0f82c4010000   jc 575  (0x3282bf7f)
                  ;;; @37: gap.
0x3282bdbb   123  89d3           mov ebx,edx
                  ;;; @38: add-i. <#39>
0x3282bdbd   125  03d9           add ebx,ecx
0x3282bdbf   127  0f8077d2f617   jo 0x4a79903c               ;; deoptimization bailout 6
                  ;;; @39: gap.
                  ;;; @40: add-i. <#42>
0x3282bdc5   133  83c101         add ecx,0x1
                  ;;; @41: gap.
                  ;;; @42: gap.
0x3282bdc8   136  89da           mov edx,ebx
                  ;;; @43: goto. <#44>
0x3282bdca   138  ebd7           jmp 99  (0x3282bda3)
                  ;;; @48: label. <#45>
                  ;;; B6
0x3282bdcc   140  894de8         mov [ebp+0xe8],ecx
0x3282bdcf   143  8955e4         mov [ebp+0xe4],edx

(spill stores were sunk from B2 down to B6).

Comment 2 by habl...@google.com, Apr 29 2015

Status: Assigned (was: NULL)
Status: Archived (was: NULL)
I'm sure new register allocator will take care of this.
Labels: Priority-2

Sign in to add a comment