https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78185
Bug ID: 78185
Summary: Wrong branch optimization with -O1 on x86/x86_64
Product: gcc
Version: 7.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: mdaniels at qnx dot com
Target Milestone: ---
Created attachment 39943
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=39943&action=edit
Testcase
The attached test case is being incorrectly optimized on x86/x86_64 with -O1 or
above.
$ gcc -O1 -fno-strict-aliasing -fwrapv -fno-aggressive-loop-optimizations -Wall
-Wextra -o /tmp/test /tmp/test.c
$ /tmp/test
Floating point exception (core dumped)
The test case is reduced from csmith output.
Looking at the resulting assembly, it seems like the wrong branch is being
optimized away. Since it takes the wrong branch it ends up trying to divide by
zero.
I had also tried with armv7 and aarch64, which kept both branches so the
problem was not seen on those archs.
Tested on a Linux x86_64 host with GCC 5.4 and ToT.