[HW] Make sure the index type for arrays is at least i1#9733
[HW] Make sure the index type for arrays is at least i1#9733fzi-hielscher merged 4 commits intollvm:mainfrom
Conversation
When converting bitcast ops, we collect all unpacked integers to cast to a packed integer. If we encounter an array, we create a get operation for the array elements which require the index type. The index type is calculated using llvm::Log2_64_Ceil of the number of elements in the array. If the number of elements was 1 then prior to this fix the index type would be i0, resulting in a crash.
|
Could you point out where this crashes? I guess somewhere at the end of the Arcilator pipeline? Technically this pass is not specific to Arcilator and in general we consider |
I have updated the description with full crash information |
|
Thanks.
The |
We are definitely not doing this as we have our own tool and we are not using the ArcToLLVM conversion pass. We are directly using
Now if this canonicalization is required then it should be part of ConvertHWToLLVM or similar. However, is there any reason not to fix it in HWConvertBitcasts? Do we expect to get |
fzi-hielscher
left a comment
There was a problem hiding this comment.
Okay, thanks for the context.
However, is there any reason not to fix it in HWConvertBitcasts? Do we expect to get
i0from other places?
Verilog does not support zero-width types, so in your scenario you are unlikely to encounter them. But other frontends do use them and they are a legal and supported type within the core dialects. Which is why I am against quietly introducing a rule that you should avoid them.
I'm okay with landing this as a temporary fix. But I think what we actually want is a dedicated "HWRemoveZeroWidthTypes" pass that actively strips them from the IR instead of relying on folders and canonicalizers.
Co-authored-by: Leon Hielscher <47524191+fzi-hielscher@users.noreply.github.com>
Co-authored-by: Leon Hielscher <47524191+fzi-hielscher@users.noreply.github.com>
When converting bitcast ops, we collect all unpacked integers to cast to a packed integer. If we encounter an array, we create a get operation for the array elements which require the index type. The index type is calculated using
lvm::Log2_64_Ceilof the number of elements in the array. If the number of elements was 1 then prior to this fix the index type would bei0, resulting in a crash when lowering to llvm-ir.So if we have a code like this:
Which is converted to mlir using ImportVerilog to produce:
It generates the following llvm-mlir
Which, when lowering to llvm-ir, causes an assert:
/home/ucsdev/pcabot/develop/circt/llvm/llvm/lib/IR/Type.cpp:319: static IntegerType *llvm::IntegerType::get(LLVMContext &, unsigned int): AssertionNumBits >= MIN_INT_BITS && "bitwidth too small"' failed.`Stack trace: