<html>
<head>
<base href="https://llvm.org/bugs/" />
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW --- - Missed optimization: sink computation result to the first use"
href="https://llvm.org/bugs/show_bug.cgi?id=27846">27846</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Missed optimization: sink computation result to the first use
</td>
</tr>
<tr>
<th>Product</th>
<td>libraries
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>Register Allocator
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>eugeni.stepanov@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>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>
...</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>