[llvm-commits] [llvm] r129509 - /llvm/trunk/lib/Transforms/Scalar/ScalarReplAggregates.cpp
Mon Ping Wang
wangmp at apple.com
Thu Apr 14 12:25:46 PDT 2011
Thanks for the comments. Fixed in r129532.
-- Mon Ping
On Apr 14, 2011, at 8:49 AM, Chris Lattner wrote:
> On Apr 14, 2011, at 1:04 AM, Mon P Wang wrote:
>> Author: wangmp
>> Date: Thu Apr 14 03:04:01 2011
>> New Revision: 129509
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=129509&view=rev
>> Log:
>> Cleanup r129472 by using a utility routine as suggested by Eli.
>
> Thanks Mon Ping, some more minor nits :)
>
>> +++ llvm/trunk/lib/Transforms/Scalar/ScalarReplAggregates.cpp Thu Apr 14 03:04:01 2011
>> @@ -676,6 +676,37 @@
>> llvm_unreachable("Invalid type for a partial vector access of an alloca!");
>> }
>>
>> +/// CreateShuffleVectorCast - Creates a shuffle vector to convert one vector
>> +/// to another vector of the same element type which has the same allocation
>> +/// size but different primitive sizes (e.g. <3 x i32> and <4 x i32>).
>> +static Value *CreateShuffleVectorCast(Value *FromVal, const Type *ToType,
>> + IRBuilder<> &Builder) {
>> + const Type *FromType = FromVal->getType();
>> + const VectorType *FromVTy = dyn_cast<VectorType>(FromType);
>> + const VectorType *ToVTy = dyn_cast<VectorType>(ToType);
>> + assert(FromVTy && ToVTy &&
>> + (ToVTy->getElementType() == FromVTy->getElementType()) &&
>> + "Vectors must have the same element type");
>
> Instead of using dyn_cast + assert(!null), please just use cast<>
>
>> + LLVMContext &Context = FromVal->getContext();
>> + Value *UnV = UndefValue::get(FromType);
>> + unsigned numEltsFrom = FromVTy->getNumElements();
>> + unsigned numEltsTo = ToVTy->getNumElements();
>> +
>> + SmallVector<Constant*, 3> Args;
>> + unsigned minNumElts = std::min(numEltsFrom, numEltsTo);
>> + unsigned i;
>> + for (i=0; i != minNumElts; ++i)
>> + Args.push_back(ConstantInt::get(Type::getInt32Ty(Context), i));
>
> You can use Builder.getInt32Ty() to simplify the code, or Builder.getInt32(i) to simplify it even more.
>
> -Chris
More information about the llvm-commits
mailing list