[Git][ghc/ghc][wip/ncg-simd] use MOVU instructions for spill/unspill

sheaf (@sheaf) gitlab at gitlab.haskell.org
Sat Jun 8 12:39:29 UTC 2024



sheaf pushed to branch wip/ncg-simd at Glasgow Haskell Compiler / GHC


Commits:
3ed919cf by sheaf at 2024-06-08T14:38:42+02:00
use MOVU instructions for spill/unspill

- - - - -


2 changed files:

- compiler/GHC/CmmToAsm/X86/Instr.hs
- compiler/GHC/CmmToAsm/X86/Ppr.hs


Changes:

=====================================
compiler/GHC/CmmToAsm/X86/Instr.hs
=====================================
@@ -363,6 +363,7 @@ data Instr
         | MOVU        Format Operand Operand
         | MOVL        Format Operand Operand
         | MOVH        Format Operand Operand
+        | MOVA        Format Operand Operand
 
         -- logic operations
         | VPXOR       Format Reg Reg Reg
@@ -503,6 +504,7 @@ regUsageOfInstr platform instr
 
     VMOVU        fmt src dst   -> mkRU fmt (use_R src []) (use_R dst [])
     MOVU         fmt src dst   -> mkRU fmt (use_R src []) (use_R dst [])
+    MOVA         fmt src dst   -> mkRU fmt (use_R src []) (use_R dst [])
     MOVL         fmt src dst   -> mkRU fmt (use_R src []) (use_R dst [])
     MOVH         fmt src dst   -> mkRU fmt (use_R src []) (use_R dst [])
     VPXOR        fmt s1 s2 dst -> mkRU fmt [s1,s2] [dst]
@@ -709,6 +711,7 @@ patchRegsOfInstr instr env
 
     VMOVU      fmt src dst   -> VMOVU fmt (patchOp src) (patchOp dst)
     MOVU       fmt src dst   -> MOVU  fmt (patchOp src) (patchOp dst)
+    MOVA       fmt src dst   -> MOVA  fmt (patchOp src) (patchOp dst)
     MOVL       fmt src dst   -> MOVL  fmt (patchOp src) (patchOp dst)
     MOVH       fmt src dst   -> MOVH  fmt (patchOp src) (patchOp dst)
     VPXOR      fmt s1 s2 dst -> VPXOR fmt (env s1) (env s2) (env dst)
@@ -826,16 +829,14 @@ mkSpillInstr
     -> [Instr]
 
 mkSpillInstr config reg fmt delta slot
-  = let off s = spillSlotToOffset platform s - delta
+  = let off = spillSlotToOffset platform slot - delta
     in case fmt of
-        VecFormat {} ->
+        VecFormat {}
           -- SIMD NCG TODO: panic for unsupported VecFormats (& same in mkLoadInstr)
-          [MOV FF64 (OpReg reg) (OpAddr (spRel platform $ off slot))
-           -- Now shuffle the register, putting the high half into the lower half.
-          ,SHUFPD fmt (ImmInt 0b01) (OpReg reg) reg
-            -- SIMD NCG TODO: can we emit more efficient code here?
-          ,MOV FF64 (OpReg reg) (OpAddr (spRel platform $ off (slot + 1)))]
-        _ -> [MOV fmt (OpReg reg) (OpAddr (spRel platform $ off slot))]
+          -> [MOVU fmt (OpReg reg) (OpAddr (spRel platform off))]
+            -- NB: not using MOVA because we have no guarantees about the stack
+            -- being sufficiently aligned, including even numbered stack slots.
+        _ -> [MOV fmt (OpReg reg) (OpAddr (spRel platform off))]
     where platform = ncgPlatform config
 
 -- | Make a spill reload instruction.
@@ -848,14 +849,14 @@ mkLoadInstr
     -> [Instr]
 
 mkLoadInstr config reg fmt delta slot
-  = let off s     = spillSlotToOffset platform s - delta
-    in
-        case fmt of
-              VecFormat {} ->
-                -- SIMD NCG TODO: panic on unsupported VecFormats
-                [MOVH (VecFormat 2 FmtDouble W64) (OpAddr (spRel platform $ off (slot + 1))) (OpReg reg)
-                ,MOVL (VecFormat 2 FmtDouble W64) (OpAddr (spRel platform $ off slot)) (OpReg reg)]
-              _ -> [MOV fmt (OpAddr (spRel platform $ off slot)) (OpReg reg)]
+  = let off = spillSlotToOffset platform slot - delta
+    in case fmt of
+          VecFormat {}
+            -- SIMD NCG TODO: panic for unsupported VecFormats (& same in mkLoadInstr)
+            -> [MOVU fmt (OpAddr (spRel platform off)) (OpReg reg)]
+            -- NB: not using MOVA because we have no guarantees about the stack
+            -- being sufficiently aligned, including even numbered stack slots.
+          _ -> [MOV fmt (OpAddr (spRel platform off)) (OpReg reg)]
 
     where platform = ncgPlatform config
 


=====================================
compiler/GHC/CmmToAsm/X86/Ppr.hs
=====================================
@@ -928,6 +928,8 @@ pprInstr platform i = case i of
      -> pprFormatOpOp (text "vmovu") format from to
    MOVU format from to
      -> pprFormatOpOp (text "movu") format from to
+   MOVA format from to
+     -> pprFormatOpOp (text "mova") format from to
    MOVL format from to
      -> pprFormatOpOp (text "movl") format from to
    MOVH format from to



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/3ed919cf1ad69b0ee05954e79f4e9c38bc0319aa

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/3ed919cf1ad69b0ee05954e79f4e9c38bc0319aa
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20240608/456bfc3b/attachment-0001.html>


More information about the ghc-commits mailing list