Optimisations of comparison checks on primitive integers.
Consider a somewhat common use case of converting a `Word8` (as ASCII or latin1 character) into `Char`. This is total operation, without any quirks:
```haskell
module Word8ToChar where
import Data.Char
import Data.Word
word8ToChar :: Word8 -> Char
word8ToChar = chr . fromIntegral
```
There is a redundant check: `<= 1114111`
```haskell
word8ToChar
= \ (x_aZF :: Word8) ->
case x_aZF of { GHC.Word.W8# x#_a10E ->
let {
wild1_a10B :: GHC.Prim.Int#
[LclId]
wild1_a10B
= GHC.Prim.word2Int# (GHC.Prim.word8ToWord# x#_a10E) } in
case GHC.Prim.leWord# (GHC.Prim.int2Word# wild1_a10B) 1114111##
of {
__DEFAULT -> GHC.Char.$wlvl wild1_a10B;
1# -> GHC.Types.C# (GHC.Prim.chr# wild1_a10B)
}
}
```
and AFAICT the checks don't get optimised away later either.
---
E.g. bytestring has similar function https://hackage.haskell.org/package/bytestring-0.12.2.0/docs/src/Data.ByteString.Internal.Type.html#w2c, but it uses [`unsafeChr`](https://hackage.haskell.org/package/base-4.21.0.0/docs/GHC-Base.html#v:unsafeChr).
```haskell
word8ToChar' = unsafeChr . fromIntegral
```
```haskell
word8ToChar'
= \ (x_a100 :: Word8) ->
case x_a100 of { GHC.Word.W8# x#_a113 ->
GHC.Types.C# (chr# (word2Int# (word8ToWord# x#_a113)))
}
```
I'd like if the `chr . fromIntegral` were compiled to the same code, without explicitly relying on "unsafe" `unsafeChr`.
(I learned about existence of `unsafeChr` by looking at what others do. E.g. `text` doesn't use it (https://hackage.haskell.org/package/text-2.1.2/docs/Data-Text-Internal-Unsafe-Char.html#v:unsafeChr8), and everything else found by Hoogle seems to use `toEnum` or `chr`, i.e. has a slightly inefficient code.
issue