<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 - -memcpyopt moves alloca struct load past stackrestore"
href="https://bugs.llvm.org/show_bug.cgi?id=48599">48599</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>-memcpyopt moves alloca struct load past stackrestore
</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>Scalar Optimizations
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>default_357-feep@yahoo.de
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>See <a href="https://godbolt.org/z/38nqh6">https://godbolt.org/z/38nqh6</a>
Consider the following IR:
declare i8* @llvm.stacksave()
declare void @llvm.stackrestore(i8*)
declare i8* @xmalloc(i64)
define i8* @bug() {
%stack = tail call i8* @llvm.stacksave()
%alloc = alloca { i64 }, align 8
%v0 = insertvalue { i64 } undef, i64 1, 0
store { i64 } %v0, { i64 }* %alloc, align 8
; load before restoring stack
%loaded = load { i64 }, { i64 }* %alloc, align 8
tail call void @llvm.stackrestore(i8* %stack)
%mem = tail call i8* @xmalloc(i64 8)
%mem.i64x1 = bitcast i8* %mem to { i64 }*
; loading %alloc here would no longer be valid!
store { i64 } %loaded, { i64 }* %mem.i64x1, align 8
ret i8* %mem
}
When passed to `opt -memcpyopt` on trunk of Dec-25-2020, this "optimizes" the
load followed by store into a memcpy. However, the memcpy is placed after the
stackrestore, leading to it reading stack memory that is no longer valid.</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>