llvm.org GIT mirror llvm / f4d18ab
IR: Add a shufflevector mask commutation helper function. NFC. Summary: Following up on Sanjay's suggetion in D32955, move this functionality into ShuffleVectornstruction. Reviewers: spatel, RKSimon Reviewed By: RKSimon Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D32956 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@302420 91177308-0d34-0410-b5e6-96231b3b80d8 Zvi Rackover 2 years ago
3 changed file(s) with 21 addition(s) and 7 deletion(s). Raw diff Collapse all Expand all
22602260 return Mask;
22612261 }
22622262
2263 /// Change values in a shuffle permute mask assuming the two vector operands
2264 /// of length InVecNumElts have swapped position.
2265 static void commuteShuffleMask(MutableArrayRef Mask,
2266 unsigned InVecNumElts) {
2267 for (int &Idx : Mask) {
2268 if (Idx == -1)
2269 continue;
2270 Idx = Idx < (int)InVecNumElts ? Idx + InVecNumElts : Idx - InVecNumElts;
2271 assert(Idx >= 0 && Idx < (int)InVecNumElts * 2 &&
2272 "shufflevector mask index out of range");
2273 }
2274 }
2275
22632276 // Methods for support type inquiry through isa, cast, and dyn_cast:
22642277 static inline bool classof(const Instruction *I) {
22652278 return I->getOpcode() == Instruction::ShuffleVector;
41254125 // second one.
41264126 if (Op0Const && !Op1Const) {
41274127 std::swap(Op0, Op1);
4128 for (int &Idx : Indices) {
4129 if (Idx == -1)
4130 continue;
4131 Idx = Idx < (int)InVecNumElts ? Idx + InVecNumElts : Idx - InVecNumElts;
4132 assert(Idx >= 0 && Idx < (int)InVecNumElts * 2 &&
4133 "shufflevector mask index out of range");
4134 }
4128 ShuffleVectorInst::commuteShuffleMask(Indices, InVecNumElts);
41354129 Mask = ConstantDataVector::get(
41364130 Mask->getContext(),
41374131 makeArrayRef(reinterpret_cast(Indices.data()),
2020 #include "llvm/IR/Module.h"
2121 #include "llvm/IR/NoFolder.h"
2222 #include "llvm/IR/Operator.h"
23 #include "gmock/gmock-matchers.h"
2324 #include "gtest/gtest.h"
2425 #include
2526
739740 EXPECT_EQ(BB1.get(), Handle.getCaseSuccessor());
740741 }
741742
743 TEST(InstructionsTest, CommuteShuffleMask) {
744 SmallVector Indices({-1, 0, 7});
745 ShuffleVectorInst::commuteShuffleMask(Indices, 4);
746 EXPECT_THAT(Indices, testing::ContainerEq(ArrayRef({-1, 4, 3})));
747 }
748
742749 } // end anonymous namespace
743750 } // end namespace llvm