[Git][ghc/ghc][wip/marge_bot_batch_merge_job] 4 commits: Redirect output of musttail attribute test

Marge Bot (@marge-bot) gitlab at gitlab.haskell.org
Mon Nov 28 15:47:34 UTC 2022



Marge Bot pushed to branch wip/marge_bot_batch_merge_job at Glasgow Haskell Compiler / GHC


Commits:
2da5c38a by Will Hawkins at 2022-11-26T04:05:04-05:00
Redirect output of musttail attribute test

Compilation output from test for support of musttail attribute leaked to
the console.

- - - - -
0eb1c331 by Cheng Shao at 2022-11-28T08:55:53+00:00
Move hs_mulIntMayOflo cbits to ghc-prim

It's only used by wasm NCG at the moment, but ghc-prim is a more
reasonable place for hosting out-of-line primops. Also, we only need a
single version of hs_mulIntMayOflo.

- - - - -
36b53a9d by Cheng Shao at 2022-11-28T09:05:57+00:00
compiler: generate ccalls for clz/ctz/popcnt in wasm NCG

We used to generate a single wasm clz/ctz/popcnt opcode, but it's
wrong when it comes to subwords, so might as well generate ccalls for
them. See #22470 for details.

- - - - -
ac928c5e by Cheng Shao at 2022-11-28T10:47:22-05:00
compiler: remove unused MO_U_MulMayOflo

We actually only emit MO_S_MulMayOflo and never emit MO_U_MulMayOflo anywhere.

- - - - -


13 changed files:

- compiler/GHC/Cmm/MachOp.hs
- compiler/GHC/Cmm/Parser.y
- compiler/GHC/CmmToAsm/AArch64/CodeGen.hs
- compiler/GHC/CmmToAsm/Wasm/Asm.hs
- compiler/GHC/CmmToAsm/Wasm/FromCmm.hs
- compiler/GHC/CmmToAsm/Wasm/Types.hs
- compiler/GHC/CmmToC.hs
- compiler/GHC/CmmToLlvm/CodeGen.hs
- + libraries/ghc-prim/cbits/mulIntMayOflo.c
- libraries/ghc-prim/ghc-prim.cabal
- m4/fp_musttail.m4
- rts/rts.cabal.in
- − rts/wasm/Ops.c


Changes:

=====================================
compiler/GHC/Cmm/MachOp.hs
=====================================
@@ -65,7 +65,6 @@ data MachOp
   | MO_S_Neg  Width             -- unary -
 
   -- Unsigned multiply/divide
-  | MO_U_MulMayOflo Width       -- nonzero if unsigned multiply overflows
   | MO_U_Quot Width             -- unsigned / (same semantics as WordQuotOp)
   | MO_U_Rem  Width             -- unsigned % (same semantics as WordRemOp)
 
@@ -251,7 +250,6 @@ isCommutableMachOp mop =
         MO_Ne _                 -> True
         MO_Mul _                -> True
         MO_S_MulMayOflo _       -> True
-        MO_U_MulMayOflo _       -> True
         MO_And _                -> True
         MO_Or _                 -> True
         MO_Xor _                -> True
@@ -379,7 +377,6 @@ machOpResultType platform mop tys =
     MO_S_Quot r         -> cmmBits r
     MO_S_Rem  r         -> cmmBits r
     MO_S_Neg  r         -> cmmBits r
-    MO_U_MulMayOflo r   -> cmmBits r
     MO_U_Quot r         -> cmmBits r
     MO_U_Rem  r         -> cmmBits r
 
@@ -473,7 +470,6 @@ machOpArgReps platform op =
     MO_S_Quot r         -> [r,r]
     MO_S_Rem  r         -> [r,r]
     MO_S_Neg  r         -> [r]
-    MO_U_MulMayOflo r   -> [r,r]
     MO_U_Quot r         -> [r,r]
     MO_U_Rem  r         -> [r,r]
 


=====================================
compiler/GHC/Cmm/Parser.y
=====================================
@@ -961,7 +961,6 @@ machOps = listToUFM $
         ( "ne",         MO_Ne ),
         ( "mul",        MO_Mul ),
         ( "mulmayoflo",  MO_S_MulMayOflo ),
-        ( "mulmayoflou", MO_U_MulMayOflo ),
         ( "neg",        MO_S_Neg ),
         ( "quot",       MO_S_Quot ),
         ( "rem",        MO_S_Rem ),


=====================================
compiler/GHC/CmmToAsm/AArch64/CodeGen.hs
=====================================
@@ -910,7 +910,6 @@ getRegister' config plat expr
                       intOp True w (\d x y -> toOL [ SDIV t x y, MSUB d t y x ])
 
         -- Unsigned multiply/divide
-        MO_U_MulMayOflo _w -> unsupportedP plat expr
         MO_U_Quot w -> intOp False w (\d x y -> unitOL $ UDIV d x y)
         MO_U_Rem w  -> withTempIntReg w $ \t ->
                        intOp False w (\d x y -> toOL [ UDIV t x y, MSUB d t y x ])
@@ -962,9 +961,6 @@ getRegister' config plat expr
       -> pprPanic "getRegister' (variadic CmmMachOp): " (pdoc plat expr)
 
   where
-    unsupportedP :: OutputableP env a => env -> a -> b
-    unsupportedP platform op = pprPanic "Unsupported op:" (pdoc platform op)
-
     isNbitEncodeable :: Int -> Integer -> Bool
     isNbitEncodeable n i = let shift = n - 1 in (-1 `shiftL` shift) <= i && i < (1 `shiftL` shift)
     -- This needs to check if n can be encoded as a bitmask immediate:


=====================================
compiler/GHC/CmmToAsm/Wasm/Asm.hs
=====================================
@@ -308,9 +308,6 @@ asmTellWasmInstr ty_word instr = case instr of
   WasmConvert Unsigned t0 t1 ->
     asmTellLine $
       asmFromWasmType t1 <> ".convert_" <> asmFromWasmType t0 <> "_u"
-  WasmClz ty -> asmTellLine $ asmFromWasmType ty <> ".clz"
-  WasmCtz ty -> asmTellLine $ asmFromWasmType ty <> ".ctz"
-  WasmPopcnt ty -> asmTellLine $ asmFromWasmType ty <> ".popcnt"
   WasmAdd ty -> asmTellLine $ asmFromWasmType ty <> ".add"
   WasmSub ty -> asmTellLine $ asmFromWasmType ty <> ".sub"
   WasmMul ty -> asmTellLine $ asmFromWasmType ty <> ".mul"


=====================================
compiler/GHC/CmmToAsm/Wasm/FromCmm.hs
=====================================
@@ -443,27 +443,22 @@ lower_MO_S_Shr lbl w0 [x, y] = case someWasmTypeFromCmmType (cmmBits w0) of
 lower_MO_S_Shr _ _ _ = panic "lower_MO_S_Shr: unreachable"
 
 -- | Lower a 'MO_MulMayOflo' operation. It's translated to a ccall to
--- one of the @hs_mulIntMayOflo@ functions in rts/wasm/Ops.c,
+-- @hs_mulIntMayOflo@ function in @ghc-prim/cbits/mulIntMayOflo@,
 -- otherwise it's quite non-trivial to implement as inline assembly.
 lower_MO_MulMayOflo ::
-  CLabel ->
-  Width ->
-  [CmmExpr] ->
-  WasmCodeGenM
-    w
-    (SomeWasmExpr w)
+  CLabel -> Width -> [CmmExpr] -> WasmCodeGenM w (SomeWasmExpr w)
 lower_MO_MulMayOflo lbl w0 [x, y] = case someWasmTypeFromCmmType ty_cmm of
   SomeWasmType ty -> do
     WasmExpr x_instr <- lower_CmmExpr_Typed lbl ty x
     WasmExpr y_instr <- lower_CmmExpr_Typed lbl ty y
-    onFuncSym f [ty_cmm, ty_cmm] [ty_cmm]
+    onFuncSym "hs_mulIntMayOflo" [ty_cmm, ty_cmm] [ty_cmm]
     pure $
       SomeWasmExpr ty $
         WasmExpr $
-          x_instr `WasmConcat` y_instr `WasmConcat` WasmCCall f
+          x_instr
+            `WasmConcat` y_instr
+            `WasmConcat` WasmCCall "hs_mulIntMayOflo"
   where
-    f = fromString $ "hs_mulIntMayOflo" <> show (widthInBits w0)
-
     ty_cmm = cmmBits w0
 lower_MO_MulMayOflo _ _ _ = panic "lower_MO_MulMayOflo: unreachable"
 
@@ -661,7 +656,6 @@ lower_CmmMachOp lbl (MO_S_Neg w0) [x] =
     lbl
     (MO_Sub w0)
     [CmmLit $ CmmInt 0 w0, x]
-lower_CmmMachOp lbl (MO_U_MulMayOflo w0) xs = lower_MO_MulMayOflo lbl w0 xs
 lower_CmmMachOp lbl (MO_U_Quot w0) xs =
   lower_MO_Bin_Homo
     (WasmDiv Unsigned)
@@ -1243,8 +1237,13 @@ lower_CallishMachOp lbl (MO_Memcmp {}) rs xs =
     CmmMayReturn
     rs
     xs
-lower_CallishMachOp lbl (MO_PopCnt {}) rs xs =
-  lower_CMO_Un_Prim lbl WasmPopcnt rs xs
+lower_CallishMachOp lbl (MO_PopCnt w0) rs xs =
+  lower_CmmUnsafeForeignCall
+    lbl
+    (Left $ fromString $ "hs_popcnt" <> show (widthInBits w0))
+    CmmMayReturn
+    rs
+    xs
 lower_CallishMachOp lbl (MO_Pdep w0) rs xs =
   lower_CmmUnsafeForeignCall
     lbl
@@ -1259,8 +1258,20 @@ lower_CallishMachOp lbl (MO_Pext w0) rs xs =
     CmmMayReturn
     rs
     xs
-lower_CallishMachOp lbl (MO_Clz {}) rs xs = lower_CMO_Un_Prim lbl WasmClz rs xs
-lower_CallishMachOp lbl (MO_Ctz {}) rs xs = lower_CMO_Un_Prim lbl WasmCtz rs xs
+lower_CallishMachOp lbl (MO_Clz w0) rs xs =
+  lower_CmmUnsafeForeignCall
+    lbl
+    (Left $ fromString $ "hs_clz" <> show (widthInBits w0))
+    CmmMayReturn
+    rs
+    xs
+lower_CallishMachOp lbl (MO_Ctz w0) rs xs =
+  lower_CmmUnsafeForeignCall
+    lbl
+    (Left $ fromString $ "hs_ctz" <> show (widthInBits w0))
+    CmmMayReturn
+    rs
+    xs
 lower_CallishMachOp lbl (MO_BSwap w0) rs xs =
   lower_CmmUnsafeForeignCall
     lbl


=====================================
compiler/GHC/CmmToAsm/Wasm/Types.hs
=====================================
@@ -279,9 +279,6 @@ data WasmInstr :: WasmType -> [WasmType] -> [WasmType] -> Type where
       w
       (t0 : pre)
       (t1 : pre)
-  WasmClz :: WasmTypeTag t -> WasmInstr w (t : pre) (t : pre)
-  WasmCtz :: WasmTypeTag t -> WasmInstr w (t : pre) (t : pre)
-  WasmPopcnt :: WasmTypeTag t -> WasmInstr w (t : pre) (t : pre)
   WasmAdd :: WasmTypeTag t -> WasmInstr w (t : t : pre) (t : pre)
   WasmSub :: WasmTypeTag t -> WasmInstr w (t : t : pre) (t : pre)
   WasmMul :: WasmTypeTag t -> WasmInstr w (t : t : pre) (t : pre)


=====================================
compiler/GHC/CmmToC.hs
=====================================
@@ -430,8 +430,7 @@ pprMachOpApp :: Platform -> MachOp -> [CmmExpr] -> SDoc
 pprMachOpApp platform op args
   | isMulMayOfloOp op
   = text "mulIntMayOflo" <> parens (commafy (map (pprExpr platform) args))
-  where isMulMayOfloOp (MO_U_MulMayOflo _) = True
-        isMulMayOfloOp (MO_S_MulMayOflo _) = True
+  where isMulMayOfloOp (MO_S_MulMayOflo _) = True
         isMulMayOfloOp _ = False
 
 pprMachOpApp platform mop args
@@ -775,10 +774,6 @@ pprMachOp_for_C platform mop = case mop of
                                 (text "MO_S_MulMayOflo")
                                 (panic $ "PprC.pprMachOp_for_C: MO_S_MulMayOflo"
                                       ++ " should have been handled earlier!")
-        MO_U_MulMayOflo _ -> pprTrace "offending mop:"
-                                (text "MO_U_MulMayOflo")
-                                (panic $ "PprC.pprMachOp_for_C: MO_U_MulMayOflo"
-                                      ++ " should have been handled earlier!")
 
         MO_V_Insert {}    -> pprTrace "offending mop:"
                                 (text "MO_V_Insert")


=====================================
compiler/GHC/CmmToLlvm/CodeGen.hs
=====================================
@@ -1451,7 +1451,6 @@ genMachOp _ op [x] = case op of
     MO_S_MulMayOflo _ -> panicOp
     MO_S_Quot _       -> panicOp
     MO_S_Rem _        -> panicOp
-    MO_U_MulMayOflo _ -> panicOp
     MO_U_Quot _       -> panicOp
     MO_U_Rem _        -> panicOp
 
@@ -1633,8 +1632,6 @@ genMachOp_slow opt op [x, y] = case op of
     MO_Sub _ -> genBinMach LM_MO_Sub
     MO_Mul _ -> genBinMach LM_MO_Mul
 
-    MO_U_MulMayOflo _ -> panic "genMachOp: MO_U_MulMayOflo unsupported!"
-
     MO_S_MulMayOflo w -> isSMulOK w x y
 
     MO_S_Quot _ -> genBinMach LM_MO_SDiv


=====================================
libraries/ghc-prim/cbits/mulIntMayOflo.c
=====================================
@@ -0,0 +1,3 @@
+#include "Rts.h"
+
+W_ hs_mulIntMayOflo(W_ a, W_ b) { return mulIntMayOflo(a, b); }


=====================================
libraries/ghc-prim/ghc-prim.cabal
=====================================
@@ -89,6 +89,7 @@ Library
         cbits/ctz.c
         cbits/debug.c
         cbits/longlong.c
+        cbits/mulIntMayOflo.c
         cbits/pdep.c
         cbits/pext.c
         cbits/popcnt.c


=====================================
m4/fp_musttail.m4
=====================================
@@ -5,7 +5,7 @@ AC_DEFUN([FP_MUSTTAIL],
 [
     AC_MSG_CHECKING([whether __attribute__((musttail)) is supported])
     echo 'extern int foo(void); int bar(void) { __attribute__((musttail)) return foo(); }' > conftest.c
-    if $CC -c conftest.c -o conftest.o
+    if $CC -c conftest.c -o conftest.o > /dev/null 2>&1
     then
         AC_MSG_RESULT([yes])
         AC_DEFINE(HAS_MUSTTAIL, 1, [Has musttail])


=====================================
rts/rts.cabal.in
=====================================
@@ -615,7 +615,6 @@ library
       asm-sources: wasm/Wasm.S
       c-sources: wasm/StgRun.c
                  wasm/GetTime.c
-                 wasm/Ops.c
                  wasm/OSMem.c
                  wasm/OSThreads.c
                  posix/Select.c


=====================================
rts/wasm/Ops.c deleted
=====================================
@@ -1,9 +0,0 @@
-#include "Stg.h"
-
-StgWord8 hs_mulIntMayOflo8(StgWord8 _0, StgWord8 _1) { return mulIntMayOflo(_0, _1); }
-
-StgWord16 hs_mulIntMayOflo16(StgWord16 _0, StgWord16 _1) { return mulIntMayOflo(_0, _1); }
-
-StgWord32 hs_mulIntMayOflo32(StgWord32 _0, StgWord32 _1) { return mulIntMayOflo(_0, _1); }
-
-StgWord64 hs_mulIntMayOflo64(StgWord64 _0, StgWord64 _1) { return mulIntMayOflo(_0, _1); }



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/e10c3df1b21f1b97a4ca45d9e5c5adf1b0a83987...ac928c5e512b519185959030b79de1bf3a5ef8eb

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/e10c3df1b21f1b97a4ca45d9e5c5adf1b0a83987...ac928c5e512b519185959030b79de1bf3a5ef8eb
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/20221128/d4c00b6d/attachment-0001.html>


More information about the ghc-commits mailing list