1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-25 04:02:41 +01:00

When mixing SSE and x87 codegen, it's possible to

have situations where an SSE instruction turns into
multiple blocks, with the live range of an x87
register crossing them.  To do this correctly make
sure we examine all blocks when inserting
FP_REG_KILL.  PR 1697.  (This was exposed by my
fix for PR 1681, but the same thing could happen
mixing x87 long double with SSE.)

llvm-svn: 42281
This commit is contained in:
Dale Johannesen 2007-09-24 22:52:39 +00:00
parent 9390abcf16
commit 5ea6a9bc3a

View File

@ -482,14 +482,17 @@ void X86DAGToDAGISel::InstructionSelectBasicBlock(SelectionDAG &DAG) {
// block defines any FP values. If so, put an FP_REG_KILL instruction before // block defines any FP values. If so, put an FP_REG_KILL instruction before
// the terminator of the block. // the terminator of the block.
// Note that FP stack instructions *are* used in SSE code for long double, // Note that FP stack instructions are used in all modes for long double,
// so we do need this check. // so we always need to do this check.
bool ContainsFPCode = false; // Also note that it's possible for an FP stack register to be live across
// an instruction that produces multiple basic blocks (SSE CMOV) so we
// must check all the generated basic blocks.
// Scan all of the machine instructions in these MBBs, checking for FP // Scan all of the machine instructions in these MBBs, checking for FP
// stores. (RFP32 and RFP64 will not exist in SSE mode, but RFP80 might.) // stores. (RFP32 and RFP64 will not exist in SSE mode, but RFP80 might.)
MachineFunction::iterator MBBI = FirstMBB; MachineFunction::iterator MBBI = FirstMBB;
do { do {
bool ContainsFPCode = false;
for (MachineBasicBlock::iterator I = MBBI->begin(), E = MBBI->end(); for (MachineBasicBlock::iterator I = MBBI->begin(), E = MBBI->end();
!ContainsFPCode && I != E; ++I) { !ContainsFPCode && I != E; ++I) {
if (I->getNumOperands() != 0 && I->getOperand(0).isRegister()) { if (I->getNumOperands() != 0 && I->getOperand(0).isRegister()) {
@ -507,35 +510,34 @@ void X86DAGToDAGISel::InstructionSelectBasicBlock(SelectionDAG &DAG) {
} }
} }
} }
} while (!ContainsFPCode && &*(MBBI++) != BB); // Check PHI nodes in successor blocks. These PHI's will be lowered to have
// a copy of the input value in this block. In SSE mode, we only care about
// Check PHI nodes in successor blocks. These PHI's will be lowered to have // 80-bit values.
// a copy of the input value in this block. In SSE mode, we only care about if (!ContainsFPCode) {
// 80-bit values. // Final check, check LLVM BB's that are successors to the LLVM BB
if (!ContainsFPCode) { // corresponding to BB for FP PHI nodes.
// Final check, check LLVM BB's that are successors to the LLVM BB const BasicBlock *LLVMBB = BB->getBasicBlock();
// corresponding to BB for FP PHI nodes. const PHINode *PN;
const BasicBlock *LLVMBB = BB->getBasicBlock(); for (succ_const_iterator SI = succ_begin(LLVMBB), E = succ_end(LLVMBB);
const PHINode *PN; !ContainsFPCode && SI != E; ++SI) {
for (succ_const_iterator SI = succ_begin(LLVMBB), E = succ_end(LLVMBB); for (BasicBlock::const_iterator II = SI->begin();
!ContainsFPCode && SI != E; ++SI) { (PN = dyn_cast<PHINode>(II)); ++II) {
for (BasicBlock::const_iterator II = SI->begin(); if (PN->getType()==Type::X86_FP80Ty ||
(PN = dyn_cast<PHINode>(II)); ++II) { (!Subtarget->hasSSE1() && PN->getType()->isFloatingPoint()) ||
if (PN->getType()==Type::X86_FP80Ty || (!Subtarget->hasSSE2() && PN->getType()==Type::DoubleTy)) {
(!Subtarget->hasSSE2() && PN->getType()->isFloatingPoint())) { ContainsFPCode = true;
ContainsFPCode = true; break;
break; }
} }
} }
} }
} // Finally, if we found any FP code, emit the FP_REG_KILL instruction.
if (ContainsFPCode) {
// Finally, if we found any FP code, emit the FP_REG_KILL instruction. BuildMI(*MBBI, MBBI->getFirstTerminator(),
if (ContainsFPCode) { TM.getInstrInfo()->get(X86::FP_REG_KILL));
BuildMI(*BB, BB->getFirstTerminator(), ++NumFPKill;
TM.getInstrInfo()->get(X86::FP_REG_KILL)); }
++NumFPKill; } while (&*(MBBI++) != BB);
}
} }
/// MatchAddress - Add the specified node to the specified addressing mode, /// MatchAddress - Add the specified node to the specified addressing mode,