scrutinee constant folding produces wrong answer when remapped values are out of bounds
This program should output 2, but in 8.1 with -O enabled it outputs 3. The problem is with the way that scrutinee constant folding rewrites the case.
f :: Word -> Word
f n = case n+1 of
0 -> 2
_ -> 3
{-# NOINLINE f #-}
main = print (f (-1))
Core with 8.1 and -O:
f [InlPrag=NOINLINE] :: Word -> Word
[GblId, Arity=1, Caf=NoCafRefs, Str=<S(S),1*U(1*U)>m]
f =
\ (n_ay2 :: Word) ->
case n_ay2 of { GHC.Types.W# x#_a1SL ->
case x#_a1SL of {
__DEFAULT -> lvl_r4lD;
-1## -> lvl1_r4mD
}
}
Apparently -1## isn't okay: it needs to be 9223372036854775807##.
Trac metadata
| Trac field | Value |
|---|---|
| Version | 8.1 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | highest |
| Resolution | Unresolved |
| Component | Compiler |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture |