[llvm-bugs] [Bug 48599] New: -memcpyopt moves alloca struct load past stackrestore
via llvm-bugs
llvm-bugs at lists.llvm.org
Fri Dec 25 08:56:34 PST 2020
https://bugs.llvm.org/show_bug.cgi?id=48599
Bug ID: 48599
Summary: -memcpyopt moves alloca struct load past stackrestore
Product: libraries
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: Scalar Optimizations
Assignee: unassignedbugs at nondot.org
Reporter: default_357-feep at yahoo.de
CC: llvm-bugs at lists.llvm.org
See https://godbolt.org/z/38nqh6
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.
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20201225/7b142cd4/attachment.html>
More information about the llvm-bugs
mailing list