@@ -732,8 +732,8 @@ Type *LegalizeBufferContentTypesVisitor::legalNonAggregateFor(Type *T) {
732
732
ElemTy = VT->getElementType ();
733
733
}
734
734
if (isa<PointerType, ScalableVectorType>(ElemTy))
735
- // Pointers are always big enough, and scalable vectors shouldn't crash the
736
- // pass .
735
+ // Pointers are always big enough, and we'll let scalable vectors through to
736
+ // fail in codegen .
737
737
return T;
738
738
unsigned ElemSize = DL.getTypeSizeInBits (ElemTy).getFixedValue ();
739
739
if (isPowerOf2_32 (ElemSize) && ElemSize >= 16 && ElemSize <= 128 ) {
@@ -855,7 +855,10 @@ void LegalizeBufferContentTypesVisitor::getVecSlices(
855
855
856
856
Value *LegalizeBufferContentTypesVisitor::extractSlice (Value *Vec, VecSlice S,
857
857
const Twine &Name) {
858
- if (!isa<FixedVectorType>(Vec->getType ()))
858
+ auto *VecVT = dyn_cast<FixedVectorType>(Vec->getType ());
859
+ if (!VecVT)
860
+ return Vec;
861
+ if (S.Length == VecVT->getNumElements () && S.Index == 0 )
859
862
return Vec;
860
863
if (S.Length == 1 )
861
864
return IRB.CreateExtractElement (Vec, S.Index ,
@@ -868,7 +871,10 @@ Value *LegalizeBufferContentTypesVisitor::extractSlice(Value *Vec, VecSlice S,
868
871
Value *LegalizeBufferContentTypesVisitor::insertSlice (Value *Whole, Value *Part,
869
872
VecSlice S,
870
873
const Twine &Name) {
871
- if (!isa<FixedVectorType>(Whole->getType ()))
874
+ auto *WholeVT = dyn_cast<FixedVectorType>(Whole->getType ());
875
+ if (!WholeVT)
876
+ return Part;
877
+ if (S.Length == WholeVT->getNumElements () && S.Index == 0 )
872
878
return Part;
873
879
if (S.Length == 1 ) {
874
880
return IRB.CreateInsertElement (Whole, Part, S.Index ,
@@ -904,23 +910,24 @@ bool LegalizeBufferContentTypesVisitor::visitLoadImpl(
904
910
llvm::enumerate (ST->elements (), Layout->getMemberOffsets ())) {
905
911
AggIdxs.push_back (I);
906
912
Changed |= visitLoadImpl (OrigLI, ElemTy, AggIdxs,
907
- AggByteOff + Offset.getKnownMinValue (), Result,
913
+ AggByteOff + Offset.getFixedValue (), Result,
908
914
Name + " ." + Twine (I));
909
915
AggIdxs.pop_back ();
910
916
}
911
917
return Changed;
912
918
}
913
919
if (auto *AT = dyn_cast<ArrayType>(PartType)) {
914
920
Type *ElemTy = AT->getElementType ();
915
- TypeSize AllocSize = DL.getTypeAllocSizeInBits (ElemTy);
921
+ TypeSize AllocSize = DL.getTypeAllocSize (ElemTy);
916
922
if (!(ElemTy->isSingleValueType () &&
917
- DL.getTypeSizeInBits (ElemTy) == AllocSize && !ElemTy->isVectorTy ())) {
923
+ DL.getTypeSizeInBits (ElemTy) == 8 * AllocSize &&
924
+ !ElemTy->isVectorTy ())) {
918
925
bool Changed = false ;
919
926
for (auto I : llvm::iota_range<uint32_t >(0 , AT->getNumElements (),
920
927
/* Inclusive=*/ false )) {
921
928
AggIdxs.push_back (I);
922
929
Changed |= visitLoadImpl (OrigLI, ElemTy, AggIdxs,
923
- AggByteOff + I * AllocSize.getKnownMinValue (),
930
+ AggByteOff + I * AllocSize.getFixedValue (),
924
931
Result, Name + Twine (I));
925
932
AggIdxs.pop_back ();
926
933
}
@@ -1027,25 +1034,26 @@ std::pair<bool, bool> LegalizeBufferContentTypesVisitor::visitStoreImpl(
1027
1034
for (auto [I, ElemTy, Offset] :
1028
1035
llvm::enumerate (ST->elements (), Layout->getMemberOffsets ())) {
1029
1036
AggIdxs.push_back (I);
1030
- Changed |= std::get<0 >(visitStoreImpl (
1031
- OrigSI, ElemTy, AggIdxs, AggByteOff + Offset.getKnownMinValue (),
1032
- Name + " ." + Twine (I)));
1037
+ Changed |= std::get<0 >(visitStoreImpl (OrigSI, ElemTy, AggIdxs,
1038
+ AggByteOff + Offset.getFixedValue (),
1039
+ Name + " ." + Twine (I)));
1033
1040
AggIdxs.pop_back ();
1034
1041
}
1035
1042
return std::make_pair (Changed, /* ModifiedInPlace=*/ false );
1036
1043
}
1037
1044
if (auto *AT = dyn_cast<ArrayType>(PartType)) {
1038
1045
Type *ElemTy = AT->getElementType ();
1039
- TypeSize AllocSize = DL.getTypeAllocSizeInBits (ElemTy);
1046
+ TypeSize AllocSize = DL.getTypeAllocSize (ElemTy);
1040
1047
if (!(ElemTy->isSingleValueType () &&
1041
- DL.getTypeSizeInBits (ElemTy) == AllocSize && !ElemTy->isVectorTy ())) {
1048
+ DL.getTypeSizeInBits (ElemTy) == 8 * AllocSize &&
1049
+ !ElemTy->isVectorTy ())) {
1042
1050
bool Changed = false ;
1043
1051
for (auto I : llvm::iota_range<uint32_t >(0 , AT->getNumElements (),
1044
1052
/* Inclusive=*/ false )) {
1045
1053
AggIdxs.push_back (I);
1046
1054
Changed |= std::get<0 >(visitStoreImpl (
1047
- OrigSI, ElemTy, AggIdxs,
1048
- AggByteOff + I * AllocSize. getKnownMinValue (), Name + Twine (I)));
1055
+ OrigSI, ElemTy, AggIdxs, AggByteOff + I * AllocSize. getFixedValue (),
1056
+ Name + Twine (I)));
1049
1057
AggIdxs.pop_back ();
1050
1058
}
1051
1059
return std::make_pair (Changed, /* ModifiedInPlace=*/ false );
0 commit comments