aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2006-03-28 22:11:53 +0000
committerChris Lattner <sabre@nondot.org>2006-03-28 22:11:53 +0000
commit66445d3e0a3c6d02585a3c18ec295451a80d427c (patch)
treeb02ecf645553aa72babfadab474116a7d6f087fc /lib/CodeGen/SelectionDAG/DAGCombiner.cpp
parentbfc1a79c5bc7cb5360bf70773cc2d849379bf507 (diff)
Canonicalize VECTOR_SHUFFLE(X, X, Y) -> VECTOR_SHUFFLE(X,undef,Y')
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@27235 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/SelectionDAG/DAGCombiner.cpp')
-rw-r--r--lib/CodeGen/SelectionDAG/DAGCombiner.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
index 16952a7bdb..1c90f78435 100644
--- a/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ b/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -212,6 +212,7 @@ namespace {
SDOperand visitINSERT_VECTOR_ELT(SDNode *N);
SDOperand visitVINSERT_VECTOR_ELT(SDNode *N);
SDOperand visitVBUILD_VECTOR(SDNode *N);
+ SDOperand visitVECTOR_SHUFFLE(SDNode *N);
SDOperand ReassociateOps(unsigned Opc, SDOperand LHS, SDOperand RHS);
@@ -646,6 +647,7 @@ SDOperand DAGCombiner::visit(SDNode *N) {
case ISD::INSERT_VECTOR_ELT: return visitINSERT_VECTOR_ELT(N);
case ISD::VINSERT_VECTOR_ELT: return visitVINSERT_VECTOR_ELT(N);
case ISD::VBUILD_VECTOR: return visitVBUILD_VECTOR(N);
+ case ISD::VECTOR_SHUFFLE: return visitVECTOR_SHUFFLE(N);
}
return SDOperand();
}
@@ -2427,6 +2429,34 @@ SDOperand DAGCombiner::visitVBUILD_VECTOR(SDNode *N) {
return SDOperand();
}
+SDOperand DAGCombiner::visitVECTOR_SHUFFLE(SDNode *N) {
+ // If the LHS and the RHS are the same node, turn the RHS into an undef.
+ if (N->getOperand(0) == N->getOperand(1)) {
+ // Check the SHUFFLE mask, mapping any inputs from the 2nd operand into the
+ // first operand.
+ std::vector<SDOperand> MappedOps;
+ SDOperand ShufMask = N->getOperand(2);
+ unsigned NumElts = ShufMask.getNumOperands();
+ for (unsigned i = 0, e = ShufMask.getNumOperands(); i != e; ++i) {
+ if (cast<ConstantSDNode>(ShufMask.getOperand(i))->getValue() >= NumElts) {
+ unsigned NewIdx =
+ cast<ConstantSDNode>(ShufMask.getOperand(i))->getValue() - NumElts;
+ MappedOps.push_back(DAG.getConstant(NewIdx, MVT::i32));
+ } else {
+ MappedOps.push_back(ShufMask.getOperand(i));
+ }
+ }
+ ShufMask = DAG.getNode(ISD::BUILD_VECTOR, ShufMask.getValueType(),
+ MappedOps);
+ return DAG.getNode(ISD::VECTOR_SHUFFLE, N->getValueType(0),
+ N->getOperand(0),
+ DAG.getNode(ISD::UNDEF, N->getValueType(0)),
+ ShufMask);
+ }
+
+ return SDOperand();
+}
+
SDOperand DAGCombiner::SimplifySelect(SDOperand N0, SDOperand N1, SDOperand N2){
assert(N0.getOpcode() ==ISD::SETCC && "First argument must be a SetCC node!");