Skip to content

Commit 968a25c

Browse files
committed
fixup! Add and use VectorType::getWithSizeAndScalar.
1 parent 86692b0 commit 968a25c

File tree

3 files changed

+21
-16
lines changed

3 files changed

+21
-16
lines changed

clang/lib/CodeGen/CGCall.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1377,14 +1377,8 @@ static llvm::Value *CreateCoercedLoad(Address Src, llvm::Type *Ty,
13771377
auto *PoisonVec = llvm::PoisonValue::get(ScalableDstTy);
13781378
llvm::Value *Result = CGF.Builder.CreateInsertVector(
13791379
ScalableDstTy, PoisonVec, Load, uint64_t(0), "cast.scalable");
1380-
ScalableDstTy = cast<llvm::ScalableVectorType>(Ty);
1381-
if (ScalableDstTy->getElementType()->isIntegerTy(1) &&
1382-
!ScalableDstTy->getElementCount().isKnownMultipleOf(8) &&
1383-
FixedSrcTy->getElementType()->isIntegerTy(8))
1384-
ScalableDstTy = llvm::ScalableVectorType::get(
1385-
ScalableDstTy->getElementType(),
1386-
llvm::alignTo<8>(
1387-
ScalableDstTy->getElementCount().getKnownMinValue()));
1380+
ScalableDstTy = cast<llvm::ScalableVectorType>(
1381+
llvm::VectorType::getWithSizeAndScalar(ScalableDstTy, Ty));
13881382
if (Result->getType() != ScalableDstTy)
13891383
Result = CGF.Builder.CreateBitCast(Result, ScalableDstTy);
13901384
if (Result->getType() != Ty)

clang/lib/CodeGen/CGExprScalar.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2502,14 +2502,8 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) {
25022502
llvm::Value *PoisonVec = llvm::PoisonValue::get(ScalableDstTy);
25032503
llvm::Value *Result = Builder.CreateInsertVector(
25042504
ScalableDstTy, PoisonVec, Src, uint64_t(0), "cast.scalable");
2505-
ScalableDstTy = cast<llvm::ScalableVectorType>(DstTy);
2506-
if (ScalableDstTy->getElementType()->isIntegerTy(1) &&
2507-
!ScalableDstTy->getElementCount().isKnownMultipleOf(8) &&
2508-
FixedSrcTy->getElementType()->isIntegerTy(8))
2509-
ScalableDstTy = llvm::ScalableVectorType::get(
2510-
ScalableDstTy->getElementType(),
2511-
llvm::alignTo<8>(
2512-
ScalableDstTy->getElementCount().getKnownMinValue()));
2505+
ScalableDstTy = cast<llvm::ScalableVectorType>(
2506+
llvm::VectorType::getWithSizeAndScalar(ScalableDstTy, DstTy));
25132507
if (Result->getType() != ScalableDstTy)
25142508
Result = Builder.CreateBitCast(Result, ScalableDstTy);
25152509
if (Result->getType() != DstTy)

llvm/include/llvm/IR/DerivedTypes.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,23 @@ class VectorType : public Type {
554554
return VectorType::get(VTy->getElementType(), EltCnt * 2);
555555
}
556556

557+
/// This static method attempts to construct a VectorType with the same
558+
/// size-in-bits as SizeTy but with an element type that matches the scalar
559+
/// type of EltTy. The VectorType is returned on success, nullptr otherwise.
560+
static VectorType *getWithSizeAndScalar(VectorType *SizeTy, Type *EltTy) {
561+
if (SizeTy->getScalarType() == EltTy->getScalarType())
562+
return SizeTy;
563+
564+
unsigned EltSize = EltTy->getScalarSizeInBits();
565+
if (!SizeTy->getPrimitiveSizeInBits().isKnownMultipleOf(EltSize))
566+
return nullptr;
567+
568+
ElementCount EC = SizeTy->getElementCount()
569+
.multiplyCoefficientBy(SizeTy->getScalarSizeInBits())
570+
.divideCoefficientBy(EltSize);
571+
return VectorType::get(EltTy->getScalarType(), EC);
572+
}
573+
557574
/// Return true if the specified type is valid as a element type.
558575
static bool isValidElementType(Type *ElemTy);
559576

0 commit comments

Comments
 (0)