Andreas Klebinger pushed to branch wip/andreask/arm-ffi at Glasgow Haskell Compiler / GHC Commits: bf2663c0 by Andreas Klebinger at 2026-07-14T19:45:07+02:00 Wibbles - - - - - 1 changed file: - compiler/GHC/CmmToAsm/AArch64/CodeGen.hs Changes: ===================================== compiler/GHC/CmmToAsm/AArch64/CodeGen.hs ===================================== @@ -358,43 +358,6 @@ data Register = Fixed Format Reg InstrBlock | Any Format (Reg -> InstrBlock) -registerFormat :: Register -> Format -registerFormat reg = case reg of { Fixed format _ _ -> format; Any format _ -> format } --- | Sometimes we need to change the Format of a register. Primarily during --- conversion. When shrinking the register below machine word size we zero the high --- bits. See Note [Signed arithmetic on AArch64] - -swizzleRegisterRep :: Width -> Format -> Register -> Register -swizzleRegisterRep old_width format reg - -- APK: Currently this assertion doesn't always hold. - -- This seems problematic but will have to be fixed another time. - | (reg_width /= old_width) - , pprTrace "Missmatched widths" (ppr (old_width, format, reg)) False - = undefined - - | old_width == formatToWidth format = - reg - -- The CMM needs to expect garbage in high bits so this is fine. - | old_width < f_width || format >= II32 = - reg - | otherwise = truncateSmaller reg - where - f_width = formatToWidth format - reg_width = formatToWidth (registerFormat reg) - trunc_instr = case f_width of - W8 -> UXTB - W16 -> UXTH - _ -> panic "unexpected width" - truncateSmaller (Fixed _fmt_in reg old_code) = - let reg_code = old_code `snocOL` - trunc_instr (OpReg old_width reg) (OpReg W32 reg) - in Fixed format reg reg_code - truncateSmaller (Any _fmt_in codefn) = - let reg_code = \reg -> - codefn reg `snocOL` - trunc_instr (OpReg old_width reg) (OpReg W32 reg) - in Any format reg_code - -- | Grab the Reg for a CmmReg getRegisterReg :: Platform -> CmmReg -> Reg @@ -983,7 +946,13 @@ getRegister' config plat expr where fmt = intFormat w -- Conversions - MO_XX_Conv from to -> swizzleRegisterRep from (intFormat to) <$> getRegister e + MO_XX_Conv from to + | to >= W32 || to > from -> + -- We don't care about garbage high bits when upcasting this way. + pure $ Fixed (intFormat to) reg code + | otherwise -> do + (trunc_reg, code_trunc) <- truncateReg from to reg + return $ Fixed (intFormat to) trunc_reg (code `appOL` code_trunc) -- Vector MO_V_Broadcast l w -> return $ Any fmt (\dst -> code `snocOL` DUP fmt (OpReg vw dst) (OpScalarAsVec w reg)) @@ -1929,7 +1898,7 @@ signExtendReg w w' r = | otherwise -> extend SXTW W16 -> extend SXTH W8 -> extend SXTB - _ -> panic "intOp" + _ -> panic "signExtendReg:unexpectedWidth" where noop = return (r, nilOL) extend instr = do @@ -1939,20 +1908,20 @@ signExtendReg w w' r = -- | Instructions to truncate (zero extend) the value in the given register from width @w@ -- down to width @w'@ into a new register. Or return the original register if it's a noop. truncateReg :: Width -> Width -> Reg -> NatM (Reg, OrdList Instr) -truncateReg w w' r = do - case w' of +truncateReg w_from w_to r = do + case w_to of W64 -> noop W32 - | w' == W32 -> noop + | w_from == W32 -> noop | otherwise -> trunc MOV W16 -> trunc UXTH W8 -> trunc UXTB - _ -> panic "intOp" + _ -> panic "truncateReg:unexpectedWidth" where noop = return (r, nilOL) trunc instr = do - r' <- getNewRegNat (intFormat w') - return (r', unitOL $ instr (OpReg w' r') (OpReg w r)) + r' <- getNewRegNat (intFormat w_to) + return (r', unitOL $ instr (OpReg W32 r') (OpReg W32 r)) -- | Instructions to truncate (zero extend) the value in the given register from width @w@ -- down to width @w'@. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/bf2663c0954db0ee04db6e8a8ae30f58... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/bf2663c0954db0ee04db6e8a8ae30f58... You're receiving this email because of your account on gitlab.haskell.org. Manage all notifications: https://gitlab.haskell.org/-/profile/notifications | Help: https://gitlab.haskell.org/help
participants (1)
-
Andreas Klebinger (@AndreasK)