Created attachment 17884 [details] C reproducer The attached testcase performs a division (by zero) before checking the condition present in the original sourcecode. The problem appears when compiling test-suite/SingleSource/UnitTests/SignlessTypes/rem.c with the -Oz flag. I reduced the test to a small reproducer and will attach them here. Looking at the -print-after-all output it seems GVNHoist is to blame and the problem goes away with -gvn-max-hoisted=0 for me. I can reproduce this on a macOS system with: $ clang -Oz reduced.c $ ./a.out Floating point exception: 8 I attached a -O0 -emit-llvm .ll file for convenience but did not test whether that reproduces as well.
Created attachment 17885 [details] llvm ir reproducer
Fix for the bug: https://reviews.llvm.org/D29092
Is this a duplicate of bug 30806?
As far as I understand this bug only affects -Os and -Oz users, so PR30806 is probably not a duplicate.
After some more discussion in the fix for this bug, it may very well be the same (and just the currently proposed fix being too narrow).
bug 30806 is different. It is related to jump-threading.
(In reply to hiraditya from comment #2) > Fix for the bug: https://reviews.llvm.org/D29092 This was committed in r296642. I'll merge that to 4.0 once it's been in trunk for a bit.
Thanks Hans.
Merged to 4.0 in r296761.