[clang] [RISCV] Improve casting between i1 scalable vectors and i8 fixed vectors for -mrvv-vector-bits (PR #139190)
Craig Topper via cfe-commits
cfe-commits at lists.llvm.org
Tue May 13 10:07:34 PDT 2025
================
@@ -1366,19 +1366,29 @@ static llvm::Value *CreateCoercedLoad(Address Src, llvm::Type *Ty,
// If we are casting a fixed i8 vector to a scalable i1 predicate
// vector, use a vector insert and bitcast the result.
if (ScalableDstTy->getElementType()->isIntegerTy(1) &&
- ScalableDstTy->getElementCount().isKnownMultipleOf(8) &&
FixedSrcTy->getElementType()->isIntegerTy(8)) {
ScalableDstTy = llvm::ScalableVectorType::get(
FixedSrcTy->getElementType(),
- ScalableDstTy->getElementCount().getKnownMinValue() / 8);
+ llvm::divideCeil(
+ ScalableDstTy->getElementCount().getKnownMinValue(), 8));
}
if (ScalableDstTy->getElementType() == FixedSrcTy->getElementType()) {
auto *Load = CGF.Builder.CreateLoad(Src);
auto *PoisonVec = llvm::PoisonValue::get(ScalableDstTy);
llvm::Value *Result = CGF.Builder.CreateInsertVector(
ScalableDstTy, PoisonVec, Load, uint64_t(0), "cast.scalable");
- if (ScalableDstTy != Ty)
- Result = CGF.Builder.CreateBitCast(Result, Ty);
+ ScalableDstTy = cast<llvm::ScalableVectorType>(Ty);
+ if (ScalableDstTy->getElementType()->isIntegerTy(1) &&
+ !ScalableDstTy->getElementCount().isKnownMultipleOf(8) &&
+ FixedSrcTy->getElementType()->isIntegerTy(8))
+ ScalableDstTy = llvm::ScalableVectorType::get(
+ ScalableDstTy->getElementType(),
+ llvm::alignTo<8>(
+ ScalableDstTy->getElementCount().getKnownMinValue()));
----------------
topperc wrote:
I replaced only line 1387. I see now I was supposed to replaced 1380-1387. That works.
https://github.com/llvm/llvm-project/pull/139190
More information about the cfe-commits
mailing list