<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 - Extra stack load/store generated for a volatile {i16, i16} store"
href="https://bugs.llvm.org/show_bug.cgi?id=42709">42709</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Extra stack load/store generated for a volatile {i16, i16} store
</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>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>C
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>glider@google.com
</td>
</tr>
<tr>
<th>CC</th>
<td>blitzrakete@gmail.com, dgregor@apple.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
</td>
</tr></table>
<p>
<div>
<pre>For the following program:
$ cat tb.c
typedef struct { short v1, v2;} st_t;
void foo(st_t a) {
volatile st_t b;
b = a;
}
GCC generates a single store to a stack slot:
$ gcc tb.c -O2 -c
$ objdump -d tb.o
...
0000000000000000 <foo>:
0: 89 7c 24 fc mov %edi,-0x4(%rsp)
4: c3 retq
, whereas Clang uses an extra stack slot to store %rdi for no reason:
$ clang tb.c -O2 -c
$ objdump -d tb.o...
0000000000000000 <foo>:
0: 89 7c 24 f8 mov %edi,-0x8(%rsp)
4: 8b 44 24 f8 mov -0x8(%rsp),%eax
8: 89 44 24 fc mov %eax,-0x4(%rsp)
c: c3 retq
According to the generated IR Clang chose to use a volatile load for that extra
slot:
; Function Attrs: nounwind uwtable
define dso_local void @foo(i32 %a.coerce) local_unnamed_addr #0 {
entry:
%a.sroa.0 = alloca i32, align 4
%b.sroa.0 = alloca i32, align 4
store i32 %a.coerce, i32* %a.sroa.0, align 4
%b.sroa.0.0.b.0..sroa_cast = bitcast i32* %b.sroa.0 to i8*
call void @llvm.lifetime.start.p0i8(i64 4, i8* nonnull
%b.sroa.0.0.b.0..sroa_cast)
%a.sroa.0.0.a.sroa.0.0.a.sroa.0.0.copyload = load volatile i32, i32*
%a.sroa.0, align 4
store volatile i32 %a.sroa.0.0.a.sroa.0.0.a.sroa.0.0.copyload, i32*
%b.sroa.0, align 4
call void @llvm.lifetime.end.p0i8(i64 4, i8* nonnull
%b.sroa.0.0.b.0..sroa_cast)
ret void
}
- maybe that prevented DSE from removing the dead store.</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>