Index: lib/CodeGen/SelectionDAG/DAGCombiner.cpp =================================================================== --- lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -15237,7 +15237,13 @@ if (InVec.isUndef()) return DAG.getUNDEF(NVT); + SDValue EltNo = N->getOperand(1); + ConstantSDNode *ConstEltNo = dyn_cast(EltNo); + if (InVec.getOpcode() == ISD::SCALAR_TO_VECTOR) { + if (ConstEltNo && !ConstEltNo->getAPIntValue().isNullValue()) + return DAG.getUNDEF(NVT); + // Check if the result type doesn't match the inserted element type. A // SCALAR_TO_VECTOR may truncate the inserted element and the // EXTRACT_VECTOR_ELT may widen the extracted vector. @@ -15249,9 +15255,6 @@ return InOp; } - SDValue EltNo = N->getOperand(1); - ConstantSDNode *ConstEltNo = dyn_cast(EltNo); - // extract_vector_elt of out-of-bounds element -> UNDEF if (ConstEltNo && ConstEltNo->getAPIntValue().uge(VT.getVectorNumElements())) return DAG.getUNDEF(NVT);