Index: llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp =================================================================== --- llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp +++ llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp @@ -2916,7 +2916,8 @@ ISD::VSELECT : ISD::SELECT; // Min/max matching is only viable if all output VTs are the same. - if (std::equal(ValueVTs.begin(), ValueVTs.end(), ValueVTs.begin())) { + if (ValueVTs.size() == 1 || + std::equal(ValueVTs.begin() + 1, ValueVTs.end(), ValueVTs.begin())) { EVT VT = ValueVTs[0]; LLVMContext &Ctx = *DAG.getContext(); auto &TLI = DAG.getTargetLoweringInfo(); Index: llvm/lib/Transforms/Scalar/NewGVN.cpp =================================================================== --- llvm/lib/Transforms/Scalar/NewGVN.cpp +++ llvm/lib/Transforms/Scalar/NewGVN.cpp @@ -3176,8 +3176,8 @@ std::back_inserter(OperandList)); bool Okay = OperandList.size() == 1; if (!Okay) - Okay = - std::equal(OperandList.begin(), OperandList.end(), OperandList.begin()); + Okay = std::equal(OperandList.begin() + 1, OperandList.end(), + OperandList.begin()); if (Okay) return singleReachablePHIPath(Visited, cast(OperandList[0]), Second); @@ -3272,8 +3272,9 @@ const MemoryDef *MD = cast(U); return ValueToClass.lookup(MD->getMemoryInst()); }); - assert(std::equal(PhiOpClasses.begin(), PhiOpClasses.end(), - PhiOpClasses.begin()) && + assert((PhiOpClasses.size() == 1 || + std::equal(PhiOpClasses.begin() + 1, PhiOpClasses.end(), + PhiOpClasses.begin())) && "All MemoryPhi arguments should be in the same class"); } }