Skip to content

Constant folding integer division

Summary

In !8392 (closed) a question about minBound / (-1) for integer division came up and its unboxed primop has different behavior depending on optimizations:

let I# x = minBound in I# (quotInt# x (-1#)) == floating point exception (-O0) or minBound (-O1)

As far as I can tell this happens in core, but I am pretty sure the cmm constant folding would do the same.

Expected behavior

Both of them should crash with the floating point exception.

Environment

  • GHC version used: 8.4.4 - 9.8.2

Tested on play.haskell.org for every version available there (8.4.4 - 9.8.2) and locally on some recent version of the main branch.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information