Index: lib/Transforms/Vectorize/LoopVectorize.cpp =================================================================== --- lib/Transforms/Vectorize/LoopVectorize.cpp +++ lib/Transforms/Vectorize/LoopVectorize.cpp @@ -2949,8 +2949,26 @@ StoredVec = reverseVector(StoredVec); // If this member has different type, cast it to an unified type. - if (StoredVec->getType() != SubVT) + if (StoredVec->getType() != SubVT) { + const DataLayout &DL = Member->getModule()->getDataLayout(); + if (!CastInst::isBitOrNoopPointerCastable(StoredVec->getType(), SubVT, DL)) { + // StoredVec cannot be directly casted to SubVT type. + // May happen when StoredVec is Floating point vector but SubVT is a + // pointer type. + const Type* SrcElemTy = cast(StoredVec->getType())->getElementType(); + if (ScalarTy->isPointerTy() && SrcElemTy->isFloatingPointTy()) { + // Needs two step casting. First bitcast floating type to an int type. + // Int type can be safely casted to the pointer type. + Type* IntTy = IntegerType::getIntNTy(Member->getContext(), SrcElemTy->getPrimitiveSizeInBits()); + VectorType *VecIntTy = VectorType::get(IntTy, VF); + StoredVec = Builder.CreateBitOrPointerCast(StoredVec, VecIntTy); + } else { + // Casting is not possible. + return; + } + } StoredVec = Builder.CreateBitOrPointerCast(StoredVec, SubVT); + } StoredVecs.push_back(StoredVec); }