[PATCH] D35498: [LoopVectorizer] Use two step casting for float to pointer type.
Manoj Gupta via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 17 12:14:45 PDT 2017
manojgupta created this revision.
Herald added subscribers: mzolotukhin, rengolin.
Is is illegal to drectly cast a floating point type to a pointer type
even if the types have same size. Use a two-step casting by bitcasting
to integer and integer to pointer to avoid a crash.
Fixes PR33804.
https://reviews.llvm.org/D35498
Files:
lib/Transforms/Vectorize/LoopVectorize.cpp
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<VectorType>(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);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D35498.106916.patch
Type: text/x-patch
Size: 1580 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170717/ec3acdc4/attachment.bin>
More information about the llvm-commits
mailing list