<html>
<head>
<base href="https://llvm.org/bugs/" />
</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 --- - Multi-level pointers not disambiguated, even with strict aliasing"
href="https://llvm.org/bugs/show_bug.cgi?id=31096">31096</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Multi-level pointers not disambiguated, even with strict aliasing
</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>All
</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>Global Analyses
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>dberlin@dberlin.org
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>The following simple example:
int *p;
int foo(int argc, char **argv)
{
int result;
*p = 2;
if (argc)
*p = 2;
result = *p;
return result;
}
Does not get optimized by GVN (or NewGVN).
It's trivial friend:
int foo(int argc, char **argv, int *p)
{
int result;
*p = 2;
if (argc)
*p = 2;
result = *p;
return result;
}
Does get optimized by NewGVN with a patch i have.
The difference is that the global object turns into an i32 ** that we do a load
from, so the llvm IR looks like this:
@p = common global i32* null, align 8
; Function Attrs: norecurse nounwind ssp uwtable
define i32 @foo(i32, i8** nocapture readnone) #0 {
%3 = load i32*, i32** @p, align 8, !tbaa !2
store i32 2, i32* %3, align 4, !tbaa !6
%4 = icmp eq i32 %0, 0
br i1 %4, label %7, label %5
; <label>:5 ; preds = %2
%6 = load i32*, i32** @p, align 8, !tbaa !2
store i32 2, i32* %6, align 4, !tbaa !6
br label %7
; <label>:7 ; preds = %2, %5
%8 = load i32*, i32** @p, align 8, !tbaa !2
%9 = load i32, i32* %8, align 4, !tbaa !6
ret i32 %9
}
!0 = !{i32 1, !"PIC Level", i32 2}
!1 = !{!"Apple LLVM version 8.0.0 (clang-800.0.42.1)"}
!2 = !{!3, !3, i64 0}
!3 = !{!"any pointer", !4, i64 0}
!4 = !{!"omnipotent char", !5, i64 0}
!5 = !{!"Simple C/C++ TBAA"}
!6 = !{!7, !7, i64 0}
!7 = !{!"int", !4, i64 0}
Note that in this two level version, we believe the stores to i32* can affect
an i32**.
At the "llvm level" this is correct (IE there are no real types, aso we can't
say anything) , however, with strict aliasing, and the original code, it's not
possible.
In fact, at least for basic types, with strict aliasing, it's not possible for
a pointer of level n to affect a pointer of level n+1 (IE a store to an int *
can't ever alias an int **, only the reverse) , but we haven't taught LLVM
that.
(I suspect, btw, the above can be reproduced with multi-level pointers in
general)
Not sure where we should fix this, suggestions welcome.</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>