Comparisons against minBound/maxBound not optimised for (Int|Word)(8|16|32)
foo :: Int -> Bool
foo n = n < minBound || n > maxBound
GHC retains both comparisons even though they are guaranteed to be False. This also happens for other integral types. The optimisation is fairly easy to implement for Int
and Word
(only requires some plumbing in !PrelRules) but it's not clear what to do about smaller integral types. For Int64
and Word64
, GHC doesn't even inline minBound
and maxBound
:
T.$wfoo :: GHC.Prim.Int64# -> GHC.Bool.Bool
T.$wfoo =
\ (ww_ss5 :: GHC.Prim.Int64#) ->
case GHC.Int.$fBoundedInt64_$cminBound
of _ { GHC.Int.I64# y#_are ->
case {__ccall hs_ltInt64 GHC.Prim.Int64#
-> GHC.Prim.Int64#
-> GHC.Prim.State# GHC.Prim.RealWorld
-> (# GHC.Prim.State# GHC.Prim.RealWorld, GHC.Prim.Int# #)}_arD
ww_ss5 y#_are GHC.Prim.realWorld#
of _ { (# _, ds3_arH #) ->
case ds3_arH of _ {
__DEFAULT -> GHC.Bool.True;
0 ->
case GHC.Int.$fBoundedInt64_$cmaxBound
of _ { GHC.Int.I64# y#1_ar4 ->
GHC.IntWord64.gtInt64# ww_ss5 y#1_ar4
}
}
}
}
T.foo :: GHC.Int.Int64 -> GHC.Bool.Bool
T.foo =
\ (w_ss3 :: GHC.Int.Int64) ->
case w_ss3 of _ { GHC.Int.I64# ww_ss5 -> T.$wfoo ww_ss5 }
Trac metadata
Trac field | Value |
---|---|
Version | 6.13 |
Type | Bug |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | Compiler |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | |
Architecture |