[PATCH] IRBuilder - add a CreateShuffleVector function that takes an ArrayRef of int
Sanjay Patel
spatel at rotateright.com
Mon Mar 9 14:48:27 PDT 2015
Hi chandlerc, craig.topper, RKSimon, andreadb,
Adding this convenience function was suggested in D8086 as a way to ease creation of ShuffleVectors in AutoUpgrade and other places.
I changed one instance in AutoUpgrade as an example of the intended usage.
http://reviews.llvm.org/D8184
Files:
include/llvm/IR/IRBuilder.h
lib/IR/AutoUpgrade.cpp
Index: include/llvm/IR/IRBuilder.h
===================================================================
--- include/llvm/IR/IRBuilder.h
+++ include/llvm/IR/IRBuilder.h
@@ -1486,6 +1486,16 @@
return Insert(new ShuffleVectorInst(V1, V2, Mask), Name);
}
+ Value *CreateShuffleVector(Value *V1, Value *V2, ArrayRef<int> IntMask,
+ const Twine &Name = "") {
+ size_t MaskSize = IntMask.size();
+ SmallVector<Constant*, 8> MaskVec(MaskSize);
+ for (size_t i = 0; i != MaskSize; ++i)
+ MaskVec[i] = getInt32(IntMask[i]);
+ Value *Mask = ConstantVector::get(MaskVec);
+ return CreateShuffleVector(V1, V2, Mask, Name);
+ }
+
Value *CreateExtractValue(Value *Agg,
ArrayRef<unsigned> Idxs,
const Twine &Name = "") {
Index: lib/IR/AutoUpgrade.cpp
===================================================================
--- lib/IR/AutoUpgrade.cpp
+++ lib/IR/AutoUpgrade.cpp
@@ -560,11 +560,9 @@
CI->getArgOperand(0),
PointerType::getUnqual(VectorType::get(Type::getInt64Ty(C), 2)));
Value *Load = Builder.CreateLoad(Op);
- SmallVector<Constant *, 4> Idxs; // 0, 1, 0, 1.
- for (unsigned i = 0; i != 4; ++i)
- Idxs.push_back(Builder.getInt32(i & 1));
+ int Idxs[4] = { 0, 1, 0, 1 };
Rep = Builder.CreateShuffleVector(Load, UndefValue::get(Load->getType()),
- ConstantVector::get(Idxs));
+ Idxs);
} else if (Name == "llvm.x86.sse2.psll.dq") {
// 128-bit shift left specified in bits.
unsigned Shift = cast<ConstantInt>(CI->getArgOperand(1))->getZExtValue();
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D8184.21516.patch
Type: text/x-patch
Size: 1714 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150309/25931796/attachment.bin>
More information about the llvm-commits
mailing list