[llvm] [PPC]Optimize zeroing accumulator and spilling instructions into simple instructions (PR #96094)
zhijian lin via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 8 10:21:07 PDT 2024
================
@@ -109,6 +109,93 @@ static bool hasPCRelativeForm(MachineInstr &Use) {
MachineFunctionProperties::Property::NoVRegs);
}
+ // The funtion will simply the zeroing accumulator and spilling instrcutions
+ // into simple xxlxor and spilling instrcuctions.
+ // From:
+ // setaccz acci
+ // xxmfacc acci
+ // stxv vsr(i*4+0), D(1)
+ // stxv vsr(i*4+1), D-16(1)
+ // stxv vsr(i*4+2), D-32(1)
+ // stxv vsr(i*4+3), D-48(1)
+
+ // To:
+ // xxlxor vsr(i*4), 0, 0
+ // stxv vsr(i*4), D(1)
+ // stxv vsr(i*4), D-16(1)
+ // stxv vsr(i*4), D-32(1)
+ // stxv vsr(i*4), D-48(1)
+ bool
+ OptimizeZeroingAccumulatorSpilling(MachineBasicBlock &MBB,
+ const TargetRegisterInfo *TRI) const {
+ bool changed = false;
+ for (auto BBI = MBB.instr_begin(); BBI != MBB.instr_end(); ++BBI) {
+ if (BBI->getOpcode() != PPC::XXSETACCZ)
+ continue;
+
+ Register ACCZReg = BBI->getOperand(0).getReg();
+
+ DenseSet<MachineInstr *> InstrsToErase;
+ InstrsToErase.insert(&*BBI++);
+
----------------
diggerlin wrote:
the patch is for issue https://github.ibm.com/compiler/wyvern/issues/16624, it is a spill, there is another solution to whether there is XXSETACCZ instruction in the function https://github.com/llvm/llvm-project/blob/main/llvm/lib/Target/PowerPC/PPCRegisterInfo.cpp#L1313
if there is the XXSETACCZ instruction , we do not do
https://github.com/llvm/llvm-project/blob/main/llvm/lib/Target/PowerPC/PPCRegisterInfo.cpp#L1336
`BuildMI(MBB, II, DL, TII.get(PPC::XXMFACC), SrcReg).addReg(SrcReg);`
and in the function [static void spillRegPairs](https://github.com/llvm/llvm-project/blob/main/llvm/lib/Target/PowerPC/PPCRegisterInfo.cpp#L1238)
we change the code
```
addFrameReference(BuildMI(MBB, II, DL, TII.get(PPC::STXV))
.addReg(Reg + i, getKillRegState(IsKilled)),
FrameIndex, Offset);
```
to
```
addFrameReference(BuildMI(MBB, II, DL, TII.get(PPC::STXV))
.addReg(Reg , getKillRegState(IsKilled)),
FrameIndex, Offset);
```
but I do not think it is good place to put optimize in the function `PPCRegisterInfo::lowerACCSpilling`
https://github.com/llvm/llvm-project/pull/96094
More information about the llvm-commits
mailing list