[llvm-commits] CVS: llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp SelectionDAGISel.cpp

Nate Begeman natebegeman at mac.com
Wed Dec 7 11:48:22 PST 2005



Changes in directory llvm/lib/CodeGen/SelectionDAG:

LegalizeDAG.cpp updated: 1.223 -> 1.224
SelectionDAGISel.cpp updated: 1.111 -> 1.112
---
Log message:

Fix a crash where ConstantVec nodes were being generated with the wrong
type when the target did not support them.  Also teach Legalize how to
expand ConstantVecs.

This allows us to generate

_test:
        lwz r2, 12(r3)
        lwz r4, 8(r3)
        lwz r5, 4(r3)
        lwz r6, 0(r3)
        addi r2, r2, 4
        addi r4, r4, 3
        addi r5, r5, 2
        addi r6, r6, 1
        stw r2, 12(r3)
        stw r4, 8(r3)
        stw r5, 4(r3)
        stw r6, 0(r3)
        blr

For:

void %test(%v4i *%P) {
        %T = load %v4i* %P
        %S = add %v4i %T, <int 1, int 2, int 3, int 4>
        store %v4i %S, %v4i * %P
        ret void
}

On PowerPC.


---
Diffs of the changes:  (+30 -2)

 LegalizeDAG.cpp      |   22 ++++++++++++++++++++++
 SelectionDAGISel.cpp |   10 ++++++++--
 2 files changed, 30 insertions(+), 2 deletions(-)


Index: llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
diff -u llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp:1.223 llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp:1.224
--- llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp:1.223	Tue Dec  6 00:18:55 2005
+++ llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp	Wed Dec  7 13:48:11 2005
@@ -3159,6 +3159,28 @@
     Hi = DAG.getConstant(Cst >> MVT::getSizeInBits(NVT), NVT);
     break;
   }
+  case ISD::ConstantVec: {
+    unsigned NumElements = Node->getNumOperands();
+    // If we only have two elements left in the constant vector, just break it
+    // apart into the two scalar constants it contains.  Otherwise, bisect the
+    // ConstantVec, and return each half as a new ConstantVec.
+    // FIXME: this is hard coded as big endian, it may have to change to support
+    // SSE and Alpha MVI
+    if (NumElements == 2) {
+      Hi = Node->getOperand(0);
+      Lo = Node->getOperand(1);
+    } else {
+      NumElements /= 2; 
+      std::vector<SDOperand> LoOps, HiOps;
+      for (unsigned I = 0, E = NumElements; I < E; ++I) {
+        HiOps.push_back(Node->getOperand(I));
+        LoOps.push_back(Node->getOperand(I+NumElements));
+      }
+      Lo = DAG.getNode(ISD::ConstantVec, MVT::Vector, LoOps);
+      Hi = DAG.getNode(ISD::ConstantVec, MVT::Vector, HiOps);
+    }
+    break;
+  }
 
   case ISD::BUILD_PAIR:
     // Legalize both operands.  FIXME: in the future we should handle the case


Index: llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
diff -u llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:1.111 llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:1.112
--- llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:1.111	Tue Dec  6 00:18:55 2005
+++ llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp	Wed Dec  7 13:48:11 2005
@@ -318,9 +318,15 @@
         }
         // Handle the case where we have a 1-element vector, in which
         // case we want to immediately turn it into a scalar constant.
-        if (Ops.size() == 1)
+        if (Ops.size() == 1) {
           return N = Ops[0];
-        return N = DAG.getNode(ISD::ConstantVec, TVT, Ops);
+        } else if (TVT != MVT::Other && TLI.isTypeLegal(TVT)) {
+          return N = DAG.getNode(ISD::ConstantVec, TVT, Ops);
+        } else {
+          // If the packed type isn't legal, then create a ConstantVec node with
+          // generic Vector type instead.
+          return N = DAG.getNode(ISD::ConstantVec, MVT::Vector, Ops);
+        }
       } else {
         // Canonicalize all constant ints to be unsigned.
         return N = DAG.getConstant(cast<ConstantIntegral>(C)->getRawValue(),VT);






More information about the llvm-commits mailing list