<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 - `-fmerge-functions` incorrectly overrides __attribute__((always_inline)) and __attribute__((flatten))"
href="https://bugs.llvm.org/show_bug.cgi?id=44805">44805</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>`-fmerge-functions` incorrectly overrides __attribute__((always_inline)) and __attribute__((flatten))
</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>Windows NT
</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>Frontend
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>mike.k@digitalcarbide.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>When `-Xclang -fmerge-functions` is supplied to Clang (trunk [10] until 3.6,
before 3.6 does not support `merge-functions`), attributes `always_inline` and
`flatten` are ignored, while GCC with equivalent `-fipa-icf` (supplied via
`-O3` by default) does not do such.
Observe (<a href="https://godbolt.org/z/5vJKDF">https://godbolt.org/z/5vJKDF</a>):
```
__attribute__((always_inline))
static int func (int a, int b) {
return a / b;
}
int func_a(int a, int b) {
return func(a, b);
}
int func_b(int a, int b) {
return func(a, b);
}
__attribute__((flatten))
int func_c(int a, int b) {
return func(a, b);
}
```
On GCC with the `-O3` flag, this produces:
```
func_a(int, int):
mov eax, edi
cdq
idiv esi
ret
func_b(int, int):
mov eax, edi
cdq
idiv esi
ret
func_c(int, int):
mov eax, edi
cdq
idiv esi
ret
```
On Clang with only the `-O3` flag, this produces the identical:
```
func_a(int, int): # @func_a(int, int)
mov eax, edi
cdq
idiv esi
ret
func_b(int, int): # @func_b(int, int)
mov eax, edi
cdq
idiv esi
ret
func_c(int, int): # @func_c(int, int)
mov eax, edi
cdq
idiv esi
ret
```
However, when `-Xclang -fmerge-functions` is supplied to match GCC's
`-fipa-icf` (#44804), both `always_inline` _and_ `flatten` are ignored, despite
GCC not ignoring them:
```
func_a(int, int): # @func_a(int, int)
mov eax, edi
cdq
idiv esi
ret
func_b(int, int): # @func_b(int, int)
jmp func_a(int, int) # TAILCALL
func_c(int, int): # @func_c(int, int)
jmp func_a(int, int) # TAILCALL
```</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>