Skip to content

[SVE] Assertion fails in PtrToInt with scalable vector #55410

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
stevesuzuki-arm opened this issue May 12, 2022 · 1 comment
Closed

[SVE] Assertion fails in PtrToInt with scalable vector #55410

stevesuzuki-arm opened this issue May 12, 2022 · 1 comment
Labels
backend:AArch64 llvm:crash SVE ARM Scalable Vector Extensions

Comments

@stevesuzuki-arm
Copy link
Contributor

stevesuzuki-arm commented May 12, 2022

/llvm-project/llvm/include/llvm/Support/Casting.h:269: typename llvm::cast_retty<X, Y*>::ret_type llvm::cast(Y*) [with X = llvm::FixedVectorType; Y = llvm::Type; typename llvm::cast_retty<X, Y*>::ret_type = llvm::FixedVectorType*]: Assertion `isa<X>(Val) && "cast<Ty>() argument of incompatible type!"' failed.

, which is probably called from

Constant *ConstantExpr::getPtrToInt(Constant *C, Type *DstTy,
                                    bool OnlyIfReduced) {
  assert(C->getType()->isPtrOrPtrVectorTy() &&
         "PtrToInt source must be pointer or pointer vector");
  assert(DstTy->isIntOrIntVectorTy() &&
         "PtrToInt destination must be integer or integer vector");
  assert(isa<VectorType>(C->getType()) == isa<VectorType>(DstTy));
  if (isa<VectorType>(C->getType()))
    assert(cast<FixedVectorType>(C->getType())->getNumElements() ==
               cast<FixedVectorType>(DstTy)->getNumElements() &&
           "Invalid cast between a different number of vector elements");
  return getFoldedCast(Instruction::PtrToInt, C, DstTy, OnlyIfReduced);
}

Pseudo code for this case is as follows. This happens with scalable vector and not with fixed sized vector.

{
    auto ec = ElementCount::getScalable(4);
    // auto ec = ElementCount::getFixed(4);
    Type *Int64Ty = Type::getInt64Ty(M->getContext());
    Type *Int64x4Ty = VectorType::get(Int64Ty, ec);
    PointerType *Int8PtrTy = Type::getInt8PtrTy(M->getContext());

    FunctionType *MainFty = FunctionType::get(Int64Ty, {}, false);
    Function *MainFn = Function::Create(MainFty, GlobalValue::ExternalLinkage, "main", M);
    BasicBlock *BB = BasicBlock::Create(M->getContext(), "entry", MainFn);
    Builder.SetInsertPoint(BB);

    Value *p = ConstantPointerNull::get(Int8PtrTy);
    Value *p_bc = Builder.CreateVectorSplat(ec, p);
    V = Builder.CreatePtrToInt(p_bc, Int64x4Ty);
    Builder.CreateRet(V);
}
@EugeneZelenko EugeneZelenko added backend:AArch64 SVE ARM Scalable Vector Extensions llvm:crash and removed new issue labels May 12, 2022
@llvmbot
Copy link
Member

llvmbot commented May 12, 2022

@llvm/issue-subscribers-backend-aarch64

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:AArch64 llvm:crash SVE ARM Scalable Vector Extensions
Projects
None yet
Development

No branches or pull requests

3 participants