<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 --- - Bug in alias analysis (GlobalsAA)"
href="https://llvm.org/bugs/show_bug.cgi?id=25822">25822</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Bug in alias analysis (GlobalsAA)
</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>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>fraser@codeplay.com
</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>I believe I've found a bug in alias analysis (globals mod ref) leading to
incorrect instcombine optimization. Take the following C snippet:
static int i;
int __attribute__((noinline)) foo(int *ptr) {
i = 1;
*ptr = 10;
return i;
}
Compiled with clang to IR at -O0 we get:
@i = internal global i32 0, align 4
; Function Attrs: noinline nounwind uwtable
define i32 @foo(i32* %ptr) #0 {
entry:
%ptr.addr = alloca i32*, align 8
store i32* %ptr, i32** %ptr.addr, align 8
store i32 1, i32* @i, align 4
%0 = load i32*, i32** %ptr.addr, align 8
store i32 10, i32* %0, align 4
%1 = load i32, i32* @i, align 4
ret i32 %1
}
Then running opt on it as follows:
<span class="quote">> opt -O1 -S -o - test.ll</span >
@i = internal global i32 0, align 4
; Function Attrs: noinline norecurse nounwind uwtable
define i32 @foo(i32* nocapture %ptr) #0 {
entry:
store i32 1, i32* @i, align 4
store i32 10, i32* %ptr, align 4
ret i32 1
}
I believe this is an invalid optimization, as ptr could alias to &i, like in
this example:
int main() {
return foo(&i) != 10;
}
I tracked it down to GlobalsAA being turned on by default in r250157 (git
938c3d3)
So, doing:
<span class="quote">> opt -O1 -S -enable-non-lto-gmr=false -o - test.ll</span >
@i = internal global i32 0, align 4
; Function Attrs: noinline norecurse nounwind uwtable
define i32 @foo(i32* nocapture %ptr) #0 {
entry:
store i32 1, i32* @i, align 4
store i32 10, i32* %ptr, align 4
%0 = load i32, i32* @i, align 4
ret i32 %0
}
works as expected. I haven't gone further to work out what inside these
analyses is causing the problem.</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>