aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Target/PowerPC/PPCFastISel.cpp
diff options
context:
space:
mode:
authorBill Schmidt <wschmidt@linux.vnet.ibm.com>2013-08-30 23:31:33 +0000
committerBill Schmidt <wschmidt@linux.vnet.ibm.com>2013-08-30 23:31:33 +0000
commit9d2238cb0f6f67ed6883a0e9f98a835c523724da (patch)
treeaab43b9e11c0c9417de66d8545ef68ace1adffe4 /lib/Target/PowerPC/PPCFastISel.cpp
parent9056dd45a4402cf6266b61f219aa56651633b2c1 (diff)
downloadexternal_llvm-9d2238cb0f6f67ed6883a0e9f98a835c523724da.zip
external_llvm-9d2238cb0f6f67ed6883a0e9f98a835c523724da.tar.gz
external_llvm-9d2238cb0f6f67ed6883a0e9f98a835c523724da.tar.bz2
[PowerPC] Add integer truncation support to fast-isel.
This is the last substantive patch I'm planning for fast-isel in the near future, adding fast selection of integer truncates. There are certainly more things that can be improved (many of which are called out in FIXMEs), but for now we are catching most of the important cases. I'll document some of the remaining work in a cleanup patch shortly. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@189706 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Target/PowerPC/PPCFastISel.cpp')
-rw-r--r--lib/Target/PowerPC/PPCFastISel.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/Target/PowerPC/PPCFastISel.cpp b/lib/Target/PowerPC/PPCFastISel.cpp
index 0276668..0e789cc 100644
--- a/lib/Target/PowerPC/PPCFastISel.cpp
+++ b/lib/Target/PowerPC/PPCFastISel.cpp
@@ -116,6 +116,7 @@ class PPCFastISel : public FastISel {
bool SelectBinaryIntOp(const Instruction *I, unsigned ISDOpcode);
bool SelectCall(const Instruction *I);
bool SelectRet(const Instruction *I);
+ bool SelectTrunc(const Instruction *I);
bool SelectIntExt(const Instruction *I);
// Utility routines.
@@ -1667,6 +1668,34 @@ bool PPCFastISel::SelectCmp(const Instruction *I) {
return true;
}
+// Attempt to fast-select an integer truncate instruction.
+bool PPCFastISel::SelectTrunc(const Instruction *I) {
+ Value *Src = I->getOperand(0);
+ EVT SrcVT = TLI.getValueType(Src->getType(), true);
+ EVT DestVT = TLI.getValueType(I->getType(), true);
+
+ if (SrcVT != MVT::i64 && SrcVT != MVT::i32 && SrcVT != MVT::i16)
+ return false;
+
+ if (DestVT != MVT::i32 && DestVT != MVT::i16 && DestVT != MVT::i8)
+ return false;
+
+ unsigned SrcReg = getRegForValue(Src);
+ if (!SrcReg)
+ return false;
+
+ // The only interesting case is when we need to switch register classes.
+ if (SrcVT == MVT::i64) {
+ unsigned ResultReg = createResultReg(&PPC::GPRCRegClass);
+ BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(TargetOpcode::COPY),
+ ResultReg).addReg(SrcReg, 0, PPC::sub_32);
+ SrcReg = ResultReg;
+ }
+
+ UpdateValueMap(I, SrcReg);
+ return true;
+}
+
// Attempt to fast-select an integer extend instruction.
bool PPCFastISel::SelectIntExt(const Instruction *I) {
Type *DestTy = I->getType();
@@ -1743,6 +1772,8 @@ bool PPCFastISel::TargetSelectInstruction(const Instruction *I) {
return SelectCall(I);
case Instruction::Ret:
return SelectRet(I);
+ case Instruction::Trunc:
+ return SelectTrunc(I);
case Instruction::ZExt:
case Instruction::SExt:
return SelectIntExt(I);