[llvm-bugs] [Bug 44062] New: instcombine: doesn't remove redundant allocation / memory access with aligned_alloc
via llvm-bugs
llvm-bugs at lists.llvm.org
Tue Nov 19 06:49:02 PST 2019
https://bugs.llvm.org/show_bug.cgi?id=44062
Bug ID: 44062
Summary: instcombine: doesn't remove redundant allocation /
memory access with aligned_alloc
Product: tools
Version: 8.0
Hardware: PC
OS: Linux
Status: NEW
Severity: enhancement
Priority: P
Component: opt
Assignee: unassignedbugs at nondot.org
Reporter: uday at polymagelabs.com
CC: llvm-bugs at lists.llvm.org
In the snippet below, the allocated storage is optimized away when a malloc is
used, but not when an aligned_alloc is used. (aligned_alloc has effectively
similar semantics for the purpose of relevant opts here, and it has been in
glibc since 2.16 and in the C11 standard.) When a malloc is used, once the
load/stores are hoisted out by LICM, -instcombine gets rid of the heap
allocation and *s is effectively in a virtual register. But the same thing
doesn't happen with aligned_alloc; the allocation and the store to it remain.
https://godbolt.org/z/WCUF9n
------------------------------------------------
#include <stdlib.h>
#define N 100
void foo(int Y[N], int A[N][N], int X[N]) {
for (int i = 0; i < N; ++i) {
// Allocated storage optimized away when malloc is used.
// int *s = (int*)malloc((sizeof(int)));
int *s = (int *)aligned_alloc(sizeof(int), sizeof(int));
*s = Y[i];
for (int j = 0; j < N; ++j) {
*s += A[i][j] * X[j];
}
Y[i] += *s;
free(s);
}
}
--------------
On this note, this issue exists with posix_memalign as well. With
posix_memalign, in fact, the load/stores to *s in the loop aren't replaced by a
scalar. Although this is an artificial C/C++ example to reproduce this issue,
the more interesting/real use case is for example when a pass/utility has to
generate an allocation for a buffer of vector element types -- as such, an
alignment to vector size boundaries is desired, which malloc doesn't provide
for > 16 bytes.
--
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/20191119/006fa5c3/attachment.html>
More information about the llvm-bugs
mailing list