summaryrefslogtreecommitdiff
path: root/compiler/GHC/StgToCmm
diff options
context:
space:
mode:
authorSylvain Henry <sylvain@haskus.fr>2021-07-26 12:01:51 +0200
committerJohn Ericson <John.Ericson@Obsidian.Systems>2021-08-17 21:01:44 +0000
commit5798357d9396c62a07413b1ee8ab3515526cf1e7 (patch)
tree8fa4b3f7e5b993632d0bfb244558d498d1147b25 /compiler/GHC/StgToCmm
parentb784a51eb1cf084353e369d48643d64008b61b4a (diff)
downloadhaskell-5798357d9396c62a07413b1ee8ab3515526cf1e7.tar.gz
StgToCmm: use correct bounds for switches on sized valueswip/byte-switch
StgToCmm was only using literals signedness to determine whether using Int and Word range in Cmm switches. Now that we have sized literals (Int8#, Int16#, etc.), it needs to take their ranges into account.
Diffstat (limited to 'compiler/GHC/StgToCmm')
-rw-r--r--compiler/GHC/StgToCmm/Utils.hs19
1 files changed, 13 insertions, 6 deletions
diff --git a/compiler/GHC/StgToCmm/Utils.hs b/compiler/GHC/StgToCmm/Utils.hs
index 4913bbd3ce..934fd6d726 100644
--- a/compiler/GHC/StgToCmm/Utils.hs
+++ b/compiler/GHC/StgToCmm/Utils.hs
@@ -454,12 +454,19 @@ emitCmmLitSwitch scrut branches deflt = do
rep = typeWidth cmm_ty
-- We find the necessary type information in the literals in the branches
- let signed = case head branches of
- (LitNumber nt _, _) -> litNumIsSigned nt
- _ -> False
-
- let range | signed = (platformMinInt platform, platformMaxInt platform)
- | otherwise = (0, platformMaxWord platform)
+ let (signed,range) = case head branches of
+ (LitNumber nt _, _) -> (signed,range)
+ where
+ signed = litNumIsSigned nt
+ range = case litNumRange platform nt of
+ (Just mi, Just ma) -> (mi,ma)
+ -- unbounded literals (Natural and
+ -- Integer) must have been
+ -- lowered at this point
+ partial_bounds -> pprPanic "Unexpected unbounded literal range"
+ (ppr partial_bounds)
+ -- assuming native word range
+ _ -> (False, (0, platformMaxWord platform))
if isFloatType cmm_ty
then emit =<< mk_float_switch rep scrut' deflt_lbl noBound branches_lbls