[llvm-bugs] [Bug 27846] New: Missed optimization: sink computation result to the first use

via llvm-bugs llvm-bugs at lists.llvm.org
Mon May 23 14:44:15 PDT 2016


https://llvm.org/bugs/show_bug.cgi?id=27846

            Bug ID: 27846
           Summary: Missed optimization: sink computation result to the
                    first use
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Register Allocator
          Assignee: unassignedbugs at nondot.org
          Reporter: eugeni.stepanov at gmail.com
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

In the code snippet below, clang -O3 produces different code for f() and g().
The code for f() computes all x0..x9 values early, resulting in lots of used
registers. If I add a bunch more calls (and x* variables), or switch to a
target with less registers, computation results will be spilled on stack.

void f() {
  int *p = new int[10];
  int *x0 = &p[0];
  int *x1 = &p[1];
  int *x2 = &p[2];
  int *x3 = &p[3];
  int *x4 = &p[4];
  int *x5 = &p[5];
  int *x6 = &p[6];
  int *x7 = &p[7];
  int *x8 = &p[8];
  int *x9 = &p[9];
  capture(x0);
  capture(x1);
  capture(x2);
  capture(x3);
  capture(x4);
  capture(x5);
  capture(x6);
  capture(x7);
  capture(x8);
  capture(x9);
}

void g() {
  int *p = new int[10];
  int *x0 = &p[0];
  capture(x0);
  int *x1 = &p[1];
  capture(x1);
  int *x2 = &p[2];
  capture(x2);
  int *x3 = &p[3];
  capture(x3);
  int *x4 = &p[4];
  capture(x4);
  int *x5 = &p[5];
  capture(x5);
  int *x6 = &p[6];
  capture(x6);
  int *x7 = &p[7];
  capture(x7);
  int *x8 = &p[8];
  capture(x8);
  int *x9 = &p[9];
  capture(x9);
}

0000000000000000 <_Z1fv>:
_Z1fv():
   0:    f81a0ffb     str    x27, [sp,#-96]!
   4:    a90167fa     stp    x26, x25, [sp,#16]
   8:    a9025ff8     stp    x24, x23, [sp,#32]
   c:    a90357f6     stp    x22, x21, [sp,#48]
  10:    a9044ff4     stp    x20, x19, [sp,#64]
  14:    a9057bfd     stp    x29, x30, [sp,#80]
  18:    910143fd     add    x29, sp, #0x50
  1c:    52800500     mov    w0, #0x28                      // #40
  20:    94000000     bl    0 <_Znam>
  24:    91001013     add    x19, x0, #0x4
  28:    91002014     add    x20, x0, #0x8
  2c:    91003015     add    x21, x0, #0xc
  30:    91004016     add    x22, x0, #0x10
  34:    91005017     add    x23, x0, #0x14
  38:    91006018     add    x24, x0, #0x18
  3c:    91007019     add    x25, x0, #0x1c
  40:    9100801a     add    x26, x0, #0x20
  44:    9100901b     add    x27, x0, #0x24
  48:    94000000     bl    0 <_Z7capturePi>
  4c:    aa1303e0     mov    x0, x19
  50:    94000000     bl    0 <_Z7capturePi>
  ...

00000000000000ac <_Z1gv>:
_Z1gv():
  ac:    f81e0ff3     str    x19, [sp,#-32]!
  b0:    a9017bfd     stp    x29, x30, [sp,#16]
  b4:    910043fd     add    x29, sp, #0x10
  b8:    52800500     mov    w0, #0x28                      // #40
  bc:    94000000     bl    0 <_Znam>
  c0:    aa0003f3     mov    x19, x0
  c4:    94000000     bl    0 <_Z7capturePi>
  c8:    91001260     add    x0, x19, #0x4
  cc:    94000000     bl    0 <_Z7capturePi>
  ...

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20160523/4977ba2e/attachment.html>


More information about the llvm-bugs mailing list