Improve EXTRACT_VECTOR_ELT patch based on comments from Duncan

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@95012 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Mon P Wang 2010-02-01 22:15:09 +00:00
parent c54a747352
commit 87c46d8a0e
2 changed files with 10 additions and 10 deletions

View File

@ -5411,10 +5411,7 @@ SDValue DAGCombiner::visitEXTRACT_VECTOR_ELT(SDNode *N) {
EVT NVT = N->getValueType(0); EVT NVT = N->getValueType(0);
if (InOp.getValueType() != NVT) { if (InOp.getValueType() != NVT) {
assert(InOp.getValueType().isInteger() && NVT.isInteger()); assert(InOp.getValueType().isInteger() && NVT.isInteger());
if (NVT.getSizeInBits() > InOp.getValueType().getSizeInBits()) return DAG.getSExtOrTrunc(InOp, InVec.getDebugLoc(), NVT);
return DAG.getNode(ISD::SIGN_EXTEND, InVec.getDebugLoc(), NVT, InOp);
else
return DAG.getNode(ISD::TRUNCATE, InVec.getDebugLoc(), NVT, InOp);
} }
return InOp; return InOp;
} }

View File

@ -2764,13 +2764,16 @@ SDValue SelectionDAG::getNode(unsigned Opcode, DebugLoc DL, EVT VT,
// EXTRACT_VECTOR_ELT of INSERT_VECTOR_ELT is often formed when vector // EXTRACT_VECTOR_ELT of INSERT_VECTOR_ELT is often formed when vector
// operations are lowered to scalars. // operations are lowered to scalars.
if (N1.getOpcode() == ISD::INSERT_VECTOR_ELT) { if (N1.getOpcode() == ISD::INSERT_VECTOR_ELT) {
// If the indices are the same, return the inserted element. // If the indices are the same, return the inserted element else
if (N1.getOperand(2) == N2 && VT == N1.getOperand(1).getValueType()) // if the indices are known different, extract the element from
return N1.getOperand(1);
// If the indices are known different, extract the element from
// the original vector. // the original vector.
else if (isa<ConstantSDNode>(N1.getOperand(2)) && if (N1.getOperand(2) == N2) {
isa<ConstantSDNode>(N2)) if (VT == N1.getOperand(1).getValueType())
return N1.getOperand(1);
else
return getSExtOrTrunc(N1.getOperand(1), DL, VT);
} else if (isa<ConstantSDNode>(N1.getOperand(2)) &&
isa<ConstantSDNode>(N2))
return getNode(ISD::EXTRACT_VECTOR_ELT, DL, VT, N1.getOperand(0), N2); return getNode(ISD::EXTRACT_VECTOR_ELT, DL, VT, N1.getOperand(0), N2);
} }
break; break;