<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 - Missed hoisting opportunity"
href="https://bugs.llvm.org/show_bug.cgi?id=51747">51747</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Missed hoisting opportunity
</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>enhancement
</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>david.bolvansky@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>#include <stdio.h> /* fprintf, open, fdopen, fread, _fileno, stdin, stdout
*/
#include <stdlib.h> /* malloc, free */
#include <string.h> /* strcmp, strlen */
static const char*
extractFilename(const char* path, char separator)
{
const char* search = strrchr(path, separator);
if (search == NULL) return path;
return search+1;
}
char*
FIO_createFilename_fromOutDir(const char* path, const char* outDirName, const
size_t suffixLen)
{
const char* filenameStart;
char separator;
char* result;
separator = '/';
filenameStart = extractFilename(path, separator);
result = (char*) calloc(1, strlen(outDirName) + 1 + strlen(filenameStart) +
suffixLen + 1);
if (!result) {
; // EXM_THROW(30, "zstd: FIO_createFilename_fromOutDir: %s",
strerror(errno));
}
memcpy(result, outDirName, strlen(outDirName));
if (outDirName[strlen(outDirName)-1] == separator) {
memcpy(result + strlen(outDirName), filenameStart,
strlen(filenameStart));
} else {
memcpy(result + strlen(outDirName), &separator, 1);
memcpy(result + strlen(outDirName) + 1, filenameStart,
strlen(filenameStart));
}
return result;
}
define dso_local noalias i8* @_Z29FIO_createFilename_fromOutDirPKcS0_m(i8*
readonly %0, i8* nocapture readonly %1, i64 %2) local_unnamed_addr #0 {
%4 = tail call i8* @strrchr(i8* noundef nonnull dereferenceable(1) %0, i32
47) #4
%5 = icmp eq i8* %4, null
%6 = getelementptr inbounds i8, i8* %4, i64 1
%7 = select i1 %5, i8* %0, i8* %6
%8 = tail call i64 @strlen(i8* noundef nonnull dereferenceable(1) %1) #4
%9 = tail call i64 @strlen(i8* noundef nonnull dereferenceable(1) %7) #4
%10 = add i64 %2, 2
%11 = add i64 %10, %8
%12 = add i64 %11, %9
%13 = tail call noalias align 16 i8* @calloc(i64 1, i64 %12) #5
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 16 %13, i8* align 1 %1,
i64 %8, i1 false)
%14 = add i64 %8, -1
%15 = getelementptr inbounds i8, i8* %1, i64 %14
%16 = load i8, i8* %15, align 1, !tbaa !3
%17 = icmp eq i8 %16, 47
%18 = getelementptr inbounds i8, i8* %13, i64 %8
br i1 %17, label %19, label %21
19: ; preds = %3
%20 = tail call i64 @strlen(i8* noundef nonnull dereferenceable(1) %7) #4
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 %18, i8* align 1 %7,
i64 %20, i1 false)
br label %24
21: ; preds = %3
store i8 47, i8* %18, align 1
%22 = getelementptr inbounds i8, i8* %18, i64 1
%23 = tail call i64 @strlen(i8* noundef nonnull dereferenceable(1) %7) #4
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* nonnull align 1 %22, i8* align
1 %7, i64 %23, i1 false)
br label %24
24: ; preds = %21, %19
ret i8* %13
}
Issue: hoist strlen (%20, %23) before branch? GVN Hoist does not help. Seems
like LLVM is worried about "store i8 47, i8* %18, align 1".
With:
19: ; preds = %3
%20 = tail call i64 @strlen(i8* noundef nonnull dereferenceable(1) %7) #4
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 %18, i8* align 1 %7,
i64 %20, i1 false)
br label %24
21: ; preds = %3
%22 = tail call i64 @strlen(i8* noundef nonnull dereferenceable(1) %7) #4
%23 = getelementptr inbounds i8, i8* %18, i64 1
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* nonnull align 1 %23, i8* align
1 %7, i64 %22, i1 false)
br label %24
24: ; preds = %21, %19
ret i8* %13
}
Hoisted fine.
But if gep and strlen is reordered (also in motivating testcase IR):
19: ; preds = %3
%20 = tail call i64 @strlen(i8* noundef nonnull dereferenceable(1) %7) #4
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 %18, i8* align 1 %7,
i64 %20, i1 false)
br label %24
21: ; preds = %3
%22 = getelementptr inbounds i8, i8* %18, i64 1
%23 = tail call i64 @strlen(i8* noundef nonnull dereferenceable(1) %7) #4
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* nonnull align 1 %22, i8* align
1 %7, i64 %23, i1 false)
br label %24
24: ; preds = %21, %19
ret i8* %13
}
Hoisting failed.
%22</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>