id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc	os	architecture	failure	difficulty	testcase	blockedby	blocking	related
3744	Comparisons against minBound/maxBound not optimised	rl		"{{{
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 }

}}}
"	bug	new	low	7.6.2	Compiler	6.13			daniel.is.fischer@… michal.terepeta@…	Unknown/Multiple	Unknown/Multiple	Runtime performance bug					
