[Git][ghc/ghc][wip/supersven/riscv64-ncg] CmmInt 0 should refer to zero register

Sven Tennie (@supersven) gitlab at gitlab.haskell.org
Sat May 20 09:58:02 UTC 2023



Sven Tennie pushed to branch wip/supersven/riscv64-ncg at Glasgow Haskell Compiler / GHC


Commits:
a08a160d by Sven Tennie at 2023-05-20T11:57:23+02:00
CmmInt 0 should refer to zero register

A constant 0 can always be taken from the zero register.

- - - - -


3 changed files:

- compiler/GHC/CmmToAsm/RV64/CodeGen.hs
- compiler/GHC/CmmToAsm/RV64/Instr.hs
- + tests/compiler/cmm/zero.cmm


Changes:

=====================================
compiler/GHC/CmmToAsm/RV64/CodeGen.hs
=====================================
@@ -499,7 +499,7 @@ getRegister' config plat expr
     CmmLit lit
       -> case lit of
 
-        -- TODO handle CmmInt 0 specially, use wzr or xzr.
+        CmmInt 0 w -> pure $ Fixed (intFormat w) zero_reg nilOL
 
         CmmInt i W8 | i >= 0 -> do
           return (Any (intFormat W8) (\dst -> unitOL $ annExpr expr (MOV (OpReg W8 dst) (OpImm (ImmInteger (narrowU W8 i))))))


=====================================
compiler/GHC/CmmToAsm/RV64/Instr.hs
=====================================
@@ -793,14 +793,14 @@ opReg :: Width -> Reg -> Operand
 opReg = OpReg
 
 ra_reg, sp_reg :: Reg
+zero_reg = RegReal (RealRegSingle 0)
 ra_reg = RegReal (RealRegSingle 1)
 sp_reg = RegReal (RealRegSingle 2)
 
-xzr, wzr, sp, ip0 :: Operand
-xzr = OpReg W64 (RegReal (RealRegSingle 0))
-wzr = OpReg W32 (RegReal (RealRegSingle 0))
-ra  = OpReg W64 (RegReal (RealRegSingle 1))
-sp  = OpReg W64 (RegReal (RealRegSingle 2))
+zero, sp, ip0 :: Operand
+zero = OpReg W64 zero_reg
+ra  = OpReg W64 ra_reg
+sp  = OpReg W64 sp_reg
 gp  = OpReg W64 (RegReal (RealRegSingle 3))
 tp  = OpReg W64 (RegReal (RealRegSingle 4))
 fp  = OpReg W64 (RegReal (RealRegSingle 8))


=====================================
tests/compiler/cmm/zero.cmm
=====================================
@@ -0,0 +1,14 @@
+// RUN: "$HC" -cpp -dcmm-lint -keep-s-file -c "$1" && cat "${1%%.*}.s" | FileCheck "$1" -check-prefix=CHECK-RV64
+// RUN: "$CC" "${1%%.*}.o" -o "${1%%.*}.exe"
+// RUN: "$EXEC" "${1%%.cmm}.exe"
+
+#include "Cmm.h"
+#include "Types.h"
+
+main(){
+    I64 zero;
+    // Should refer to the zero register
+    // CHECK-RV64: addi t0, zero, 0
+    zero = 0;
+    foreign "C" exit(zero);
+}



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

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/a08a160d8bd504e80348c31c0a08844a385a1ee5
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/20230520/df07584b/attachment-0001.html>


More information about the ghc-commits mailing list