@@ -452,26 +452,25 @@ Instruction *InstCombiner::visitExtractElementInst(ExtractElementInst &EI) {
452
452
// / If V is a shuffle of values that ONLY returns elements from either LHS or
453
453
// / RHS, return the shuffle mask and true. Otherwise, return false.
454
454
static bool collectSingleShuffleElements (Value *V, Value *LHS, Value *RHS,
455
- SmallVectorImpl<Constant* > &Mask) {
455
+ SmallVectorImpl<int > &Mask) {
456
456
assert (LHS->getType () == RHS->getType () &&
457
457
" Invalid CollectSingleShuffleElements" );
458
458
unsigned NumElts = cast<VectorType>(V->getType ())->getNumElements ();
459
459
460
460
if (isa<UndefValue>(V)) {
461
- Mask.assign (NumElts, UndefValue::get ( Type::getInt32Ty (V-> getContext ())) );
461
+ Mask.assign (NumElts, - 1 );
462
462
return true ;
463
463
}
464
464
465
465
if (V == LHS) {
466
466
for (unsigned i = 0 ; i != NumElts; ++i)
467
- Mask.push_back (ConstantInt::get ( Type::getInt32Ty (V-> getContext ()), i) );
467
+ Mask.push_back (i );
468
468
return true ;
469
469
}
470
470
471
471
if (V == RHS) {
472
472
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);
475
474
return true ;
476
475
}
477
476
@@ -490,7 +489,7 @@ static bool collectSingleShuffleElements(Value *V, Value *LHS, Value *RHS,
490
489
// transitively ok.
491
490
if (collectSingleShuffleElements (VecOp, LHS, RHS, Mask)) {
492
491
// If so, update the mask to reflect the inserted undef.
493
- Mask[InsertedIdx] = UndefValue::get ( Type::getInt32Ty (V-> getContext ())) ;
492
+ Mask[InsertedIdx] = - 1 ;
494
493
return true ;
495
494
}
496
495
} else if (ExtractElementInst *EI = dyn_cast<ExtractElementInst>(ScalarOp)){
@@ -507,14 +506,10 @@ static bool collectSingleShuffleElements(Value *V, Value *LHS, Value *RHS,
507
506
if (collectSingleShuffleElements (VecOp, LHS, RHS, Mask)) {
508
507
// If so, update the mask to reflect the inserted value.
509
508
if (EI->getOperand (0 ) == LHS) {
510
- Mask[InsertedIdx % NumElts] =
511
- ConstantInt::get (Type::getInt32Ty (V->getContext ()),
512
- ExtractedIdx);
509
+ Mask[InsertedIdx % NumElts] = ExtractedIdx;
513
510
} else {
514
511
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;
518
513
}
519
514
return true ;
520
515
}
@@ -546,12 +541,11 @@ static void replaceExtractElements(InsertElementInst *InsElt,
546
541
// values. The mask selects all of the values of the original vector followed
547
542
// by as many undefined values as needed to create a vector of the same length
548
543
// as the inserted-to vector.
549
- SmallVector<Constant *, 16 > ExtendMask;
550
- IntegerType *IntType = Type::getInt32Ty (InsElt->getContext ());
544
+ SmallVector<int , 16 > ExtendMask;
551
545
for (unsigned i = 0 ; i < NumExtElts; ++i)
552
- ExtendMask.push_back (ConstantInt::get (IntType, i) );
546
+ ExtendMask.push_back (i );
553
547
for (unsigned i = NumExtElts; i < NumInsElts; ++i)
554
- ExtendMask.push_back (UndefValue::get (IntType) );
548
+ ExtendMask.push_back (- 1 );
555
549
556
550
Value *ExtVecOp = ExtElt->getVectorOperand ();
557
551
auto *ExtVecOpInst = dyn_cast<Instruction>(ExtVecOp);
@@ -579,8 +573,8 @@ static void replaceExtractElements(InsertElementInst *InsElt,
579
573
if (InsElt->hasOneUse () && isa<InsertElementInst>(InsElt->user_back ()))
580
574
return ;
581
575
582
- auto *WideVec = new ShuffleVectorInst (ExtVecOp, UndefValue::get (ExtVecType),
583
- ConstantVector ::get (ExtendMask) );
576
+ auto *WideVec =
577
+ new ShuffleVectorInst (ExtVecOp, UndefValue ::get (ExtVecType), ExtendMask );
584
578
585
579
// Insert the new shuffle after the vector operand of the extract is defined
586
580
// (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,
613
607
// / often been chosen carefully to be efficiently implementable on the target.
614
608
using ShuffleOps = std::pair<Value *, Value *>;
615
609
616
- static ShuffleOps collectShuffleElements (Value *V,
617
- SmallVectorImpl<Constant *> &Mask,
610
+ static ShuffleOps collectShuffleElements (Value *V, SmallVectorImpl<int > &Mask,
618
611
Value *PermittedRHS,
619
612
InstCombiner &IC) {
620
613
assert (V->getType ()->isVectorTy () && " Invalid shuffle!" );
621
614
unsigned NumElts = cast<VectorType>(V->getType ())->getNumElements ();
622
615
623
616
if (isa<UndefValue>(V)) {
624
- Mask.assign (NumElts, UndefValue::get ( Type::getInt32Ty (V-> getContext ())) );
617
+ Mask.assign (NumElts, - 1 );
625
618
return std::make_pair (
626
619
PermittedRHS ? UndefValue::get (PermittedRHS->getType ()) : V, nullptr );
627
620
}
628
621
629
622
if (isa<ConstantAggregateZero>(V)) {
630
- Mask.assign (NumElts, ConstantInt::get ( Type::getInt32Ty (V-> getContext ()), 0 ) );
623
+ Mask.assign (NumElts, 0 );
631
624
return std::make_pair (V, nullptr );
632
625
}
633
626
@@ -658,15 +651,13 @@ static ShuffleOps collectShuffleElements(Value *V,
658
651
// We tried our best, but we can't find anything compatible with RHS
659
652
// further up the chain. Return a trivial shuffle.
660
653
for (unsigned i = 0 ; i < NumElts; ++i)
661
- Mask[i] = ConstantInt::get ( Type::getInt32Ty (V-> getContext ()), i) ;
654
+ Mask[i] = i ;
662
655
return std::make_pair (V, nullptr );
663
656
}
664
657
665
658
unsigned NumLHSElts =
666
659
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;
670
661
return std::make_pair (LR.first , RHS);
671
662
}
672
663
@@ -676,9 +667,7 @@ static ShuffleOps collectShuffleElements(Value *V,
676
667
unsigned NumLHSElts =
677
668
cast<VectorType>(EI->getOperand (0 )->getType ())->getNumElements ();
678
669
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);
682
671
return std::make_pair (EI->getOperand (0 ), PermittedRHS);
683
672
}
684
673
@@ -694,7 +683,7 @@ static ShuffleOps collectShuffleElements(Value *V,
694
683
695
684
// Otherwise, we can't do anything fancy. Return an identity vector.
696
685
for (unsigned i = 0 ; i != NumElts; ++i)
697
- Mask.push_back (ConstantInt::get ( Type::getInt32Ty (V-> getContext ()), i) );
686
+ Mask.push_back (i );
698
687
return std::make_pair (V, nullptr );
699
688
}
700
689
@@ -815,12 +804,12 @@ static Instruction *foldInsSequenceIntoSplat(InsertElementInst &InsElt) {
815
804
FirstIE = InsertElementInst::Create (UndefVec, SplatVal, Zero, " " , &InsElt);
816
805
817
806
// 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 );
819
808
for (unsigned i = 0 ; i != NumElements; ++i)
820
809
if (!ElementPresent[i])
821
- Mask[i] = UndefValue::get (Int32Ty) ;
810
+ Mask[i] = - 1 ;
822
811
823
- return new ShuffleVectorInst (FirstIE, UndefVec, ConstantVector::get ( Mask) );
812
+ return new ShuffleVectorInst (FirstIE, UndefVec, Mask);
824
813
}
825
814
826
815
// / Try to fold an insert element into an existing splat shuffle by changing
@@ -996,33 +985,29 @@ static Instruction *foldConstantInsEltIntoShuffle(InsertElementInst &InsElt) {
996
985
!match (IEI->getOperand (1 ), m_Constant (Val[1 ])))
997
986
return nullptr ;
998
987
SmallVector<Constant *, 16 > Values (NumElts);
999
- SmallVector<Constant * , 16 > Mask (NumElts);
988
+ SmallVector<int , 16 > Mask (NumElts);
1000
989
auto ValI = std::begin (Val);
1001
990
// Generate new constant vector and mask.
1002
991
// We have 2 values/masks from the insertelements instructions. Insert them
1003
992
// into new value/mask vectors.
1004
993
for (uint64_t I : InsertIdx) {
1005
994
if (!Values[I]) {
1006
- assert (!Mask[I]);
1007
995
Values[I] = *ValI;
1008
- Mask[I] = ConstantInt::get (Type::getInt32Ty (InsElt.getContext ()),
1009
- NumElts + I);
996
+ Mask[I] = NumElts + I;
1010
997
}
1011
998
++ValI;
1012
999
}
1013
1000
// Remaining values are filled with 'undef' values.
1014
1001
for (unsigned I = 0 ; I < NumElts; ++I) {
1015
1002
if (!Values[I]) {
1016
- assert (!Mask[I]);
1017
1003
Values[I] = UndefValue::get (InsElt.getType ()->getElementType ());
1018
- Mask[I] = ConstantInt::get ( Type::getInt32Ty (InsElt. getContext ()), I) ;
1004
+ Mask[I] = I ;
1019
1005
}
1020
1006
}
1021
1007
// Create new operands for a shuffle that includes the constant of the
1022
1008
// original insertelt.
1023
1009
return new ShuffleVectorInst (IEI->getOperand (0 ),
1024
- ConstantVector::get (Values),
1025
- ConstantVector::get (Mask));
1010
+ ConstantVector::get (Values), Mask);
1026
1011
}
1027
1012
return nullptr ;
1028
1013
}
@@ -1084,7 +1069,7 @@ Instruction *InstCombiner::visitInsertElementInst(InsertElementInst &IE) {
1084
1069
1085
1070
// Try to form a shuffle from a chain of extract-insert ops.
1086
1071
if (isShuffleRootCandidate (IE)) {
1087
- SmallVector<Constant* , 16 > Mask;
1072
+ SmallVector<int , 16 > Mask;
1088
1073
ShuffleOps LR = collectShuffleElements (&IE, Mask, nullptr , *this );
1089
1074
1090
1075
// The proposed shuffle may be trivial, in which case we shouldn't
@@ -1093,8 +1078,7 @@ Instruction *InstCombiner::visitInsertElementInst(InsertElementInst &IE) {
1093
1078
// We now have a shuffle of LHS, RHS, Mask.
1094
1079
if (LR.second == nullptr )
1095
1080
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);
1098
1082
}
1099
1083
}
1100
1084
}
@@ -1907,9 +1891,8 @@ static Instruction *foldIdentityPaddedShuffles(ShuffleVectorInst &Shuf) {
1907
1891
int WideElts = Shuffle0->getType ()->getNumElements ();
1908
1892
assert (WideElts > NarrowElts && " Unexpected types for identity with padding" );
1909
1893
1910
- Type *I32Ty = IntegerType::getInt32Ty (Shuf.getContext ());
1911
1894
ArrayRef<int > Mask = Shuf.getShuffleMask ();
1912
- SmallVector<Constant * , 16 > NewMask (Mask.size (), UndefValue::get (I32Ty) );
1895
+ SmallVector<int , 16 > NewMask (Mask.size (), - 1 );
1913
1896
for (int i = 0 , e = Mask.size (); i != e; ++i) {
1914
1897
if (Mask[i] == -1 )
1915
1898
continue ;
@@ -1929,13 +1912,13 @@ static Instruction *foldIdentityPaddedShuffles(ShuffleVectorInst &Shuf) {
1929
1912
// element is offset down to adjust for the narrow vector widths.
1930
1913
if (Mask[i] < WideElts) {
1931
1914
assert (Mask[i] < NarrowElts && " Unexpected shuffle mask" );
1932
- NewMask[i] = ConstantInt::get (I32Ty, Mask[i]) ;
1915
+ NewMask[i] = Mask[i];
1933
1916
} else {
1934
1917
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);
1936
1919
}
1937
1920
}
1938
- return new ShuffleVectorInst (X, Y, ConstantVector::get ( NewMask) );
1921
+ return new ShuffleVectorInst (X, Y, NewMask);
1939
1922
}
1940
1923
1941
1924
Instruction *InstCombiner::visitShuffleVectorInst (ShuffleVectorInst &SVI) {
0 commit comments