Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC

Commits:

6 changed files:

Changes:

  • compiler/GHC/CmmToAsm/RV64/CodeGen.hs
    ... ... @@ -718,7 +718,7 @@ getRegister' config plat expr =
    718 718
                   ( \dst ->
    
    719 719
                       code
    
    720 720
                         `appOL` code_x
    
    721
    -                    `snocOL` annExpr expr (FCVT IntToFloat (OpReg to dst) (OpReg from reg_x)) -- (Signed ConVerT Float)
    
    721
    +                    `snocOL` annExpr expr (FCVT IntToFloat (OpReg to dst) (OpReg from reg_x) Rne) -- (Signed ConVerT Float)
    
    722 722
                   )
    
    723 723
             MO_SF_Round from to ->
    
    724 724
               pure
    
    ... ... @@ -726,7 +726,7 @@ getRegister' config plat expr =
    726 726
                   (floatFormat to)
    
    727 727
                   ( \dst ->
    
    728 728
                       code
    
    729
    -                    `snocOL` annExpr expr (FCVT IntToFloat (OpReg to dst) (OpReg from reg)) -- (Signed ConVerT Float)
    
    729
    +                    `snocOL` annExpr expr (FCVT IntToFloat (OpReg to dst) (OpReg from reg) Rne) -- (Signed ConVerT Float)
    
    730 730
                   )
    
    731 731
             -- TODO: Can this case happen?
    
    732 732
             MO_FS_Truncate from to
    
    ... ... @@ -738,7 +738,7 @@ getRegister' config plat expr =
    738 738
                           code
    
    739 739
                             `snocOL`
    
    740 740
                             -- W32 is the smallest width to convert to. Decrease width afterwards.
    
    741
    -                        annExpr expr (FCVT FloatToInt (OpReg W32 dst) (OpReg from reg))
    
    741
    +                        annExpr expr (FCVT FloatToInt (OpReg W32 dst) (OpReg from reg) Rtz)
    
    742 742
                             `appOL` signExtendAdjustPrecission W32 to dst dst -- (float convert (-> zero) signed)
    
    743 743
                       )
    
    744 744
             MO_FS_Truncate from to ->
    
    ... ... @@ -747,7 +747,7 @@ getRegister' config plat expr =
    747 747
                   (intFormat to)
    
    748 748
                   ( \dst ->
    
    749 749
                       code
    
    750
    -                    `snocOL` annExpr expr (FCVT FloatToInt (OpReg to dst) (OpReg from reg))
    
    750
    +                    `snocOL` annExpr expr (FCVT FloatToInt (OpReg to dst) (OpReg from reg) Rtz)
    
    751 751
                         `appOL` truncateReg from to dst -- (float convert (-> zero) signed)
    
    752 752
                   )
    
    753 753
             MO_UU_Conv from to
    
    ... ... @@ -769,9 +769,18 @@ getRegister' config plat expr =
    769 769
                         `appOL` truncateReg from to dst
    
    770 770
                   )
    
    771 771
             MO_SS_Conv from to -> ss_conv from to reg code
    
    772
    -        MO_FF_Conv from to -> return $ Any (floatFormat to) (\dst -> code `snocOL` annExpr e (FCVT FloatToFloat (OpReg to dst) (OpReg from reg)))
    
    772
    +        MO_FF_Conv from to -> return $ Any (floatFormat to) (\dst -> code `snocOL` annExpr e (FCVT FloatToFloat (OpReg to dst) (OpReg from reg) Rne))
    
    773 773
             MO_WF_Bitcast w    -> return $ Any (floatFormat w)  (\dst -> code `snocOL` MOV (OpReg w dst) (OpReg w reg))
    
    774
    -        MO_FW_Bitcast w    -> return $ Any (intFormat w)    (\dst -> code `snocOL` MOV (OpReg w dst) (OpReg w reg))
    
    774
    +        MO_FW_Bitcast w ->
    
    775
    +          return
    
    776
    +            $ Any
    
    777
    +              (intFormat w)
    
    778
    +              ( \dst ->
    
    779
    +                  code
    
    780
    +                    `snocOL` MOV (OpReg w dst) (OpReg w reg)
    
    781
    +                    -- FMV.X.W sign-extends the value, so truncate the result
    
    782
    +                    `appOL` truncateReg W64 w dst
    
    783
    +              )
    
    775 784
     
    
    776 785
             -- Conversions
    
    777 786
             -- TODO: Duplication with MO_UU_Conv
    

  • compiler/GHC/CmmToAsm/RV64/Instr.hs
    ... ... @@ -106,7 +106,7 @@ regUsageOfInstr platform instr = case instr of
    106 106
       LDR _ dst src -> usage (regOp src, regOp dst)
    
    107 107
       LDRU _ dst src -> usage (regOp src, regOp dst)
    
    108 108
       FENCE _ _ -> usage ([], [])
    
    109
    -  FCVT _variant dst src -> usage (regOp src, regOp dst)
    
    109
    +  FCVT _variant dst src _rm -> usage (regOp src, regOp dst)
    
    110 110
       FABS dst src -> usage (regOp src, regOp dst)
    
    111 111
       FMIN dst src1 src2 -> usage (regOp src1 ++ regOp src2, regOp dst)
    
    112 112
       FMAX dst src1 src2 -> usage (regOp src1 ++ regOp src2, regOp dst)
    
    ... ... @@ -165,6 +165,7 @@ callerSavedRegisters =
    165 165
         ++ map regSingle [t3RegNo .. t6RegNo]
    
    166 166
         ++ map regSingle [ft0RegNo .. ft7RegNo]
    
    167 167
         ++ map regSingle [fa0RegNo .. fa7RegNo]
    
    168
    +    ++ map regSingle [ft8RegNo .. ft11RegNo]
    
    168 169
     
    
    169 170
     -- | Apply a given mapping to all the register references in this instruction.
    
    170 171
     patchRegsOfInstr :: Instr -> (Reg -> Reg) -> Instr
    
    ... ... @@ -205,7 +206,7 @@ patchRegsOfInstr instr env = case instr of
    205 206
       LDR f o1 o2 -> LDR f (patchOp o1) (patchOp o2)
    
    206 207
       LDRU f o1 o2 -> LDRU f (patchOp o1) (patchOp o2)
    
    207 208
       FENCE o1 o2 -> FENCE o1 o2
    
    208
    -  FCVT variant o1 o2 -> FCVT variant (patchOp o1) (patchOp o2)
    
    209
    +  FCVT variant o1 o2 rm -> FCVT variant (patchOp o1) (patchOp o2) rm
    
    209 210
       FABS o1 o2 -> FABS (patchOp o1) (patchOp o2)
    
    210 211
       FMIN o1 o2 o3 -> FMIN (patchOp o1) (patchOp o2) (patchOp o3)
    
    211 212
       FMAX o1 o2 o3 -> FMAX (patchOp o1) (patchOp o2) (patchOp o3)
    
    ... ... @@ -612,7 +613,7 @@ data Instr
    612 613
         -- Memory barrier.
    
    613 614
         FENCE FenceType FenceType
    
    614 615
       | -- | Floating point conversion
    
    615
    -    FCVT FcvtVariant Operand Operand
    
    616
    +    FCVT FcvtVariant Operand Operand RoundingMode
    
    616 617
       | -- | Floating point ABSolute value
    
    617 618
         FABS Operand Operand
    
    618 619
     
    
    ... ... @@ -636,6 +637,21 @@ data FenceType = FenceRead | FenceWrite | FenceReadWrite
    636 637
     -- | Variant of a floating point conversion instruction
    
    637 638
     data FcvtVariant = FloatToFloat | IntToFloat | FloatToInt
    
    638 639
     
    
    640
    +-- | The rounding mode associated with an instruction
    
    641
    +data RoundingMode
    
    642
    +  = -- | Round to nearest, ties to even
    
    643
    +    Rne
    
    644
    +  | -- | Round toward zero
    
    645
    +    Rtz
    
    646
    +  | -- | Round downward (toward negative infinity)
    
    647
    +    Rdn
    
    648
    +  | -- | Round upward (toward positive infinity)
    
    649
    +    Rup
    
    650
    +  | -- | Round to nearest, ties to max magnitude
    
    651
    +    Rmm
    
    652
    +  | -- | Dynamic rounding mode
    
    653
    +    Dyn
    
    654
    +
    
    639 655
     instrCon :: Instr -> String
    
    640 656
     instrCon i =
    
    641 657
       case i of
    

  • compiler/GHC/CmmToAsm/RV64/Ppr.hs
    ... ... @@ -406,6 +406,17 @@ pprReg w r = case r of
    406 406
           -- no support for widths > W64.
    
    407 407
           | otherwise = pprPanic "Unsupported width in register (max is 64)" (ppr w <+> int i)
    
    408 408
     
    
    409
    +-- | Pretty print a rounding mode
    
    410
    +--
    
    411
    +-- If the rounding mode is omitted, 'dyn' will be used.
    
    412
    +pprRm :: IsLine doc => RoundingMode -> doc
    
    413
    +pprRm Rne = text "rne"
    
    414
    +pprRm Rtz = text "rtz"
    
    415
    +pprRm Rdn = text "rdn"
    
    416
    +pprRm Rup = text "rup"
    
    417
    +pprRm Rmm = text "rmm"
    
    418
    +pprRm Dyn = text "dyn"
    
    419
    +
    
    409 420
     -- | Single precission `Operand` (floating-point)
    
    410 421
     isSingleOp :: Operand -> Bool
    
    411 422
     isSingleOp (OpReg W32 _) = True
    
    ... ... @@ -643,25 +654,26 @@ pprInstr platform instr = case instr of
    643 654
       LDRU FF64 o1 o2@(OpAddr (AddrRegImm _ _)) -> op2 (text "\tfld") o1 o2
    
    644 655
       LDRU f o1 o2 -> pprPanic "Unsupported unsigned load" ((text . show) f <+> pprOp platform o1 <+> pprOp platform o2)
    
    645 656
       FENCE r w -> line $ text "\tfence" <+> pprFenceType r <> char ',' <+> pprFenceType w
    
    646
    -  FCVT FloatToFloat o1@(OpReg W32 _) o2@(OpReg W64 _) -> op2 (text "\tfcvt.s.d") o1 o2
    
    647
    -  FCVT FloatToFloat o1@(OpReg W64 _) o2@(OpReg W32 _) -> op2 (text "\tfcvt.d.s") o1 o2
    
    648
    -  FCVT FloatToFloat o1 o2 ->
    
    657
    +  FCVT FloatToFloat o1@(OpReg W32 _) o2@(OpReg W64 _) rm -> op2rm (text "\tfcvt.s.d") o1 o2 rm
    
    658
    +  -- The assembler seems to be unhappy with explicit rounding mode on fcvt.d.s
    
    659
    +  FCVT FloatToFloat o1@(OpReg W64 _) o2@(OpReg W32 _) _rm -> op2 (text "\tfcvt.d.s") o1 o2
    
    660
    +  FCVT FloatToFloat o1 o2 rm ->
    
    649 661
         pprPanic "RV64.pprInstr - impossible float to float conversion"
    
    650
    -      $ line (pprOp platform o1 <> text "->" <> pprOp platform o2)
    
    651
    -  FCVT IntToFloat o1@(OpReg W32 _) o2@(OpReg W32 _) -> op2 (text "\tfcvt.s.w") o1 o2
    
    652
    -  FCVT IntToFloat o1@(OpReg W32 _) o2@(OpReg W64 _) -> op2 (text "\tfcvt.s.l") o1 o2
    
    653
    -  FCVT IntToFloat o1@(OpReg W64 _) o2@(OpReg W32 _) -> op2 (text "\tfcvt.d.w") o1 o2
    
    654
    -  FCVT IntToFloat o1@(OpReg W64 _) o2@(OpReg W64 _) -> op2 (text "\tfcvt.d.l") o1 o2
    
    655
    -  FCVT IntToFloat o1 o2 ->
    
    662
    +      $ line (pprOp platform o1 <> text "->" <> pprOp platform o2 <> text "," <> pprRm rm)
    
    663
    +  FCVT IntToFloat o1@(OpReg W32 _) o2@(OpReg W32 _) rm -> op2rm (text "\tfcvt.s.w") o1 o2 rm
    
    664
    +  FCVT IntToFloat o1@(OpReg W32 _) o2@(OpReg W64 _) rm -> op2rm (text "\tfcvt.s.l") o1 o2 rm
    
    665
    +  FCVT IntToFloat o1@(OpReg W64 _) o2@(OpReg W32 _) rm -> op2rm (text "\tfcvt.d.w") o1 o2 rm
    
    666
    +  FCVT IntToFloat o1@(OpReg W64 _) o2@(OpReg W64 _) rm -> op2rm (text "\tfcvt.d.l") o1 o2 rm
    
    667
    +  FCVT IntToFloat o1 o2 rm ->
    
    656 668
         pprPanic "RV64.pprInstr - impossible integer to float conversion"
    
    657
    -      $ line (pprOp platform o1 <> text "->" <> pprOp platform o2)
    
    658
    -  FCVT FloatToInt o1@(OpReg W32 _) o2@(OpReg W32 _) -> op2 (text "\tfcvt.w.s") o1 o2
    
    659
    -  FCVT FloatToInt o1@(OpReg W32 _) o2@(OpReg W64 _) -> op2 (text "\tfcvt.w.d") o1 o2
    
    660
    -  FCVT FloatToInt o1@(OpReg W64 _) o2@(OpReg W32 _) -> op2 (text "\tfcvt.l.s") o1 o2
    
    661
    -  FCVT FloatToInt o1@(OpReg W64 _) o2@(OpReg W64 _) -> op2 (text "\tfcvt.l.d") o1 o2
    
    662
    -  FCVT FloatToInt o1 o2 ->
    
    669
    +      $ line (pprOp platform o1 <> text "->" <> pprOp platform o2 <> text "," <> pprRm rm)
    
    670
    +  FCVT FloatToInt o1@(OpReg W32 _) o2@(OpReg W32 _) rm -> op2rm (text "\tfcvt.w.s") o1 o2 rm
    
    671
    +  FCVT FloatToInt o1@(OpReg W32 _) o2@(OpReg W64 _) rm -> op2rm (text "\tfcvt.w.d") o1 o2 rm
    
    672
    +  FCVT FloatToInt o1@(OpReg W64 _) o2@(OpReg W32 _) rm -> op2rm (text "\tfcvt.l.s") o1 o2 rm
    
    673
    +  FCVT FloatToInt o1@(OpReg W64 _) o2@(OpReg W64 _) rm -> op2rm (text "\tfcvt.l.d") o1 o2 rm
    
    674
    +  FCVT FloatToInt o1 o2 rm ->
    
    663 675
         pprPanic "RV64.pprInstr - impossible float to integer conversion"
    
    664
    -      $ line (pprOp platform o1 <> text "->" <> pprOp platform o2)
    
    676
    +      $ line (pprOp platform o1 <> text "->" <> pprOp platform o2 <> text "," <> pprRm rm)
    
    665 677
       FABS o1 o2 | isSingleOp o2 -> op2 (text "\tfabs.s") o1 o2
    
    666 678
       FABS o1 o2 | isDoubleOp o2 -> op2 (text "\tfabs.d") o1 o2
    
    667 679
       FMIN o1 o2 o3 | isSingleOp o1 -> op3 (text "\tfmin.s") o1 o2 o3
    
    ... ... @@ -678,6 +690,8 @@ pprInstr platform instr = case instr of
    678 690
       instr -> panic $ "RV64.pprInstr - Unknown instruction: " ++ instrCon instr
    
    679 691
       where
    
    680 692
         op2 op o1 o2 = line $ op <+> pprOp platform o1 <> comma <+> pprOp platform o2
    
    693
    +    op2rm op o1 o2 Dyn = line $ op <+> pprOp platform o1 <> comma <+> pprOp platform o2
    
    694
    +    op2rm op o1 o2 rm = line $ op <+> pprOp platform o1 <> comma <+> pprOp platform o2 <> comma <+> pprRm rm
    
    681 695
         op3 op o1 o2 o3 = line $ op <+> pprOp platform o1 <> comma <+> pprOp platform o2 <> comma <+> pprOp platform o3
    
    682 696
         op4 op o1 o2 o3 o4 = line $ op <+> pprOp platform o1 <> comma <+> pprOp platform o2 <> comma <+> pprOp platform o3 <> comma <+> pprOp platform o4
    
    683 697
         pprFenceType FenceRead = text "r"
    

  • compiler/GHC/CmmToAsm/RV64/Regs.hs
    ... ... @@ -53,9 +53,14 @@ d7RegNo, ft7RegNo :: RegNo
    53 53
     d7RegNo = 39
    
    54 54
     ft7RegNo = d7RegNo
    
    55 55
     
    
    56
    +d28RegNo, ft8RegNo :: RegNo
    
    57
    +d28RegNo = 60
    
    58
    +ft8RegNo = d28RegNo
    
    59
    +
    
    56 60
     -- | Last floating point register.
    
    57
    -d31RegNo :: RegNo
    
    61
    +d31RegNo, ft11RegNo :: RegNo
    
    58 62
     d31RegNo = 63
    
    63
    +ft11RegNo = d31RegNo
    
    59 64
     
    
    60 65
     a0RegNo, x10RegNo :: RegNo
    
    61 66
     x10RegNo = 10
    

  • testsuite/tests/codeGen/should_run/T16617.hs
    1 1
     import GHC.Float
    
    2 2
     
    
    3
    +{-# OPAQUE noinline #-}
    
    4
    +noinline :: a -> a
    
    5
    +noinline x = x
    
    6
    +
    
    3 7
     main :: IO ()
    
    4 8
     main = do
    
    5 9
       -- As per #16617, Word32s should be non-negative
    
    6 10
       print $ castFloatToWord32 (-1)
    
    7 11
       print $ toInteger (castFloatToWord32 (-1)) > 0
    
    12
    +  -- Disable constant folding; see #27300
    
    13
    +  print $ castFloatToWord32 (noinline $ -1)
    
    14
    +  print $ toInteger (castFloatToWord32 (noinline $ -1)) > 0
    
    8 15
       -- For completeness, so should Word64s
    
    9 16
       print $ castDoubleToWord64 (-1)
    
    10 17
       print $ toInteger (castDoubleToWord64 (-1)) > 0
    
    18
    +  print $ castDoubleToWord64 (noinline $ -1)
    
    19
    +  print $ toInteger (castDoubleToWord64 (noinline $ -1)) > 0

  • testsuite/tests/codeGen/should_run/T16617.stdout
    1 1
     3212836864
    
    2 2
     True
    
    3
    +3212836864
    
    4
    +True
    
    5
    +13830554455654793216
    
    6
    +True
    
    3 7
     13830554455654793216
    
    4 8
     True