Skip to content

Commit 444bfae

Browse files
d0kmemfrob
authored andcommitted
Upgrade users of 'new ShuffleVectorInst' to pass indices as an int array
No functionality change intended.
1 parent 76eacee commit 444bfae

File tree

4 files changed

+41
-66
lines changed

4 files changed

+41
-66
lines changed

llvm/lib/Target/AMDGPU/AMDGPUPrintfRuntimeBinding.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -484,12 +484,8 @@ bool AMDGPUPrintfRuntimeBinding::lowerPrintfForGpu(
484484
uint32_t EleSize = ArgType->getScalarSizeInBits();
485485
uint32_t TotalSize = EleCount * EleSize;
486486
if (EleCount == 3) {
487-
IntegerType *Int32Ty = Type::getInt32Ty(ArgType->getContext());
488-
Constant *Indices[4] = {
489-
ConstantInt::get(Int32Ty, 0), ConstantInt::get(Int32Ty, 1),
490-
ConstantInt::get(Int32Ty, 2), ConstantInt::get(Int32Ty, 2)};
491-
Constant *Mask = ConstantVector::get(Indices);
492-
ShuffleVectorInst *Shuffle = new ShuffleVectorInst(Arg, Arg, Mask);
487+
ShuffleVectorInst *Shuffle =
488+
new ShuffleVectorInst(Arg, Arg, ArrayRef<int>{0, 1, 2, 2});
493489
Shuffle->insertBefore(Brnch);
494490
Arg = Shuffle;
495491
ArgType = Arg->getType();

llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1923,8 +1923,8 @@ static Instruction *optimizeVectorResizeWithIntegerBitCasts(Value *InVal,
19231923
// Now that the element types match, get the shuffle mask and RHS of the
19241924
// shuffle to use, which depends on whether we're increasing or decreasing the
19251925
// size of the input.
1926-
SmallVector<uint32_t, 16> ShuffleMaskStorage;
1927-
ArrayRef<uint32_t> ShuffleMask;
1926+
SmallVector<int, 16> ShuffleMaskStorage;
1927+
ArrayRef<int> ShuffleMask;
19281928
Value *V2;
19291929

19301930
// Produce an identify shuffle mask for the src vector.
@@ -1963,9 +1963,7 @@ static Instruction *optimizeVectorResizeWithIntegerBitCasts(Value *InVal,
19631963
ShuffleMask = ShuffleMaskStorage;
19641964
}
19651965

1966-
return new ShuffleVectorInst(InVal, V2,
1967-
ConstantDataVector::get(V2->getContext(),
1968-
ShuffleMask));
1966+
return new ShuffleVectorInst(InVal, V2, ShuffleMask);
19691967
}
19701968

19711969
static bool isMultipleOfTypeSize(unsigned Value, Type *Ty) {

llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1937,20 +1937,19 @@ static Instruction *canonicalizeSelectToShuffle(SelectInst &SI) {
19371937
return nullptr;
19381938

19391939
unsigned NumElts = cast<VectorType>(CondVal->getType())->getNumElements();
1940-
SmallVector<Constant *, 16> Mask;
1940+
SmallVector<int, 16> Mask;
19411941
Mask.reserve(NumElts);
1942-
Type *Int32Ty = Type::getInt32Ty(CondVal->getContext());
19431942
for (unsigned i = 0; i != NumElts; ++i) {
19441943
Constant *Elt = CondC->getAggregateElement(i);
19451944
if (!Elt)
19461945
return nullptr;
19471946

19481947
if (Elt->isOneValue()) {
19491948
// If the select condition element is true, choose from the 1st vector.
1950-
Mask.push_back(ConstantInt::get(Int32Ty, i));
1949+
Mask.push_back(i);
19511950
} else if (Elt->isNullValue()) {
19521951
// If the select condition element is false, choose from the 2nd vector.
1953-
Mask.push_back(ConstantInt::get(Int32Ty, i + NumElts));
1952+
Mask.push_back(i + NumElts);
19541953
} else if (isa<UndefValue>(Elt)) {
19551954
// Undef in a select condition (choose one of the operands) does not mean
19561955
// the same thing as undef in a shuffle mask (any value is acceptable), so
@@ -1962,8 +1961,7 @@ static Instruction *canonicalizeSelectToShuffle(SelectInst &SI) {
19621961
}
19631962
}
19641963

1965-
return new ShuffleVectorInst(SI.getTrueValue(), SI.getFalseValue(),
1966-
ConstantVector::get(Mask));
1964+
return new ShuffleVectorInst(SI.getTrueValue(), SI.getFalseValue(), Mask);
19671965
}
19681966

19691967
/// If we have a select of vectors with a scalar condition, try to convert that

llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp

Lines changed: 32 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -452,26 +452,25 @@ Instruction *InstCombiner::visitExtractElementInst(ExtractElementInst &EI) {
452452
/// If V is a shuffle of values that ONLY returns elements from either LHS or
453453
/// RHS, return the shuffle mask and true. Otherwise, return false.
454454
static bool collectSingleShuffleElements(Value *V, Value *LHS, Value *RHS,
455-
SmallVectorImpl<Constant*> &Mask) {
455+
SmallVectorImpl<int> &Mask) {
456456
assert(LHS->getType() == RHS->getType() &&
457457
"Invalid CollectSingleShuffleElements");
458458
unsigned NumElts = cast<VectorType>(V->getType())->getNumElements();
459459

460460
if (isa<UndefValue>(V)) {
461-
Mask.assign(NumElts, UndefValue::get(Type::getInt32Ty(V->getContext())));
461+
Mask.assign(NumElts, -1);
462462
return true;
463463
}
464464

465465
if (V == LHS) {
466466
for (unsigned i = 0; i != NumElts; ++i)
467-
Mask.push_back(ConstantInt::get(Type::getInt32Ty(V->getContext()), i));
467+
Mask.push_back(i);
468468
return true;
469469
}
470470

471471
if (V == RHS) {
472472
for (unsigned i = 0; i != NumElts; ++i)
473-
Mask.push_back(ConstantInt::get(Type::getInt32Ty(V->getContext()),
474-
i+NumElts));
473+
Mask.push_back(i + NumElts);
475474
return true;
476475
}
477476

@@ -490,7 +489,7 @@ static bool collectSingleShuffleElements(Value *V, Value *LHS, Value *RHS,
490489
// transitively ok.
491490
if (collectSingleShuffleElements(VecOp, LHS, RHS, Mask)) {
492491
// If so, update the mask to reflect the inserted undef.
493-
Mask[InsertedIdx] = UndefValue::get(Type::getInt32Ty(V->getContext()));
492+
Mask[InsertedIdx] = -1;
494493
return true;
495494
}
496495
} else if (ExtractElementInst *EI = dyn_cast<ExtractElementInst>(ScalarOp)){
@@ -507,14 +506,10 @@ static bool collectSingleShuffleElements(Value *V, Value *LHS, Value *RHS,
507506
if (collectSingleShuffleElements(VecOp, LHS, RHS, Mask)) {
508507
// If so, update the mask to reflect the inserted value.
509508
if (EI->getOperand(0) == LHS) {
510-
Mask[InsertedIdx % NumElts] =
511-
ConstantInt::get(Type::getInt32Ty(V->getContext()),
512-
ExtractedIdx);
509+
Mask[InsertedIdx % NumElts] = ExtractedIdx;
513510
} else {
514511
assert(EI->getOperand(0) == RHS);
515-
Mask[InsertedIdx % NumElts] =
516-
ConstantInt::get(Type::getInt32Ty(V->getContext()),
517-
ExtractedIdx + NumLHSElts);
512+
Mask[InsertedIdx % NumElts] = ExtractedIdx + NumLHSElts;
518513
}
519514
return true;
520515
}
@@ -546,12 +541,11 @@ static void replaceExtractElements(InsertElementInst *InsElt,
546541
// values. The mask selects all of the values of the original vector followed
547542
// by as many undefined values as needed to create a vector of the same length
548543
// as the inserted-to vector.
549-
SmallVector<Constant *, 16> ExtendMask;
550-
IntegerType *IntType = Type::getInt32Ty(InsElt->getContext());
544+
SmallVector<int, 16> ExtendMask;
551545
for (unsigned i = 0; i < NumExtElts; ++i)
552-
ExtendMask.push_back(ConstantInt::get(IntType, i));
546+
ExtendMask.push_back(i);
553547
for (unsigned i = NumExtElts; i < NumInsElts; ++i)
554-
ExtendMask.push_back(UndefValue::get(IntType));
548+
ExtendMask.push_back(-1);
555549

556550
Value *ExtVecOp = ExtElt->getVectorOperand();
557551
auto *ExtVecOpInst = dyn_cast<Instruction>(ExtVecOp);
@@ -579,8 +573,8 @@ static void replaceExtractElements(InsertElementInst *InsElt,
579573
if (InsElt->hasOneUse() && isa<InsertElementInst>(InsElt->user_back()))
580574
return;
581575

582-
auto *WideVec = new ShuffleVectorInst(ExtVecOp, UndefValue::get(ExtVecType),
583-
ConstantVector::get(ExtendMask));
576+
auto *WideVec =
577+
new ShuffleVectorInst(ExtVecOp, UndefValue::get(ExtVecType), ExtendMask);
584578

585579
// Insert the new shuffle after the vector operand of the extract is defined
586580
// (as long as it's not a PHI) or at the start of the basic block of the
@@ -613,21 +607,20 @@ static void replaceExtractElements(InsertElementInst *InsElt,
613607
/// often been chosen carefully to be efficiently implementable on the target.
614608
using ShuffleOps = std::pair<Value *, Value *>;
615609

616-
static ShuffleOps collectShuffleElements(Value *V,
617-
SmallVectorImpl<Constant *> &Mask,
610+
static ShuffleOps collectShuffleElements(Value *V, SmallVectorImpl<int> &Mask,
618611
Value *PermittedRHS,
619612
InstCombiner &IC) {
620613
assert(V->getType()->isVectorTy() && "Invalid shuffle!");
621614
unsigned NumElts = cast<VectorType>(V->getType())->getNumElements();
622615

623616
if (isa<UndefValue>(V)) {
624-
Mask.assign(NumElts, UndefValue::get(Type::getInt32Ty(V->getContext())));
617+
Mask.assign(NumElts, -1);
625618
return std::make_pair(
626619
PermittedRHS ? UndefValue::get(PermittedRHS->getType()) : V, nullptr);
627620
}
628621

629622
if (isa<ConstantAggregateZero>(V)) {
630-
Mask.assign(NumElts, ConstantInt::get(Type::getInt32Ty(V->getContext()),0));
623+
Mask.assign(NumElts, 0);
631624
return std::make_pair(V, nullptr);
632625
}
633626

@@ -658,15 +651,13 @@ static ShuffleOps collectShuffleElements(Value *V,
658651
// We tried our best, but we can't find anything compatible with RHS
659652
// further up the chain. Return a trivial shuffle.
660653
for (unsigned i = 0; i < NumElts; ++i)
661-
Mask[i] = ConstantInt::get(Type::getInt32Ty(V->getContext()), i);
654+
Mask[i] = i;
662655
return std::make_pair(V, nullptr);
663656
}
664657

665658
unsigned NumLHSElts =
666659
cast<VectorType>(RHS->getType())->getNumElements();
667-
Mask[InsertedIdx % NumElts] =
668-
ConstantInt::get(Type::getInt32Ty(V->getContext()),
669-
NumLHSElts+ExtractedIdx);
660+
Mask[InsertedIdx % NumElts] = NumLHSElts + ExtractedIdx;
670661
return std::make_pair(LR.first, RHS);
671662
}
672663

@@ -676,9 +667,7 @@ static ShuffleOps collectShuffleElements(Value *V,
676667
unsigned NumLHSElts =
677668
cast<VectorType>(EI->getOperand(0)->getType())->getNumElements();
678669
for (unsigned i = 0; i != NumElts; ++i)
679-
Mask.push_back(ConstantInt::get(
680-
Type::getInt32Ty(V->getContext()),
681-
i == InsertedIdx ? ExtractedIdx : NumLHSElts + i));
670+
Mask.push_back(i == InsertedIdx ? ExtractedIdx : NumLHSElts + i);
682671
return std::make_pair(EI->getOperand(0), PermittedRHS);
683672
}
684673

@@ -694,7 +683,7 @@ static ShuffleOps collectShuffleElements(Value *V,
694683

695684
// Otherwise, we can't do anything fancy. Return an identity vector.
696685
for (unsigned i = 0; i != NumElts; ++i)
697-
Mask.push_back(ConstantInt::get(Type::getInt32Ty(V->getContext()), i));
686+
Mask.push_back(i);
698687
return std::make_pair(V, nullptr);
699688
}
700689

@@ -815,12 +804,12 @@ static Instruction *foldInsSequenceIntoSplat(InsertElementInst &InsElt) {
815804
FirstIE = InsertElementInst::Create(UndefVec, SplatVal, Zero, "", &InsElt);
816805

817806
// Splat from element 0, but replace absent elements with undef in the mask.
818-
SmallVector<Constant *, 16> Mask(NumElements, Zero);
807+
SmallVector<int, 16> Mask(NumElements, 0);
819808
for (unsigned i = 0; i != NumElements; ++i)
820809
if (!ElementPresent[i])
821-
Mask[i] = UndefValue::get(Int32Ty);
810+
Mask[i] = -1;
822811

823-
return new ShuffleVectorInst(FirstIE, UndefVec, ConstantVector::get(Mask));
812+
return new ShuffleVectorInst(FirstIE, UndefVec, Mask);
824813
}
825814

826815
/// Try to fold an insert element into an existing splat shuffle by changing
@@ -996,33 +985,29 @@ static Instruction *foldConstantInsEltIntoShuffle(InsertElementInst &InsElt) {
996985
!match(IEI->getOperand(1), m_Constant(Val[1])))
997986
return nullptr;
998987
SmallVector<Constant *, 16> Values(NumElts);
999-
SmallVector<Constant *, 16> Mask(NumElts);
988+
SmallVector<int, 16> Mask(NumElts);
1000989
auto ValI = std::begin(Val);
1001990
// Generate new constant vector and mask.
1002991
// We have 2 values/masks from the insertelements instructions. Insert them
1003992
// into new value/mask vectors.
1004993
for (uint64_t I : InsertIdx) {
1005994
if (!Values[I]) {
1006-
assert(!Mask[I]);
1007995
Values[I] = *ValI;
1008-
Mask[I] = ConstantInt::get(Type::getInt32Ty(InsElt.getContext()),
1009-
NumElts + I);
996+
Mask[I] = NumElts + I;
1010997
}
1011998
++ValI;
1012999
}
10131000
// Remaining values are filled with 'undef' values.
10141001
for (unsigned I = 0; I < NumElts; ++I) {
10151002
if (!Values[I]) {
1016-
assert(!Mask[I]);
10171003
Values[I] = UndefValue::get(InsElt.getType()->getElementType());
1018-
Mask[I] = ConstantInt::get(Type::getInt32Ty(InsElt.getContext()), I);
1004+
Mask[I] = I;
10191005
}
10201006
}
10211007
// Create new operands for a shuffle that includes the constant of the
10221008
// original insertelt.
10231009
return new ShuffleVectorInst(IEI->getOperand(0),
1024-
ConstantVector::get(Values),
1025-
ConstantVector::get(Mask));
1010+
ConstantVector::get(Values), Mask);
10261011
}
10271012
return nullptr;
10281013
}
@@ -1084,7 +1069,7 @@ Instruction *InstCombiner::visitInsertElementInst(InsertElementInst &IE) {
10841069

10851070
// Try to form a shuffle from a chain of extract-insert ops.
10861071
if (isShuffleRootCandidate(IE)) {
1087-
SmallVector<Constant*, 16> Mask;
1072+
SmallVector<int, 16> Mask;
10881073
ShuffleOps LR = collectShuffleElements(&IE, Mask, nullptr, *this);
10891074

10901075
// The proposed shuffle may be trivial, in which case we shouldn't
@@ -1093,8 +1078,7 @@ Instruction *InstCombiner::visitInsertElementInst(InsertElementInst &IE) {
10931078
// We now have a shuffle of LHS, RHS, Mask.
10941079
if (LR.second == nullptr)
10951080
LR.second = UndefValue::get(LR.first->getType());
1096-
return new ShuffleVectorInst(LR.first, LR.second,
1097-
ConstantVector::get(Mask));
1081+
return new ShuffleVectorInst(LR.first, LR.second, Mask);
10981082
}
10991083
}
11001084
}
@@ -1907,9 +1891,8 @@ static Instruction *foldIdentityPaddedShuffles(ShuffleVectorInst &Shuf) {
19071891
int WideElts = Shuffle0->getType()->getNumElements();
19081892
assert(WideElts > NarrowElts && "Unexpected types for identity with padding");
19091893

1910-
Type *I32Ty = IntegerType::getInt32Ty(Shuf.getContext());
19111894
ArrayRef<int> Mask = Shuf.getShuffleMask();
1912-
SmallVector<Constant *, 16> NewMask(Mask.size(), UndefValue::get(I32Ty));
1895+
SmallVector<int, 16> NewMask(Mask.size(), -1);
19131896
for (int i = 0, e = Mask.size(); i != e; ++i) {
19141897
if (Mask[i] == -1)
19151898
continue;
@@ -1929,13 +1912,13 @@ static Instruction *foldIdentityPaddedShuffles(ShuffleVectorInst &Shuf) {
19291912
// element is offset down to adjust for the narrow vector widths.
19301913
if (Mask[i] < WideElts) {
19311914
assert(Mask[i] < NarrowElts && "Unexpected shuffle mask");
1932-
NewMask[i] = ConstantInt::get(I32Ty, Mask[i]);
1915+
NewMask[i] = Mask[i];
19331916
} else {
19341917
assert(Mask[i] < (WideElts + NarrowElts) && "Unexpected shuffle mask");
1935-
NewMask[i] = ConstantInt::get(I32Ty, Mask[i] - (WideElts - NarrowElts));
1918+
NewMask[i] = Mask[i] - (WideElts - NarrowElts);
19361919
}
19371920
}
1938-
return new ShuffleVectorInst(X, Y, ConstantVector::get(NewMask));
1921+
return new ShuffleVectorInst(X, Y, NewMask);
19391922
}
19401923

19411924
Instruction *InstCombiner::visitShuffleVectorInst(ShuffleVectorInst &SVI) {

0 commit comments

Comments
 (0)