[LLVMbugs] [Bug 24090] Division of signed ints incorrectly optimizes to right bitshift

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Fri Jul 10 22:55:26 PDT 2015


https://llvm.org/bugs/show_bug.cgi?id=24090

David Majnemer <david.majnemer at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |david.majnemer at gmail.com
         Resolution|---                         |INVALID

--- Comment #1 from David Majnemer <david.majnemer at gmail.com> ---
Your code relies on undefined behavior.  Because of this, LLVM's optimizations
cannot ensure your program will have the same result as an -O0 build.

angle is 315. angle / 45 is 7.  ANG45 * 7 == 536870912 * 7 == -536870912. 
Multiplying two positive signed integers cannot result in a negative number
without violating C or C++'s rules on undefined behavior: signed overflow is
undefined.

The operations you perform with 'an' assume that signed overflow does not
occur, because doing so is undefined, and thus the incongruent behavior between
-O0 and -O3.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20150711/814aee32/attachment.html>


More information about the llvm-bugs mailing list