LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 31729 - GVNHoist illegally hoists div instruction
Summary: GVNHoist illegally hoists div instruction
Status: RESOLVED FIXED
Alias: None
Product: libraries
Classification: Unclassified
Component: Scalar Optimizations (show other bugs)
Version: trunk
Hardware: PC All
: P normal
Assignee: Unassigned LLVM Bugs
URL:
Keywords:
Depends on:
Blocks: 31622
  Show dependency tree
 
Reported: 2017-01-23 20:52 PST by Matthias Braun
Modified: 2017-03-02 08:56 PST (History)
7 users (show)

See Also:
Fixed By Commit(s):


Attachments
C reproducer (782 bytes, application/octet-stream)
2017-01-23 20:52 PST, Matthias Braun
Details
llvm ir reproducer (4.45 KB, application/octet-stream)
2017-01-23 20:52 PST, Matthias Braun
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Matthias Braun 2017-01-23 20:52:04 PST
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.
Comment 1 Matthias Braun 2017-01-23 20:52:36 PST
Created attachment 17885 [details]
llvm ir reproducer
Comment 2 hiraditya 2017-01-24 12:47:47 PST
Fix for the bug: https://reviews.llvm.org/D29092
Comment 3 Martin Richtarsky 2017-02-23 12:43:55 PST
Is this a duplicate of bug 30806?
Comment 4 Matthias Braun 2017-02-23 12:57:36 PST
As far as I understand this bug only affects -Os and -Oz users, so PR30806 is probably not a duplicate.
Comment 5 Matthias Braun 2017-02-23 13:29:56 PST
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).
Comment 6 hiraditya 2017-02-24 10:24:52 PST
 bug 30806 is different. It is related to jump-threading.
Comment 7 Hans Wennborg 2017-03-01 09:39:07 PST
(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.
Comment 8 hiraditya 2017-03-01 11:38:30 PST
Thanks Hans.
Comment 9 Hans Wennborg 2017-03-02 08:56:31 PST
Merged to 4.0 in r296761.