mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-08-19 19:29:31 +00:00
Fix cut & paste errors (32->64), and codegen float->int more optimally.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21098 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
ac6e2dbf52
commit
a3829d5580
@ -1,4 +1,4 @@
|
||||
//===-- PPC32ISelPattern.cpp - A pattern matching inst selector for PPC32 -===//
|
||||
//===-- PPC64ISelPattern.cpp - A pattern matching inst selector for PPC64 -===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
@ -7,7 +7,7 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file defines a pattern matching instruction selector for 32 bit PowerPC.
|
||||
// This file defines a pattern matching instruction selector for 64 bit PowerPC.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
@ -1421,73 +1421,13 @@ unsigned ISel::SelectExpr(SDOperand N) {
|
||||
|
||||
case ISD::FP_TO_UINT:
|
||||
case ISD::FP_TO_SINT: {
|
||||
bool U = (ISD::FP_TO_UINT == opcode);
|
||||
Tmp1 = SelectExpr(N.getOperand(0));
|
||||
if (!U) {
|
||||
Tmp2 = MakeReg(MVT::f64);
|
||||
BuildMI(BB, PPC::FCTIWZ, 1, Tmp2).addReg(Tmp1);
|
||||
int FrameIdx = BB->getParent()->getFrameInfo()->CreateStackObject(8, 8);
|
||||
addFrameReference(BuildMI(BB, PPC::STFD, 3).addReg(Tmp2), FrameIdx);
|
||||
addFrameReference(BuildMI(BB, PPC::LWZ, 2, Result), FrameIdx, 4);
|
||||
return Result;
|
||||
} else {
|
||||
unsigned Zero = getConstDouble(0.0);
|
||||
unsigned MaxInt = getConstDouble((1LL << 32) - 1);
|
||||
unsigned Border = getConstDouble(1LL << 31);
|
||||
unsigned UseZero = MakeReg(MVT::f64);
|
||||
unsigned UseMaxInt = MakeReg(MVT::f64);
|
||||
unsigned UseChoice = MakeReg(MVT::f64);
|
||||
unsigned TmpReg = MakeReg(MVT::f64);
|
||||
unsigned TmpReg2 = MakeReg(MVT::f64);
|
||||
unsigned ConvReg = MakeReg(MVT::f64);
|
||||
unsigned IntTmp = MakeReg(MVT::i32);
|
||||
unsigned XorReg = MakeReg(MVT::i32);
|
||||
MachineFunction *F = BB->getParent();
|
||||
int FrameIdx = F->getFrameInfo()->CreateStackObject(8, 8);
|
||||
// Update machine-CFG edges
|
||||
MachineBasicBlock *XorMBB = new MachineBasicBlock(BB->getBasicBlock());
|
||||
MachineBasicBlock *PhiMBB = new MachineBasicBlock(BB->getBasicBlock());
|
||||
MachineBasicBlock *OldMBB = BB;
|
||||
ilist<MachineBasicBlock>::iterator It = BB; ++It;
|
||||
F->getBasicBlockList().insert(It, XorMBB);
|
||||
F->getBasicBlockList().insert(It, PhiMBB);
|
||||
BB->addSuccessor(XorMBB);
|
||||
BB->addSuccessor(PhiMBB);
|
||||
// Convert from floating point to unsigned 32-bit value
|
||||
// Use 0 if incoming value is < 0.0
|
||||
BuildMI(BB, PPC::FSEL, 3, UseZero).addReg(Tmp1).addReg(Tmp1).addReg(Zero);
|
||||
// Use 2**32 - 1 if incoming value is >= 2**32
|
||||
BuildMI(BB, PPC::FSUB, 2, UseMaxInt).addReg(MaxInt).addReg(Tmp1);
|
||||
BuildMI(BB, PPC::FSEL, 3, UseChoice).addReg(UseMaxInt).addReg(UseZero)
|
||||
.addReg(MaxInt);
|
||||
// Subtract 2**31
|
||||
BuildMI(BB, PPC::FSUB, 2, TmpReg).addReg(UseChoice).addReg(Border);
|
||||
// Use difference if >= 2**31
|
||||
BuildMI(BB, PPC::FCMPU, 2, PPC::CR0).addReg(UseChoice).addReg(Border);
|
||||
BuildMI(BB, PPC::FSEL, 3, TmpReg2).addReg(TmpReg).addReg(TmpReg)
|
||||
.addReg(UseChoice);
|
||||
// Convert to integer
|
||||
BuildMI(BB, PPC::FCTIWZ, 1, ConvReg).addReg(TmpReg2);
|
||||
addFrameReference(BuildMI(BB, PPC::STFD, 3).addReg(ConvReg), FrameIdx);
|
||||
addFrameReference(BuildMI(BB, PPC::LWZ, 2, IntTmp), FrameIdx, 4);
|
||||
BuildMI(BB, PPC::BLT, 2).addReg(PPC::CR0).addMBB(PhiMBB);
|
||||
BuildMI(BB, PPC::B, 1).addMBB(XorMBB);
|
||||
|
||||
// XorMBB:
|
||||
// add 2**31 if input was >= 2**31
|
||||
BB = XorMBB;
|
||||
BuildMI(BB, PPC::XORIS, 2, XorReg).addReg(IntTmp).addImm(0x8000);
|
||||
XorMBB->addSuccessor(PhiMBB);
|
||||
|
||||
// PhiMBB:
|
||||
// DestReg = phi [ IntTmp, OldMBB ], [ XorReg, XorMBB ]
|
||||
BB = PhiMBB;
|
||||
BuildMI(BB, PPC::PHI, 4, Result).addReg(IntTmp).addMBB(OldMBB)
|
||||
.addReg(XorReg).addMBB(XorMBB);
|
||||
return Result;
|
||||
}
|
||||
assert(0 && "Should never get here");
|
||||
return 0;
|
||||
Tmp2 = MakeReg(MVT::f64);
|
||||
BuildMI(BB, PPC::FCTIDZ, 1, Tmp2).addReg(Tmp1);
|
||||
int FrameIdx = BB->getParent()->getFrameInfo()->CreateStackObject(8, 8);
|
||||
addFrameReference(BuildMI(BB, PPC::STFD, 3).addReg(Tmp2), FrameIdx);
|
||||
addFrameReference(BuildMI(BB, PPC::LD, 2, Result), FrameIdx);
|
||||
return Result;
|
||||
}
|
||||
|
||||
case ISD::SETCC:
|
||||
|
Loading…
Reference in New Issue
Block a user