<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 - TBAA fails to disambiguate pointers, missed redundancy elimination"
href="https://bugs.llvm.org/show_bug.cgi?id=36959">36959</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>TBAA fails to disambiguate pointers, missed redundancy elimination
</td>
</tr>
<tr>
<th>Product</th>
<td>new-bugs
</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>new bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>sebpop@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>typedef struct {
const char *data;
int length;
} str;
typedef struct {
str *s;
} a;
typedef struct {
const char *s;
} b;
void fun(a *in, b *out) {
out->s = in->s->data;
out->s = in->s->data;
}
GCC finds the redundancy and reads and writes only once (for aarch64):
fun:
ldr x0, [x0]
ldr x0, [x0]
str x0, [x1]
ret
LLVM generates twice the number of loads and stores than GCC:
fun:
ldr x8, [x0]
ldr x8, [x8]
str x8, [x1]
ldr x8, [x0]
ldr x8, [x8]
str x8, [x1]
ret
This may be related to <a class="bz_bug_link
bz_status_NEW "
title="NEW - Different types share the same TBAA descriptor"
href="show_bug.cgi?id=35703">https://bugs.llvm.org/show_bug.cgi?id=35703</a>
Here is the llvm IR for the testcase:
%struct.a = type { %struct.str* }
%struct.str = type { i8*, i32 }
%struct.b = type { i8* }
define dso_local void @fun(%struct.a* nocapture readonly %in, %struct.b*
nocapture %out) local_unnamed_addr #0 {
entry:
%0 = bitcast %struct.a* %in to i64**
%1 = load i64*, i64** %0, align 8, !tbaa !2
%2 = load i64, i64* %1, align 8, !tbaa !7
%3 = bitcast %struct.b* %out to i64*
store i64 %2, i64* %3, align 8, !tbaa !2
%4 = load i64*, i64** %0, align 8, !tbaa !2
%5 = load i64, i64* %4, align 8, !tbaa !7
store i64 %5, i64* %3, align 8, !tbaa !2
ret void
}
!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{!"clang version 7.0.0 "}
!2 = !{!3, !4, i64 0}
!3 = !{!"", !4, i64 0}
!4 = !{!"any pointer", !5, i64 0}
!5 = !{!"omnipotent char", !6, i64 0}
!6 = !{!"Simple C/C++ TBAA"}
!7 = !{!8, !4, i64 0}
!8 = !{!"", !4, i64 0, !9, i64 8}
!9 = !{!"int", !5, i64 0}</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>