@@ -370,7 +370,7 @@ Constant *Constant::getIntegerValue(Type *Ty, const APInt &V) {
370
370
371
371
// Broadcast a scalar to a vector, if necessary.
372
372
if (VectorType *VTy = dyn_cast<VectorType>(Ty))
373
- C = ConstantVector::getSplat (VTy->getNumElements (), C);
373
+ C = ConstantVector::getSplat (VTy->getElementCount (), C);
374
374
375
375
return C;
376
376
}
@@ -387,7 +387,7 @@ Constant *Constant::getAllOnesValue(Type *Ty) {
387
387
}
388
388
389
389
VectorType *VTy = cast<VectorType>(Ty);
390
- return ConstantVector::getSplat (VTy->getNumElements (),
390
+ return ConstantVector::getSplat (VTy->getElementCount (),
391
391
getAllOnesValue (VTy->getElementType ()));
392
392
}
393
393
@@ -681,15 +681,15 @@ Constant *ConstantInt::getTrue(Type *Ty) {
681
681
assert (Ty->isIntOrIntVectorTy (1 ) && " Type not i1 or vector of i1." );
682
682
ConstantInt *TrueC = ConstantInt::getTrue (Ty->getContext ());
683
683
if (auto *VTy = dyn_cast<VectorType>(Ty))
684
- return ConstantVector::getSplat (VTy->getNumElements (), TrueC);
684
+ return ConstantVector::getSplat (VTy->getElementCount (), TrueC);
685
685
return TrueC;
686
686
}
687
687
688
688
Constant *ConstantInt::getFalse (Type *Ty) {
689
689
assert (Ty->isIntOrIntVectorTy (1 ) && " Type not i1 or vector of i1." );
690
690
ConstantInt *FalseC = ConstantInt::getFalse (Ty->getContext ());
691
691
if (auto *VTy = dyn_cast<VectorType>(Ty))
692
- return ConstantVector::getSplat (VTy->getNumElements (), FalseC);
692
+ return ConstantVector::getSplat (VTy->getElementCount (), FalseC);
693
693
return FalseC;
694
694
}
695
695
@@ -712,7 +712,7 @@ Constant *ConstantInt::get(Type *Ty, uint64_t V, bool isSigned) {
712
712
713
713
// For vectors, broadcast the value.
714
714
if (VectorType *VTy = dyn_cast<VectorType>(Ty))
715
- return ConstantVector::getSplat (VTy->getNumElements (), C);
715
+ return ConstantVector::getSplat (VTy->getElementCount (), C);
716
716
717
717
return C;
718
718
}
@@ -736,7 +736,7 @@ Constant *ConstantInt::get(Type *Ty, const APInt& V) {
736
736
737
737
// For vectors, broadcast the value.
738
738
if (VectorType *VTy = dyn_cast<VectorType>(Ty))
739
- return ConstantVector::getSplat (VTy->getNumElements (), C);
739
+ return ConstantVector::getSplat (VTy->getElementCount (), C);
740
740
741
741
return C;
742
742
}
@@ -781,7 +781,7 @@ Constant *ConstantFP::get(Type *Ty, double V) {
781
781
782
782
// For vectors, broadcast the value.
783
783
if (VectorType *VTy = dyn_cast<VectorType>(Ty))
784
- return ConstantVector::getSplat (VTy->getNumElements (), C);
784
+ return ConstantVector::getSplat (VTy->getElementCount (), C);
785
785
786
786
return C;
787
787
}
@@ -793,7 +793,7 @@ Constant *ConstantFP::get(Type *Ty, const APFloat &V) {
793
793
794
794
// For vectors, broadcast the value.
795
795
if (auto *VTy = dyn_cast<VectorType>(Ty))
796
- return ConstantVector::getSplat (VTy->getNumElements (), C);
796
+ return ConstantVector::getSplat (VTy->getElementCount (), C);
797
797
798
798
return C;
799
799
}
@@ -806,7 +806,7 @@ Constant *ConstantFP::get(Type *Ty, StringRef Str) {
806
806
807
807
// For vectors, broadcast the value.
808
808
if (VectorType *VTy = dyn_cast<VectorType>(Ty))
809
- return ConstantVector::getSplat (VTy->getNumElements (), C);
809
+ return ConstantVector::getSplat (VTy->getElementCount (), C);
810
810
811
811
return C;
812
812
}
@@ -817,7 +817,7 @@ Constant *ConstantFP::getNaN(Type *Ty, bool Negative, uint64_t Payload) {
817
817
Constant *C = get (Ty->getContext (), NaN);
818
818
819
819
if (VectorType *VTy = dyn_cast<VectorType>(Ty))
820
- return ConstantVector::getSplat (VTy->getNumElements (), C);
820
+ return ConstantVector::getSplat (VTy->getElementCount (), C);
821
821
822
822
return C;
823
823
}
@@ -828,7 +828,7 @@ Constant *ConstantFP::getQNaN(Type *Ty, bool Negative, APInt *Payload) {
828
828
Constant *C = get (Ty->getContext (), NaN);
829
829
830
830
if (VectorType *VTy = dyn_cast<VectorType>(Ty))
831
- return ConstantVector::getSplat (VTy->getNumElements (), C);
831
+ return ConstantVector::getSplat (VTy->getElementCount (), C);
832
832
833
833
return C;
834
834
}
@@ -839,7 +839,7 @@ Constant *ConstantFP::getSNaN(Type *Ty, bool Negative, APInt *Payload) {
839
839
Constant *C = get (Ty->getContext (), NaN);
840
840
841
841
if (VectorType *VTy = dyn_cast<VectorType>(Ty))
842
- return ConstantVector::getSplat (VTy->getNumElements (), C);
842
+ return ConstantVector::getSplat (VTy->getElementCount (), C);
843
843
844
844
return C;
845
845
}
@@ -850,7 +850,7 @@ Constant *ConstantFP::getNegativeZero(Type *Ty) {
850
850
Constant *C = get (Ty->getContext (), NegZero);
851
851
852
852
if (VectorType *VTy = dyn_cast<VectorType>(Ty))
853
- return ConstantVector::getSplat (VTy->getNumElements (), C);
853
+ return ConstantVector::getSplat (VTy->getElementCount (), C);
854
854
855
855
return C;
856
856
}
@@ -898,7 +898,7 @@ Constant *ConstantFP::getInfinity(Type *Ty, bool Negative) {
898
898
Constant *C = get (Ty->getContext (), APFloat::getInf (Semantics, Negative));
899
899
900
900
if (VectorType *VTy = dyn_cast<VectorType>(Ty))
901
- return ConstantVector::getSplat (VTy->getNumElements (), C);
901
+ return ConstantVector::getSplat (VTy->getElementCount (), C);
902
902
903
903
return C;
904
904
}
@@ -1204,15 +1204,35 @@ Constant *ConstantVector::getImpl(ArrayRef<Constant*> V) {
1204
1204
return nullptr ;
1205
1205
}
1206
1206
1207
- Constant *ConstantVector::getSplat (unsigned NumElts, Constant *V) {
1208
- // If this splat is compatible with ConstantDataVector, use it instead of
1209
- // ConstantVector.
1210
- if ((isa<ConstantFP>(V) || isa<ConstantInt>(V)) &&
1211
- ConstantDataSequential::isElementTypeCompatible (V->getType ()))
1212
- return ConstantDataVector::getSplat (NumElts, V);
1207
+ Constant *ConstantVector::getSplat (ElementCount EC, Constant *V) {
1208
+ if (!EC.Scalable ) {
1209
+ // If this splat is compatible with ConstantDataVector, use it instead of
1210
+ // ConstantVector.
1211
+ if ((isa<ConstantFP>(V) || isa<ConstantInt>(V)) &&
1212
+ ConstantDataSequential::isElementTypeCompatible (V->getType ()))
1213
+ return ConstantDataVector::getSplat (EC.Min , V);
1213
1214
1214
- SmallVector<Constant*, 32 > Elts (NumElts, V);
1215
- return get (Elts);
1215
+ SmallVector<Constant *, 32 > Elts (EC.Min , V);
1216
+ return get (Elts);
1217
+ }
1218
+
1219
+ Type *VTy = VectorType::get (V->getType (), EC);
1220
+
1221
+ if (V->isNullValue ())
1222
+ return ConstantAggregateZero::get (VTy);
1223
+ else if (isa<UndefValue>(V))
1224
+ return UndefValue::get (VTy);
1225
+
1226
+ Type *I32Ty = Type::getInt32Ty (VTy->getContext ());
1227
+
1228
+ // Move scalar into vector.
1229
+ Constant *UndefV = UndefValue::get (VTy);
1230
+ V = ConstantExpr::getInsertElement (UndefV, V, ConstantInt::get (I32Ty, 0 ));
1231
+ // Build shuffle mask to perform the splat.
1232
+ Type *MaskTy = VectorType::get (I32Ty, EC);
1233
+ Constant *Zeros = ConstantAggregateZero::get (MaskTy);
1234
+ // Splat.
1235
+ return ConstantExpr::getShuffleVector (V, UndefV, Zeros);
1216
1236
}
1217
1237
1218
1238
ConstantTokenNone *ConstantTokenNone::get (LLVMContext &Context) {
@@ -2098,15 +2118,15 @@ Constant *ConstantExpr::getGetElementPtr(Type *Ty, Constant *C,
2098
2118
unsigned AS = C->getType ()->getPointerAddressSpace ();
2099
2119
Type *ReqTy = DestTy->getPointerTo (AS);
2100
2120
2101
- unsigned NumVecElts = 0 ;
2102
- if (C->getType ()-> isVectorTy ( ))
2103
- NumVecElts = C-> getType ()-> getVectorNumElements ();
2121
+ ElementCount EltCount = { 0 , false } ;
2122
+ if (VectorType *VecTy = dyn_cast<VectorType>( C->getType ()))
2123
+ EltCount = VecTy-> getElementCount ();
2104
2124
else for (auto Idx : Idxs)
2105
- if (Idx->getType ()-> isVectorTy ( ))
2106
- NumVecElts = Idx-> getType ()-> getVectorNumElements ();
2125
+ if (VectorType *VecTy = dyn_cast<VectorType>( Idx->getType ()))
2126
+ EltCount = VecTy-> getElementCount ();
2107
2127
2108
- if (NumVecElts )
2109
- ReqTy = VectorType::get (ReqTy, NumVecElts );
2128
+ if (EltCount. Min != 0 )
2129
+ ReqTy = VectorType::get (ReqTy, EltCount );
2110
2130
2111
2131
if (OnlyIfReducedTy == ReqTy)
2112
2132
return nullptr ;
@@ -2117,12 +2137,12 @@ Constant *ConstantExpr::getGetElementPtr(Type *Ty, Constant *C,
2117
2137
ArgVec.push_back (C);
2118
2138
for (unsigned i = 0 , e = Idxs.size (); i != e; ++i) {
2119
2139
assert ((!Idxs[i]->getType ()->isVectorTy () ||
2120
- Idxs[i]->getType ()->getVectorNumElements () == NumVecElts ) &&
2140
+ Idxs[i]->getType ()->getVectorElementCount () == EltCount ) &&
2121
2141
" getelementptr index type missmatch" );
2122
2142
2123
2143
Constant *Idx = cast<Constant>(Idxs[i]);
2124
- if (NumVecElts && !Idxs[i]->getType ()->isVectorTy ())
2125
- Idx = ConstantVector::getSplat (NumVecElts , Idx);
2144
+ if (EltCount. Min != 0 && !Idxs[i]->getType ()->isVectorTy ())
2145
+ Idx = ConstantVector::getSplat (EltCount , Idx);
2126
2146
ArgVec.push_back (Idx);
2127
2147
}
2128
2148
@@ -2759,7 +2779,7 @@ Constant *ConstantDataVector::getSplat(unsigned NumElts, Constant *V) {
2759
2779
return getFP (V->getContext (), Elts);
2760
2780
}
2761
2781
}
2762
- return ConstantVector::getSplat (NumElts, V);
2782
+ return ConstantVector::getSplat ({ NumElts, false } , V);
2763
2783
}
2764
2784
2765
2785
0 commit comments