<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 - opt miscompiles with "opt -O3 -newgvn -structurizecfg""
href="https://bugs.llvm.org/show_bug.cgi?id=37664">37664</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>opt miscompiles with "opt -O3 -newgvn -structurizecfg"
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</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>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>Vsevolod.Livinskij@frtk.ru
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>Created <span class=""><a href="attachment.cgi?id=20385" name="attach_20385" title="Reproducer.">attachment 20385</a> <a href="attachment.cgi?id=20385&action=edit" title="Reproducer.">[details]</a></span>
Reproducer.
Opt produces incorrect code with -O3 -newgvn -structurizecfg
opt-bisect-limit points to Machine Common Subexpression Elimination on function
Testcase looks weird, but I can't reduce it further.
Reproducer:
<span class="quote">>$ cat func.cpp</span >
#include "init.h"
void tf_3_foo() {
bool a(var_3);
var_2 = (tf_3_var_38 && struct_obj.member_1_3) ||
(a && arr_3[0]) || !a || !ptr;
}
<span class="quote">>$ cat driver.cpp</span >
#include "init.h"
#include <vector>
void a(long) {}
std::vector<int> b;
struct_1 struct_2::member_2;
bool var_1, var_2;
const bool tf_3_var_38 = false;
unsigned short var_3 = 3;
tf_3_struct_1 struct_obj;
std::array<unsigned short, 10> arr_2;
std::valarray<bool> arr_3{false};
unsigned short *ptr = &arr_2[0];
void tf_3_foo();
int main() {
a(1038);
a(var_1);
a(struct_2::member_2.member_1);
b[2];
b[3];
tf_3_foo();
printf("%d\n", (int)var_2);
}
<span class="quote">>$ cat init.h</span >
#include <valarray>
struct struct_1 {
int member_1 : 13;
};
struct struct_2 {
static struct_1 member_2;
};
extern const bool tf_3_var_38;
extern unsigned short var_3;
struct tf_3_struct_1 {
bool member_1_3 : 3;
} extern struct_obj;
extern std::valarray<bool> arr_3;
extern bool var_2;
extern unsigned short *ptr;
Error:
<span class="quote">>$ clang++ driver.cpp func.cpp
>$ ./a.out</span >
0
<span class="quote">>$ clang++ -O3 -Xclang -disable-llvm-optzns -emit-llvm -c -o func.bc func.cpp
>$ opt -O3 -o func.ll func.bc -newgvn -structurizecfg
>$ clang++ -O3 -c -o func.o func.ll
>$ clang++ driver.cpp func.o
>$ ./a.out</span >
1
LLVM version:
clang version 7.0.0 (trunk 333377)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /llvm/bin-trunk/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/4.4.7
Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/4.8.2
Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/4.8.5
Selected GCC installation: /usr/lib/gcc/x86_64-redhat-linux/4.8.5
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Selected multilib: .;@m64</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>