[Git][ghc/ghc][master] LLVM: fix MO_S_Mul2 support (#18434)
Marge Bot
gitlab at gitlab.haskell.org
Thu Jul 9 13:50:08 UTC 2020
Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC
Commits:
3656dff8 by Sylvain Henry at 2020-07-09T09:50:01-04:00
LLVM: fix MO_S_Mul2 support (#18434)
The value indicating if the carry is useful wasn't taken into account.
- - - - -
1 changed file:
- compiler/GHC/CmmToLlvm/CodeGen.hs
Changes:
=====================================
compiler/GHC/CmmToLlvm/CodeGen.hs
=====================================
@@ -353,7 +353,7 @@ genCall (PrimTarget (MO_U_Mul2 w)) [dstH, dstL] [lhs, rhs] = runStmtsDecls $ do
statement $ Store retL dstRegL
statement $ Store retH dstRegH
-genCall (PrimTarget (MO_S_Mul2 w)) [dstH, dstL] [lhs, rhs] = runStmtsDecls $ do
+genCall (PrimTarget (MO_S_Mul2 w)) [dstC, dstH, dstL] [lhs, rhs] = runStmtsDecls $ do
let width = widthToLlvmInt w
bitWidth = widthInBits w
width2x = LMInt (bitWidth * 2)
@@ -373,10 +373,18 @@ genCall (PrimTarget (MO_S_Mul2 w)) [dstH, dstL] [lhs, rhs] = runStmtsDecls $ do
retShifted <- doExprW width2x $ LlvmOp LM_MO_AShr retV widthLlvmLit
-- And extract them into retH.
retH <- doExprW width $ Cast LM_Trunc retShifted width
+ -- Check if the carry is useful by doing a full arithmetic right shift on
+ -- retL and comparing the result with retH
+ let widthLlvmLitm1 = LMLitVar $ LMIntLit (fromIntegral bitWidth - 1) width
+ retH' <- doExprW width $ LlvmOp LM_MO_AShr retL widthLlvmLitm1
+ retC1 <- doExprW i1 $ Compare LM_CMP_Ne retH retH' -- Compare op returns a 1-bit value (i1)
+ retC <- doExprW width $ Cast LM_Zext retC1 width -- so we zero-extend it
dstRegL <- getCmmRegW (CmmLocal dstL)
dstRegH <- getCmmRegW (CmmLocal dstH)
+ dstRegC <- getCmmRegW (CmmLocal dstC)
statement $ Store retL dstRegL
statement $ Store retH dstRegH
+ statement $ Store retC dstRegC
-- MO_U_QuotRem2 is another case we handle by widening the registers to double
-- the width and use normal LLVM instructions (similarly to the MO_U_Mul2). The
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/3656dff8259199d0dab2d1a1f1b887c252a9c1a3
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/3656dff8259199d0dab2d1a1f1b887c252a9c1a3
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/20200709/9f7d024f/attachment-0001.html>
More information about the ghc-commits
mailing list