mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-26 04:32:44 +01:00
Pattern ISel: fix argument loading for i64s (thanks chris)
Simple ISel: fix i64 subtract llvm-svn: 20903
This commit is contained in:
parent
32d1caae6d
commit
734a61f057
@ -120,14 +120,10 @@ PPC32TargetLowering::LowerArguments(Function &F, SelectionDAG &DAG) {
|
|||||||
ObjSize = 4;
|
ObjSize = 4;
|
||||||
if (GPR_remaining > 0) {
|
if (GPR_remaining > 0) {
|
||||||
BuildMI(&BB, PPC::IMPLICIT_DEF, 0, GPR[GPR_idx]);
|
BuildMI(&BB, PPC::IMPLICIT_DEF, 0, GPR[GPR_idx]);
|
||||||
unsigned virtReg =
|
argt = newroot = DAG.getCopyFromReg(GPR[GPR_idx], MVT::i32,
|
||||||
MF.getSSARegMap()->createVirtualRegister(getRegClassFor(MVT::i32));
|
DAG.getRoot());
|
||||||
argt = newroot = DAG.getCopyFromReg(virtReg, MVT::i32, DAG.getRoot());
|
|
||||||
if (ObjectVT != MVT::i32)
|
if (ObjectVT != MVT::i32)
|
||||||
argt = DAG.getNode(ISD::TRUNCATE, ObjectVT, newroot);
|
argt = DAG.getNode(ISD::TRUNCATE, ObjectVT, newroot);
|
||||||
argVR.push_back(virtReg);
|
|
||||||
argPR.push_back(GPR[GPR_idx]);
|
|
||||||
argOp.push_back(PPC::OR);
|
|
||||||
} else {
|
} else {
|
||||||
needsLoad = true;
|
needsLoad = true;
|
||||||
}
|
}
|
||||||
@ -137,25 +133,13 @@ PPC32TargetLowering::LowerArguments(Function &F, SelectionDAG &DAG) {
|
|||||||
if (GPR_remaining > 1) {
|
if (GPR_remaining > 1) {
|
||||||
BuildMI(&BB, PPC::IMPLICIT_DEF, 0, GPR[GPR_idx]);
|
BuildMI(&BB, PPC::IMPLICIT_DEF, 0, GPR[GPR_idx]);
|
||||||
BuildMI(&BB, PPC::IMPLICIT_DEF, 0, GPR[GPR_idx+1]);
|
BuildMI(&BB, PPC::IMPLICIT_DEF, 0, GPR[GPR_idx+1]);
|
||||||
SDOperand root = DAG.getRoot();
|
|
||||||
SDOperand Hi = DAG.getNode(ISD::EXTRACT_ELEMENT, MVT::i32,
|
|
||||||
root, DAG.getConstant(1, MVT::i32));
|
|
||||||
SDOperand Lo = DAG.getNode(ISD::EXTRACT_ELEMENT, MVT::i32,
|
|
||||||
root, DAG.getConstant(0, MVT::i32));
|
|
||||||
|
|
||||||
// Create the pair of virtual registers
|
|
||||||
MF.getSSARegMap()->createVirtualRegister(getRegClassFor(MVT::i32));
|
|
||||||
unsigned virtReg = MF.getSSARegMap()->createVirtualRegister(getRegClassFor(MVT::i32))-1;
|
|
||||||
|
|
||||||
// Copy the extracted halves into the virtual registers
|
// Copy the extracted halves into the virtual registers
|
||||||
SDOperand argHi = DAG.getCopyFromReg(virtReg, MVT::i32, Hi);
|
SDOperand argHi = DAG.getCopyFromReg(GPR[GPR_idx], MVT::i32,
|
||||||
SDOperand argLo = DAG.getCopyFromReg(virtReg+1, MVT::i32, Lo);
|
DAG.getRoot());
|
||||||
|
SDOperand argLo = DAG.getCopyFromReg(GPR[GPR_idx+1], MVT::i32, argHi);
|
||||||
// Build the outgoing arg thingy
|
// Build the outgoing arg thingy
|
||||||
argt = newroot = DAG.getNode(ISD::BUILD_PAIR, MVT::i64, argLo, argHi);
|
argt = DAG.getNode(ISD::BUILD_PAIR, MVT::i64, argLo, argHi);
|
||||||
argVR.push_back(virtReg); argVR.push_back(virtReg+1);
|
newroot = argLo;
|
||||||
argPR.push_back(GPR[GPR_idx]); argPR.push_back(GPR[GPR_idx+1]);
|
|
||||||
argOp.push_back(PPC::OR); argOp.push_back(PPC::OR);
|
|
||||||
} else {
|
} else {
|
||||||
needsLoad = true;
|
needsLoad = true;
|
||||||
}
|
}
|
||||||
@ -164,12 +148,8 @@ PPC32TargetLowering::LowerArguments(Function &F, SelectionDAG &DAG) {
|
|||||||
case MVT::f64: ObjSize = 8;
|
case MVT::f64: ObjSize = 8;
|
||||||
if (FPR_remaining > 0) {
|
if (FPR_remaining > 0) {
|
||||||
BuildMI(&BB, PPC::IMPLICIT_DEF, 0, FPR[FPR_idx]);
|
BuildMI(&BB, PPC::IMPLICIT_DEF, 0, FPR[FPR_idx]);
|
||||||
unsigned virtReg =
|
argt = newroot = DAG.getCopyFromReg(FPR[FPR_idx], ObjectVT,
|
||||||
MF.getSSARegMap()->createVirtualRegister(getRegClassFor(ObjectVT));
|
DAG.getRoot());
|
||||||
argt = newroot = DAG.getCopyFromReg(virtReg, ObjectVT, DAG.getRoot());
|
|
||||||
argVR.push_back(virtReg);
|
|
||||||
argPR.push_back(FPR[FPR_idx]);
|
|
||||||
argOp.push_back(PPC::FMR);
|
|
||||||
--FPR_remaining;
|
--FPR_remaining;
|
||||||
++FPR_idx;
|
++FPR_idx;
|
||||||
} else {
|
} else {
|
||||||
@ -199,13 +179,6 @@ PPC32TargetLowering::LowerArguments(Function &F, SelectionDAG &DAG) {
|
|||||||
ArgValues.push_back(argt);
|
ArgValues.push_back(argt);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0, count = argVR.size(); i < count; ++i) {
|
|
||||||
if (argOp[i] == PPC::FMR)
|
|
||||||
BuildMI(&BB, argOp[i], 1, argVR[i]).addReg(argPR[i]);
|
|
||||||
else
|
|
||||||
BuildMI(&BB, argOp[i], 2, argVR[i]).addReg(argPR[i]).addReg(argPR[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the function takes variable number of arguments, make a frame index for
|
// If the function takes variable number of arguments, make a frame index for
|
||||||
// the start of the first vararg value... for expansion of llvm.va_start.
|
// the start of the first vararg value... for expansion of llvm.va_start.
|
||||||
if (F.isVarArg())
|
if (F.isVarArg())
|
||||||
@ -1014,11 +987,11 @@ unsigned ISel::SelectExpr(SDOperand N) {
|
|||||||
for (unsigned i = 0, e = N.getNumOperands(); i != e; ++i)
|
for (unsigned i = 0, e = N.getNumOperands(); i != e; ++i)
|
||||||
InVals.push_back(SelectExpr(N.getOperand(i)));
|
InVals.push_back(SelectExpr(N.getOperand(i)));
|
||||||
if (N.getOpcode() == ISD::ADD_PARTS) {
|
if (N.getOpcode() == ISD::ADD_PARTS) {
|
||||||
BuildMI(BB, PPC::ADDC, 2, Result+1).addReg(InVals[1]).addReg(InVals[3]);
|
BuildMI(BB, PPC::ADDC, 2, Result+1).addReg(InVals[0]).addReg(InVals[2]);
|
||||||
BuildMI(BB, PPC::ADDE, 2, Result).addReg(InVals[0]).addReg(InVals[2]);
|
BuildMI(BB, PPC::ADDE, 2, Result).addReg(InVals[1]).addReg(InVals[3]);
|
||||||
} else {
|
} else {
|
||||||
BuildMI(BB, PPC::SUBFC, 2, Result+1).addReg(InVals[1]).addReg(InVals[3]);
|
BuildMI(BB, PPC::SUBFC, 2, Result+1).addReg(InVals[2]).addReg(InVals[0]);
|
||||||
BuildMI(BB, PPC::SUBFE, 2, Result).addReg(InVals[0]).addReg(InVals[2]);
|
BuildMI(BB, PPC::SUBFE, 2, Result).addReg(InVals[3]).addReg(InVals[1]);
|
||||||
}
|
}
|
||||||
return Result+N.ResNo;
|
return Result+N.ResNo;
|
||||||
}
|
}
|
||||||
|
@ -2389,7 +2389,7 @@ void PPC32ISel::emitSimpleBinaryOperation(MachineBasicBlock *MBB,
|
|||||||
unsigned DestReg) {
|
unsigned DestReg) {
|
||||||
// Arithmetic and Bitwise operators
|
// Arithmetic and Bitwise operators
|
||||||
static const unsigned OpcodeTab[] = {
|
static const unsigned OpcodeTab[] = {
|
||||||
PPC::ADD, PPC::SUB, PPC::AND, PPC::OR, PPC::XOR
|
PPC::ADD, PPC::SUBF, PPC::AND, PPC::OR, PPC::XOR
|
||||||
};
|
};
|
||||||
static const unsigned LongOpTab[2][5] = {
|
static const unsigned LongOpTab[2][5] = {
|
||||||
{ PPC::ADDC, PPC::SUBFC, PPC::AND, PPC::OR, PPC::XOR },
|
{ PPC::ADDC, PPC::SUBFC, PPC::AND, PPC::OR, PPC::XOR },
|
||||||
@ -2444,6 +2444,17 @@ void PPC32ISel::emitSimpleBinaryOperation(MachineBasicBlock *MBB,
|
|||||||
unsigned Op0r = getReg(Op0, MBB, IP);
|
unsigned Op0r = getReg(Op0, MBB, IP);
|
||||||
unsigned Op1r = getReg(Op1, MBB, IP);
|
unsigned Op1r = getReg(Op1, MBB, IP);
|
||||||
|
|
||||||
|
// Subtracts have their operands swapped
|
||||||
|
if (OperatorClass == 1) {
|
||||||
|
if (Class != cLong) {
|
||||||
|
BuildMI(*MBB, IP, PPC::SUBF, 2, DestReg).addReg(Op1r).addReg(Op0r);
|
||||||
|
} else {
|
||||||
|
BuildMI(*MBB, IP, PPC::SUBFC, 2, DestReg+1).addReg(Op1r+1).addReg(Op0r+1);
|
||||||
|
BuildMI(*MBB, IP, PPC::SUBFE, 2, DestReg).addReg(Op1r).addReg(Op0r);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (Class != cLong) {
|
if (Class != cLong) {
|
||||||
unsigned Opcode = OpcodeTab[OperatorClass];
|
unsigned Opcode = OpcodeTab[OperatorClass];
|
||||||
BuildMI(*MBB, IP, Opcode, 2, DestReg).addReg(Op0r).addReg(Op1r);
|
BuildMI(*MBB, IP, Opcode, 2, DestReg).addReg(Op0r).addReg(Op1r);
|
||||||
@ -3876,7 +3887,7 @@ void PPC32ISel::visitAllocaInst(AllocaInst &I) {
|
|||||||
.addImm(0).addImm(27);
|
.addImm(0).addImm(27);
|
||||||
|
|
||||||
// Subtract size from stack pointer, thereby allocating some space.
|
// Subtract size from stack pointer, thereby allocating some space.
|
||||||
BuildMI(BB, PPC::SUB, 2, PPC::R1).addReg(PPC::R1).addReg(AlignedSize);
|
BuildMI(BB, PPC::SUBF, 2, PPC::R1).addReg(AlignedSize).addReg(PPC::R1);
|
||||||
|
|
||||||
// Put a pointer to the space into the result register, by copying
|
// Put a pointer to the space into the result register, by copying
|
||||||
// the stack pointer.
|
// the stack pointer.
|
||||||
|
Loading…
Reference in New Issue
Block a user