Aarch64 - Properly handle the zero register.
Currently this is a mess.
In compiler/CodeGen.Platform.h we have
-- stack pointer / zero reg
freeReg 31 = False
Which implies we use 31 as the register number for the zero reg.
However in compiler/GHC/CmmToAsm/AArch64/Regs.hs
we have:
xzr = OpReg W64 (RegReal (RealRegSingle (-1)))
wzr = OpReg W32 (RegReal (RealRegSingle (-1)))
...
x31 = OpReg W64 (RegReal (RealRegSingle 31))
Encoding the zero register as -1 and defining a general purpose register 31 which doesn't actually exist on the platform.
We also include register 31
in
allMachRegNos :: [RegNo]
allMachRegNos = [0..31] ++ [32..63]
In the pretty printer however we define the register 31 unconditionally as the stack register.
ppr_reg_no :: Width -> Int -> SDoc
ppr_reg_no w 31
| w == W64 = text "sp"
| w == W32 = text "wsp"
The fact that this doesn't currently cause bugs is only due to two wrongs making a right in this case.
The definition freeReg 31 = False
aimed at the zero register means that the non-existant GP register x31 never ends up being allocated by the register allocator.
Edited by sheaf