[llvm] r189706 - [PowerPC] Add integer truncation support to fast-isel.

Bill Schmidt wschmidt at linux.vnet.ibm.com
Fri Aug 30 16:31:33 PDT 2013


Author: wschmidt
Date: Fri Aug 30 18:31:33 2013
New Revision: 189706

URL: http://llvm.org/viewvc/llvm-project?rev=189706&view=rev
Log:
[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.

Modified:
    llvm/trunk/lib/Target/PowerPC/PPCFastISel.cpp

Modified: llvm/trunk/lib/Target/PowerPC/PPCFastISel.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PowerPC/PPCFastISel.cpp?rev=189706&r1=189705&r2=189706&view=diff
==============================================================================
--- llvm/trunk/lib/Target/PowerPC/PPCFastISel.cpp (original)
+++ llvm/trunk/lib/Target/PowerPC/PPCFastISel.cpp Fri Aug 30 18:31:33 2013
@@ -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 Instru
   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::TargetSelectInstructio
       return SelectCall(I);
     case Instruction::Ret:
       return SelectRet(I);
+    case Instruction::Trunc:
+      return SelectTrunc(I);
     case Instruction::ZExt:
     case Instruction::SExt:
       return SelectIntExt(I);





More information about the llvm-commits mailing list