Skip to content

DataLayout::getTypeSizeInBits may get error result when input type is !cir.long_double<!cir.f80> #1057

Closed
@PikachuHyA

Description

@PikachuHyA

I am refactoring the code in #1033 by replacing the manually implemented switch-case statements with DataLayout::getTypeSizeInBits.

During this process, I noticed that DataLayout::getTypeSizeInBits(!cir.long_double<!cir.f80>) returns 16 bits when I expected it to return 80 bits. This discrepancy is causing the test cases to fail.

For reference, you can find the relevant code in ClangIR

llvm::TypeSize
FP80Type::getTypeSizeInBits(const mlir::DataLayout &dataLayout,
mlir::DataLayoutEntryListRef params) const {
return llvm::TypeSize::getFixed(16);
}

and the LLVM IR code

// The implementation of this method is provided inline as it is particularly
// well suited to constant folding when called on a specific Type subclass.
inline TypeSize DataLayout::getTypeSizeInBits(Type *Ty) const {
assert(Ty->isSized() && "Cannot getTypeInfo() on a type that is unsized!");
switch (Ty->getTypeID()) {
case Type::LabelTyID:
return TypeSize::getFixed(getPointerSizeInBits(0));
case Type::PointerTyID:
return TypeSize::getFixed(
getPointerSizeInBits(Ty->getPointerAddressSpace()));
case Type::ArrayTyID: {
ArrayType *ATy = cast<ArrayType>(Ty);
return ATy->getNumElements() *
getTypeAllocSizeInBits(ATy->getElementType());
}
case Type::StructTyID:
// Get the layout annotation... which is lazily created on demand.
return getStructLayout(cast<StructType>(Ty))->getSizeInBits();
case Type::IntegerTyID:
return TypeSize::getFixed(Ty->getIntegerBitWidth());
case Type::HalfTyID:
case Type::BFloatTyID:
return TypeSize::getFixed(16);
case Type::FloatTyID:
return TypeSize::getFixed(32);
case Type::DoubleTyID:
return TypeSize::getFixed(64);
case Type::PPC_FP128TyID:
case Type::FP128TyID:
return TypeSize::getFixed(128);
case Type::X86_AMXTyID:
return TypeSize::getFixed(8192);
// In memory objects this is always aligned to a higher boundary, but
// only 80 bits contain information.
case Type::X86_FP80TyID:
return TypeSize::getFixed(80);
case Type::FixedVectorTyID:
case Type::ScalableVectorTyID: {
VectorType *VTy = cast<VectorType>(Ty);
auto EltCnt = VTy->getElementCount();
uint64_t MinBits = EltCnt.getKnownMinValue() *
getTypeSizeInBits(VTy->getElementType()).getFixedValue();
return TypeSize(MinBits, EltCnt.isScalable());
}
case Type::TargetExtTyID: {
Type *LayoutTy = cast<TargetExtType>(Ty)->getLayoutType();
return getTypeSizeInBits(LayoutTy);
}
default:
llvm_unreachable("DataLayout::getTypeSizeInBits(): Unsupported type");
}
}

For additional context, please see #536 .

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions