<html>
<head>
<base href="https://bugs.llvm.org/">
</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 - Size regression -Os constant propagation difference results in larger code"
href="https://bugs.llvm.org/show_bug.cgi?id=46237">46237</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Size regression -Os constant propagation difference results in larger code
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</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>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>LLVM Codegen
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>michaeljclark@mac.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
</td>
</tr></table>
<p>
<div>
<pre>-Os is using more space than -O2 for this example.
--- BEGIN SCRIPT ---
cat >f.c <<EOF
typedef unsigned long long u64;
u64 f(u64 x, u64 y, u64 z)
{
return ((z & 3u) << 6) | ((y & 7u) << 3) | (z & 7u);
}
EOF
clang -O2 -c -o O2.o f.c
clang -Os -c -o Os.o f.c
objdump -d O2.o
objdump -d Os.o
--- END SCRIPT ---
It seems that lifting a small immediate constant into a register takes more
space due to the requirement of a 32-bit immediate for register immediate
constant synthesis on x86, whereas the inlined constant fits within an imm8
operand. It seems more profitable to not hoist constants <= 255 which are used
as operands in simple arith/logical ops 2 or 3 times.
O2.o: <f>:
0: 89 d0 mov %edx,%eax
2: c1 e0 06 shl $0x6,%eax
5: 0f b6 c8 movzbl %al,%ecx
8: 83 e6 07 and $0x7,%esi
b: 83 e2 07 and $0x7,%edx
e: 48 8d 04 f2 lea (%rdx,%rsi,8),%rax
12: 48 09 c8 or %rcx,%rax
15: c3 retq
Os.o: <f>:
0: 89 d0 mov %edx,%eax
2: c1 e0 06 shl $0x6,%eax
5: 0f b6 c8 movzbl %al,%ecx
8: b8 07 00 00 00 mov $0x7,%eax
d: 48 21 c6 and %rax,%rsi
10: 48 21 c2 and %rax,%rdx
13: 48 8d 04 f2 lea (%rdx,%rsi,8),%rax
17: 48 09 c8 or %rcx,%rax
1a: c3 retq
$ clang --version
Ubuntu clang version
11.0.0-++20200607081810+e664d0543f8-1~exp1~20200607063338.223
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin</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>