Index: lib/CodeGen/SelectionDAG/LegalizeVectorOps.cpp =================================================================== --- lib/CodeGen/SelectionDAG/LegalizeVectorOps.cpp +++ lib/CodeGen/SelectionDAG/LegalizeVectorOps.cpp @@ -689,14 +689,21 @@ SDValue VectorLegalizer::ExpandBSWAP(SDValue Op) { EVT VT = Op.getValueType(); + int ScalarSizeInBytes = VT.getScalarSizeInBits() / 8; + int NElts = VT.getVectorNumElements(); + int NShuffleElts = ScalarSizeInBytes * NElts; + EVT ByteVT = EVT::getVectorVT(*DAG.getContext(), MVT::i8, NShuffleElts); + + // Don't create a shuffle on an illegal type. + if (!TLI.isTypeLegal(ByteVT)) + return DAG.UnrollVectorOp(Op.getNode()); + // Generate a byte wise shuffle mask for the BSWAP. SmallVector ShuffleMask; - int ScalarSizeInBytes = VT.getScalarSizeInBits() / 8; - for (int I = 0, E = VT.getVectorNumElements(); I != E; ++I) + for (int I = 0; I != NElts; ++I) { for (int J = ScalarSizeInBytes - 1; J >= 0; --J) ShuffleMask.push_back((I * ScalarSizeInBytes) + J); - - EVT ByteVT = EVT::getVectorVT(*DAG.getContext(), MVT::i8, ShuffleMask.size()); + } // Only emit a shuffle if the mask is legal. if (!TLI.isShuffleMaskLegal(ShuffleMask, ByteVT))