[Git][ghc/ghc][wip/T18141] GHC.Cmm.Opt: Handle MO_XX_Conv

Ben Gamari gitlab at gitlab.haskell.org
Fri May 8 19:57:01 UTC 2020



Ben Gamari pushed to branch wip/T18141 at Glasgow Haskell Compiler / GHC


Commits:
6f82de4a by Ben Gamari at 2020-05-05T17:41:48-04:00
GHC.Cmm.Opt: Handle MO_XX_Conv

This MachOp was introduced by 2c959a1894311e59cd2fd469c1967491c1e488f3
but a wildcard match in cmmMachOpFoldM hid the fact that it wasn't
handled. Ideally we would eliminate the match but this appears to be a
larger task.

Fixes #18141.

- - - - -


3 changed files:

- compiler/GHC/Cmm/Opt.hs
- + testsuite/tests/cmm/opt/T18141.hs
- testsuite/tests/cmm/opt/all.T


Changes:

=====================================
compiler/GHC/Cmm/Opt.hs
=====================================
@@ -69,6 +69,7 @@ cmmMachOpFoldM _ op [CmmLit (CmmInt x rep)]
       MO_SF_Conv _from to -> CmmLit (CmmFloat (fromInteger x) to)
       MO_SS_Conv  from to -> CmmLit (CmmInt (narrowS from x) to)
       MO_UU_Conv  from to -> CmmLit (CmmInt (narrowU from x) to)
+      MO_XX_Conv  from to -> CmmLit (CmmInt (narrowS from x) to)
 
       _ -> panic $ "cmmMachOpFoldM: unknown unary op: " ++ show op
 
@@ -76,6 +77,7 @@ cmmMachOpFoldM _ op [CmmLit (CmmInt x rep)]
 -- Eliminate conversion NOPs
 cmmMachOpFoldM _ (MO_SS_Conv rep1 rep2) [x] | rep1 == rep2 = Just x
 cmmMachOpFoldM _ (MO_UU_Conv rep1 rep2) [x] | rep1 == rep2 = Just x
+cmmMachOpFoldM _ (MO_XX_Conv rep1 rep2) [x] | rep1 == rep2 = Just x
 
 -- Eliminate nested conversions where possible
 cmmMachOpFoldM platform conv_outer [CmmMachOp conv_inner [x]]


=====================================
testsuite/tests/cmm/opt/T18141.hs
=====================================
@@ -0,0 +1,17 @@
+{-# LANGUAGE MagicHash #-}
+
+module T18141 where
+
+import GHC.Exts
+
+divInt8# :: Int8# -> Int8# -> Int8#
+x# `divInt8#` y#
+  | isTrue# (x# `gtInt8#` zero#) && isTrue# (y# `ltInt8#` zero#) =
+    ((x# `subInt8#` one#) `quotInt8#` y#) `subInt8#` one#
+  | isTrue# (x# `ltInt8#` zero#) && isTrue# (y# `gtInt8#` zero#) =
+    ((x# `plusInt8#` one#) `quotInt8#` y#) `subInt8#` one#
+  | otherwise = x# `quotInt8#` y#
+  where
+    zero# = narrowInt8# 0#
+    one# = narrowInt8# 1#
+


=====================================
testsuite/tests/cmm/opt/all.T
=====================================
@@ -1,3 +1,4 @@
 # Verify that we optimize away conditional branches which always jump
 # to the same target.
 test('T15188', normal, makefile_test, [])
+test('T18141', normal, compile, [])



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/6f82de4a5df4f14b19595f4996b58c9b901e30fc

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/6f82de4a5df4f14b19595f4996b58c9b901e30fc
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/20200508/e52e8553/attachment-0001.html>


More information about the ghc-commits mailing list