Skip to content

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

Closed
@stevesuzuki-arm

Description

@stevesuzuki-arm
/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);
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions