[llvm-commits] CVS: llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
Chris Lattner
lattner at cs.uiuc.edu
Thu Mar 23 23:29:30 PST 2006
Changes in directory llvm/lib/CodeGen/SelectionDAG:
LegalizeDAG.cpp updated: 1.336 -> 1.337
---
Log message:
prefer to generate constant pool loads over splats. This prevents us from
using a splat for {1.0,1.0,1.0,1.0}
---
Diffs of the changes: (+33 -34)
LegalizeDAG.cpp | 67 +++++++++++++++++++++++++++-----------------------------
1 files changed, 33 insertions(+), 34 deletions(-)
Index: llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
diff -u llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp:1.336 llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp:1.337
--- llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp:1.336 Thu Mar 23 20:26:29 2006
+++ llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp Fri Mar 24 01:29:17 2006
@@ -3113,6 +3113,11 @@
SDOperand SplatValue = Node->getOperand(0);
std::map<SDOperand, std::vector<unsigned> > Values;
Values[SplatValue].push_back(0);
+ bool isConstant = true;
+ if (!isa<ConstantFPSDNode>(SplatValue) && !isa<ConstantSDNode>(SplatValue) &&
+ SplatValue.getOpcode() != ISD::UNDEF)
+ isConstant = false;
+
for (unsigned i = 1; i < NumElems; ++i) {
SDOperand V = Node->getOperand(i);
std::map<SDOperand, std::vector<unsigned> >::iterator I = Values.find(V);
@@ -3124,6 +3129,12 @@
isOnlyLowElement = false;
if (SplatValue != V)
SplatValue = SDOperand(0,0);
+
+ // If this isn't a constant element or an undef, we can't use a constant
+ // pool load.
+ if (!isa<ConstantFPSDNode>(V) && !isa<ConstantSDNode>(V) &&
+ V.getOpcode() != ISD::UNDEF)
+ isConstant = false;
}
if (isOnlyLowElement) {
@@ -3135,40 +3146,7 @@
Node->getOperand(0));
}
- if (SplatValue.Val) { // Splat of one value?
- // Build the shuffle constant vector: <0, 0, 0, 0>
- MVT::ValueType MaskVT =
- MVT::getIntVectorWithNumElements(NumElems);
- SDOperand Zero = DAG.getConstant(0, MVT::getVectorBaseType(MaskVT));
- std::vector<SDOperand> ZeroVec(NumElems, Zero);
- SDOperand SplatMask = DAG.getNode(ISD::BUILD_VECTOR, MaskVT, ZeroVec);
-
- // If the target supports VECTOR_SHUFFLE and this shuffle mask, use it.
- if (TLI.isShuffleLegal(Node->getValueType(0), SplatMask)) {
- // Get the splatted value into the low element of a vector register.
- SDOperand LowValVec =
- DAG.getNode(ISD::SCALAR_TO_VECTOR, Node->getValueType(0), SplatValue);
-
- // Return shuffle(LowValVec, undef, <0,0,0,0>)
- return DAG.getNode(ISD::VECTOR_SHUFFLE, Node->getValueType(0), LowValVec,
- DAG.getNode(ISD::UNDEF, Node->getValueType(0)),
- SplatMask);
- }
- }
-
- // If the elements are all constants, turn this into a load from the constant
- // pool.
- bool isConstant = true;
- for (SDNode::op_iterator I = Node->op_begin(), E = Node->op_end();
- I != E; ++I) {
- if (!isa<ConstantFPSDNode>(I) && !isa<ConstantSDNode>(I) &&
- I->getOpcode() != ISD::UNDEF) {
- isConstant = false;
- break;
- }
- }
-
- // Create a ConstantPacked, and put it in the constant pool.
+ // If all elements are constants, create a load from the constant pool.
if (isConstant) {
MVT::ValueType VT = Node->getValueType(0);
const Type *OpNTy =
@@ -3191,7 +3169,28 @@
return DAG.getLoad(VT, DAG.getEntryNode(), CPIdx,
DAG.getSrcValue(NULL));
}
+
+ if (SplatValue.Val) { // Splat of one value?
+ // Build the shuffle constant vector: <0, 0, 0, 0>
+ MVT::ValueType MaskVT =
+ MVT::getIntVectorWithNumElements(NumElems);
+ SDOperand Zero = DAG.getConstant(0, MVT::getVectorBaseType(MaskVT));
+ std::vector<SDOperand> ZeroVec(NumElems, Zero);
+ SDOperand SplatMask = DAG.getNode(ISD::BUILD_VECTOR, MaskVT, ZeroVec);
+ // If the target supports VECTOR_SHUFFLE and this shuffle mask, use it.
+ if (TLI.isShuffleLegal(Node->getValueType(0), SplatMask)) {
+ // Get the splatted value into the low element of a vector register.
+ SDOperand LowValVec =
+ DAG.getNode(ISD::SCALAR_TO_VECTOR, Node->getValueType(0), SplatValue);
+
+ // Return shuffle(LowValVec, undef, <0,0,0,0>)
+ return DAG.getNode(ISD::VECTOR_SHUFFLE, Node->getValueType(0), LowValVec,
+ DAG.getNode(ISD::UNDEF, Node->getValueType(0)),
+ SplatMask);
+ }
+ }
+
// If there are only two unique elements, we may be able to turn this into a
// vector shuffle.
if (Values.size() == 2) {
More information about the llvm-commits
mailing list