From a2ff4fc96a4a9e0adfeab01202cd3027f7dfe0f3 Mon Sep 17 00:00:00 2001 From: Evan Cheng Date: Wed, 12 May 2010 01:42:50 +0000 Subject: [PATCH] vst instructions are modeled as this: v1024 = REG_SEQUENCE ... v1025 = EXTRACT_SUBREG v1024, 5 v1026 = EXTRACR_SUBREG v1024, 6 = VSTxx , v1025, v1026 The REG_SEQUENCE ensures the sources that feed into the VST instruction are getting the right register allocation so they form a large super- register. The extract_subreg will be coalesced away all would just work: v1024 = REG_SEQUENCE ... = VSTxx , v1024:5, v1024:6 The problem is if the coalescer isn't run, the extract_subreg instructions would stick around and there is no assurance v1025 and v1026 will get the right registers. As a short term workaround, teach the NEON pre-allocation pass to transfer the sub-register indices over. An alternative would be do it 2addr pass when reg_sequence's are eliminated. But that *seems* wrong and require updating liveness information. Another alternative is to do this in the scheduler when the instructions are created. But that would mean somehow the scheduler this has to be done for correctness reason. That's yucky as well. So for now, we are leaving this in the target specific pass. llvm-svn: 103540 --- llvm/lib/Target/ARM/NEONPreAllocPass.cpp | 26 ++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/llvm/lib/Target/ARM/NEONPreAllocPass.cpp b/llvm/lib/Target/ARM/NEONPreAllocPass.cpp index d1b1bc87eed6..766a9b9e9763 100644 --- a/llvm/lib/Target/ARM/NEONPreAllocPass.cpp +++ b/llvm/lib/Target/ARM/NEONPreAllocPass.cpp @@ -379,6 +379,7 @@ NEONPreAllocPass::FormsRegSequence(MachineInstr *MI, unsigned LastSrcReg = 0; unsigned LastSubIdx = 0; + SmallVector SubIds; for (unsigned R = 0; R < NumRegs; ++R) { const MachineOperand &MO = MI->getOperand(FirstOpnd + R); assert(MO.isReg() && MO.getSubReg() == 0 && "unexpected operand"); @@ -405,8 +406,33 @@ NEONPreAllocPass::FormsRegSequence(MachineInstr *MI, if (SubIdx != ARM::DSUBREG_0 && SubIdx != ARM::QSUBREG_0) return false; } + SubIds.push_back(SubIdx); LastSubIdx = SubIdx; } + + // FIXME: Update the uses of EXTRACT_SUBREG from REG_SEQUENCE is + // currently required for correctness. e.g. + // %reg1041; = REG_SEQUENCE %reg1040, 5, %reg1035, 6 + // %reg1042 = EXTRACT_SUBREG %reg1041, 6 + // %reg1043 = EXTRACT_SUBREG %reg1041, 5 + // VST1q16 %reg1025, 0, %reg1043, %reg1042, + // reg1025 and reg1043 should be replaced with reg1041:6 and reg1041:5 + // respectively. + // We need to change how we model uses of REG_SEQUENCE. + for (unsigned R = 0; R < NumRegs; ++R) { + MachineOperand &MO = MI->getOperand(FirstOpnd + R); + unsigned OldReg = MO.getReg(); + MachineInstr *DefMI = MRI->getVRegDef(OldReg); + assert(DefMI->isExtractSubreg()); + MO.setReg(LastSrcReg); + MO.setSubReg(SubIds[R]); + if (R != 0) + MO.setIsKill(false); + // Delete the EXTRACT_SUBREG if its result is now dead. + if (MRI->use_empty(OldReg)) + DefMI->eraseFromParent(); + } + return true; }