You are viewing a plain text version of this content. The canonical link for it is here.
Posted to discuss-archive@tvm.apache.org by "gemini-code-assist[bot] (via GitHub)" <gi...@apache.org> on 2026/06/25 02:48:22 UTC
Re: [PR] [REFACTOR][IR] Clean up PrimType follow-ups [tvm]
gemini-code-assist[bot] commented on code in PR #19884:
URL: https://github.com/apache/tvm/pull/19884#discussion_r3471557137
##########
include/tvm/ir/base_expr.h:
##########
@@ -214,7 +214,19 @@ class PrimType final : public Type {
* This uses the same packed sub-byte dtype sizing rule as runtime tensors.
* Scalable vector types have no compile-time storage size and are rejected.
*/
- TVM_DLL size_t StorageBytes() const;
+ TVM_FFI_INLINE size_t StorageBytes() const {
+ DLDataType dtype = get()->dtype;
+ int16_t encoded_lanes = static_cast<int16_t>(dtype.lanes);
+ if (TVM_FFI_PREDICT_FALSE(encoded_lanes < 0)) {
+ TVM_FFI_THROW(InternalError)
+ << "Cannot compute compile-time storage bytes for non-fixed vector type " << dtype;
+ }
+ if (dtype.code == kDLUInt && dtype.bits == 1 && dtype.lanes == 1) {
+ return 1;
+ }
+ return static_cast<size_t>(
+ (static_cast<uint64_t>(dtype.bits) * static_cast<uint64_t>(dtype.lanes) + 7) / 8);
+ }
Review Comment:

The special case check for `kDLUInt` with 1 bit and 1 lane is redundant. The general formula `(bits * lanes + 7) / 8` already correctly evaluates to `1` when `bits == 1` and `lanes == 1` (i.e., `(1 * 1 + 7) / 8 = 1`). Removing this check simplifies the code and avoids unnecessary branching.
```c
return static_cast<size_t>(
(static_cast<uint64_t>(dtype.bits) * static_cast<uint64_t>(dtype.lanes) + 7) / 8);
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org