Redundant save and restore the GPR and SPE registers .
The following code has the redundant save and restore of r29 and r30 GPR's in PPC32.
https://godbolt.org/z/dxE36MG99
@llvm/issue-subscribers-backend-powerpc
@chmeeedalf It certainly does seem odd that we have the evstdd/evldd for these registers in 32-bit mode. And it is certainly odd that we spill/restore them as 32-bit registers as well as 64-bit registers.
@nemanjai you're right, S29 and S30 should be removed from the CalleeSavedRegs block in PPCCallingConv.td R30 looks to always be in use for something, and R29 is only in use when PIC, otherwise it's free for general use. We could either have a PIC block, or always reserve R29 from SPE.
@chmeeedalf <<always reserve R29 from SPE
that's the case for R29 ,but what about the other callee (non-volatile) save regs …its insane to save in 32 bit mode and 64 bit mode too .
Someone (forget who) mentioned a couple years ago making it save only the super registers, not the subregs. It's still not done this way yet? Saving 64-bit only seems excessive in many cases when only 32-bit is used, but I don't know how to make it determine that only the subreg is used.
@chmeeedalf
<<making it save only the super registers
Does this super spe registers are non volatile across the call ?
@UmeshKalappa0 the super registers have the same volatility as the subregs, and integer operations should only touch the subregs, per the reference:
According to the E500CORERM.pdf page 2-1 (2.1 Overview)
General-purpose registers (GPRs)—Used as source and destination operands for most operations. The e500 implements 64-bit GPRs. Book E–defined instructions access only the lower word; SPE vector instructions and embedded vector single-precision and double-precision floating-point APUs (e500v2 only) use all 64 bits. See Section 2.3.1, “General-Purpose Registers (GPRs).”
Section 2.3.1 shows:
Each GPR is a 64-bit register and can be used to contain address and integer data, although all instructions except SPE APU instructions, double-precision embedded floating-point instructions (e500v2 only), and single-precision embedded vector floating-point instructions use and return 32-bit values in GPR bits 32–63.
So ideally we should be able to just save the subregs when we only need the subregs, and the super regs when we need the full super regs.
@chmeeedalf and @nemanjai ,https://godbolt.org/z/bbM44fcvM ,still we can use stw and ld ,instead of evstdd etc ,that reduce the stack space .
@UmeshKalappa0 I agree. I thought your work in 975f4f2ddb would have addressed at least part of that.
Can it be reduced even further, by looking at the usage of the registers to decide whether to save upper or just lower?
Can it be reduced even further, by looking at the usage of the registers to decide whether to save upper or just lower? @chmeeedalf ,does PPC clang has like sub-registers class for these SPE registers ,if not we need to implement the same ,so that we know its high or low reg of the given SPE register ?
Someone (forget who) mentioned a couple years ago making it save only the super registers, not the subregs. It's still not done this way yet? Saving 64-bit only seems excessive in many cases when only 32-bit is used, but I don't know how to make it determine that only the subreg is used.
That was me, committed in 2021 in time for LLVM 14 https://github.com/llvm/llvm-project/commit/95ef464ac9d1972953709c57449ac178771cd221
Can it be reduced even further, by looking at the usage of the registers to decide whether to save upper or just lower? @chmeeedalf ,does PPC clang has like sub-registers class for these SPE registers ,if not we need to implement the same ,so that we know its high or low reg of the given SPE register ?
The SPE registers have S* and R*, with R* being sub-registers of S*. @jrtc27 mentioned in the review for 95ef464 that there's no way to track subreg and superreg separately. SPE would need to be a special case, as it's the only target I'm aware of that does treat the subreg as distinct from the superreg.
If there's a way to mark in the instruction what registers get clobbered, and trace the usage, such that if only Rn gets clobbered only save Rn, not Sn, then we'd be in good shape. Is there such a capability? Some kind of liveness marker for the function?