[llvm-commits] [llvm] r72349 - /llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp

Eli Friedman eli.friedman at gmail.com
Sat May 23 15:37:25 PDT 2009


Author: efriedma
Date: Sat May 23 17:37:25 2009
New Revision: 72349

URL: http://llvm.org/viewvc/llvm-project?rev=72349&view=rev
Log:
Add a proper implementation of EXTRACT_SUBVECTOR legalization that 
doesn't split legal vector operands.  This is necessary because the 
type legalization (and therefore, vector splitting) code will be going 
away soon.


Modified:
    llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp

Modified: llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp?rev=72349&r1=72348&r2=72349&view=diff

==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp Sat May 23 17:37:25 2009
@@ -313,6 +313,7 @@
 
   SDValue ExpandEXTRACT_SUBVECTOR(SDValue Op);
   SDValue ExpandEXTRACT_VECTOR_ELT(SDValue Op);
+  SDValue ExpandExtractFromVectorThroughStack(SDValue Op);
 };
 }
 
@@ -1746,7 +1747,23 @@
     Tmp1 = Node->getOperand(0);
     Tmp2 = LegalizeOp(Node->getOperand(1));
     Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2);
-    Result = ExpandEXTRACT_SUBVECTOR(Result);
+    switch (TLI.getOperationAction(ISD::EXTRACT_SUBVECTOR,
+                                   Node->getValueType(0))) {
+    default: assert(0 && "Unknown operation action!");
+    case TargetLowering::Legal:
+      break;
+    case TargetLowering::Custom:
+      Tmp3 = TLI.LowerOperation(Result, DAG);
+      if (Tmp3.getNode()) {
+        Result = Tmp3;
+        break;
+      }
+      // FALLTHROUGH
+    case TargetLowering::Expand: {
+      Result = ExpandExtractFromVectorThroughStack(Result);
+      break;
+    }
+    }
     break;
 
   case ISD::CONCAT_VECTORS: {
@@ -5060,26 +5077,32 @@
     Op = DAG.UpdateNodeOperands(Op, Vec, Idx);
     Op = ExpandEXTRACT_VECTOR_ELT(Op);
   } else {
-    // Store the value to a temporary stack slot, then LOAD the scalar
-    // element back out.
-    SDValue StackPtr = DAG.CreateStackTemporary(Vec.getValueType());
-    SDValue Ch = DAG.getStore(DAG.getEntryNode(), dl, Vec, StackPtr, NULL, 0);
-
-    // Add the offset to the index.
-    unsigned EltSize = Op.getValueType().getSizeInBits()/8;
-    Idx = DAG.getNode(ISD::MUL, dl, Idx.getValueType(), Idx,
-                      DAG.getConstant(EltSize, Idx.getValueType()));
+    Op = ExpandExtractFromVectorThroughStack(Op);
+  }
+  return Op;
+}
 
-    if (Idx.getValueType().bitsGT(TLI.getPointerTy()))
-      Idx = DAG.getNode(ISD::TRUNCATE, dl, TLI.getPointerTy(), Idx);
-    else
-      Idx = DAG.getNode(ISD::ZERO_EXTEND, dl, TLI.getPointerTy(), Idx);
+SDValue SelectionDAGLegalize::ExpandExtractFromVectorThroughStack(SDValue Op) {
+  SDValue Vec = Op.getOperand(0);
+  SDValue Idx = Op.getOperand(1);
+  DebugLoc dl = Op.getDebugLoc();
+  // Store the value to a temporary stack slot, then LOAD the returned part.
+  SDValue StackPtr = DAG.CreateStackTemporary(Vec.getValueType());
+  SDValue Ch = DAG.getStore(DAG.getEntryNode(), dl, Vec, StackPtr, NULL, 0);
 
-    StackPtr = DAG.getNode(ISD::ADD, dl, Idx.getValueType(), Idx, StackPtr);
+  // Add the offset to the index.
+  unsigned EltSize = Op.getValueType().getSizeInBits()/8;
+  Idx = DAG.getNode(ISD::MUL, dl, Idx.getValueType(), Idx,
+                    DAG.getConstant(EltSize, Idx.getValueType()));
 
-    Op = DAG.getLoad(Op.getValueType(), dl, Ch, StackPtr, NULL, 0);
-  }
-  return Op;
+  if (Idx.getValueType().bitsGT(TLI.getPointerTy()))
+    Idx = DAG.getNode(ISD::TRUNCATE, dl, TLI.getPointerTy(), Idx);
+  else
+    Idx = DAG.getNode(ISD::ZERO_EXTEND, dl, TLI.getPointerTy(), Idx);
+
+  StackPtr = DAG.getNode(ISD::ADD, dl, Idx.getValueType(), Idx, StackPtr);
+
+  return DAG.getLoad(Op.getValueType(), dl, Ch, StackPtr, NULL, 0);
 }
 
 /// ExpandEXTRACT_SUBVECTOR - Expand a EXTRACT_SUBVECTOR operation.  For now





More information about the llvm-commits mailing list