@@ -1366,19 +1366,23 @@ static llvm::Value *CreateCoercedLoad(Address Src, llvm::Type *Ty,
13661366 // If we are casting a fixed i8 vector to a scalable i1 predicate
13671367 // vector, use a vector insert and bitcast the result.
13681368 if (ScalableDstTy->getElementType ()->isIntegerTy (1 ) &&
1369- ScalableDstTy->getElementCount ().isKnownMultipleOf (8 ) &&
13701369 FixedSrcTy->getElementType ()->isIntegerTy (8 )) {
13711370 ScalableDstTy = llvm::ScalableVectorType::get (
13721371 FixedSrcTy->getElementType (),
1373- ScalableDstTy->getElementCount ().getKnownMinValue () / 8 );
1372+ llvm::divideCeil (
1373+ ScalableDstTy->getElementCount ().getKnownMinValue (), 8 ));
13741374 }
13751375 if (ScalableDstTy->getElementType () == FixedSrcTy->getElementType ()) {
13761376 auto *Load = CGF.Builder .CreateLoad (Src);
13771377 auto *PoisonVec = llvm::PoisonValue::get (ScalableDstTy);
13781378 llvm::Value *Result = CGF.Builder .CreateInsertVector (
13791379 ScalableDstTy, PoisonVec, Load, uint64_t (0 ), " cast.scalable" );
1380- if (ScalableDstTy != Ty)
1381- Result = CGF.Builder .CreateBitCast (Result, Ty);
1380+ ScalableDstTy = cast<llvm::ScalableVectorType>(
1381+ llvm::VectorType::getWithSizeAndScalar (ScalableDstTy, Ty));
1382+ if (Result->getType () != ScalableDstTy)
1383+ Result = CGF.Builder .CreateBitCast (Result, ScalableDstTy);
1384+ if (Result->getType () != Ty)
1385+ Result = CGF.Builder .CreateExtractVector (Ty, Result, uint64_t (0 ));
13821386 return Result;
13831387 }
13841388 }
@@ -1476,8 +1480,14 @@ CoerceScalableToFixed(CodeGenFunction &CGF, llvm::FixedVectorType *ToTy,
14761480 // If we are casting a scalable i1 predicate vector to a fixed i8
14771481 // vector, first bitcast the source.
14781482 if (FromTy->getElementType ()->isIntegerTy (1 ) &&
1479- FromTy->getElementCount ().isKnownMultipleOf (8 ) &&
14801483 ToTy->getElementType () == CGF.Builder .getInt8Ty ()) {
1484+ if (!FromTy->getElementCount ().isKnownMultipleOf (8 )) {
1485+ FromTy = llvm::ScalableVectorType::get (
1486+ FromTy->getElementType (),
1487+ llvm::alignTo<8 >(FromTy->getElementCount ().getKnownMinValue ()));
1488+ llvm::Value *ZeroVec = llvm::Constant::getNullValue (FromTy);
1489+ V = CGF.Builder .CreateInsertVector (FromTy, ZeroVec, V, uint64_t (0 ));
1490+ }
14811491 FromTy = llvm::ScalableVectorType::get (
14821492 ToTy->getElementType (),
14831493 FromTy->getElementCount ().getKnownMinValue () / 8 );
0 commit comments