diff options
author | Ben Gamari <ben@smart-cactus.org> | 2021-07-21 13:17:55 -0400 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2021-07-23 21:09:52 -0400 |
commit | b6434ed3f90f322bacc586ee08004bf4915002f9 (patch) | |
tree | 67db1034eea6b27ea1a88e7638131d407f179032 | |
parent | efaad7add092c88eab46e00a9f349d4675bbee06 (diff) | |
download | haskell-b6434ed3f90f322bacc586ee08004bf4915002f9.tar.gz |
Cmm.Opt: Fix type of shift amount in constant folding
Previously the `MO_S_Quot` constant folding rule would incorrectly pass
the shift amount of the same width as the shifted value. However, the
machop's type expects the shift amount to be a Word.
Fixes #20142.
-rw-r--r-- | compiler/GHC/Cmm/Opt.hs | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/compiler/GHC/Cmm/Opt.hs b/compiler/GHC/Cmm/Opt.hs index 6a2945c4f8..8035d7b2bd 100644 --- a/compiler/GHC/Cmm/Opt.hs +++ b/compiler/GHC/Cmm/Opt.hs @@ -357,7 +357,7 @@ cmmMachOpFoldM platform mop [x, (CmmLit (CmmInt n _))] CmmReg _ <- x -> -- We duplicate x in signedQuotRemHelper, hence require -- it is a reg. FIXME: remove this restriction. Just $! (cmmMachOpFold platform (MO_S_Shr rep) - [signedQuotRemHelper rep p, CmmLit (CmmInt p rep)]) + [signedQuotRemHelper rep p, CmmLit (CmmInt p $ wordWidth platform)]) MO_S_Rem rep | Just p <- exactLog2 n, CmmReg _ <- x -> -- We duplicate x in signedQuotRemHelper, hence require @@ -391,7 +391,7 @@ cmmMachOpFoldM platform mop [x, (CmmLit (CmmInt n _))] where bits = fromIntegral (widthInBits rep) - 1 shr = if p == 1 then MO_U_Shr rep else MO_S_Shr rep - x1 = CmmMachOp shr [x, CmmLit (CmmInt bits rep)] + x1 = CmmMachOp shr [x, CmmLit (CmmInt bits $ wordWidth platform)] x2 = if p == 1 then x1 else CmmMachOp (MO_And rep) [x1, CmmLit (CmmInt (n-1) rep)] |