llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

opt miscompiles with "opt -O3 -newgvn -structurizecfg"

Open Vsevolod-Livinskij opened this issue 8 years ago • 1 comments

Bugzilla Link 37664
Resolution FIXED
Resolved on Apr 29, 2020 13:31
Version trunk
OS Linux
Attachments Reproducer.
CC @dbabokin,@ekatz,@Vsevolod-Livinskij

Extended Description

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:

$ cat func.cpp #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; } $ cat driver.cpp #include "init.h" #include void a(long) {} std::vector 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 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); } $ cat init.h #include 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 arr_3; extern bool var_2; extern unsigned short *ptr;

Error:

$ clang++ driver.cpp func.cpp $ ./a.out 0 $ 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 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

Vsevolod-Livinskij avatar Jun 02 '18 20:06 Vsevolod-Livinskij

Not reproducible anymore in LLVM 9.0.

ekatz avatar Apr 29 '20 20:04 ekatz