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 "tqchen (via GitHub)" <gi...@apache.org> on 2026/06/11 14:04:26 UTC
[PR] [BugFix][S-TIR] RemoveStoreUndef: track undef through local-scalar buffers [tvm]
tqchen opened a new pull request, #19733:
URL: https://github.com/apache/tvm/pull/19733
After the LetStmt -> Bind flattening (#18874) and the TIRx bringup
(#18913), the TVMScript frontend lowers a let-binding such as
`val = T.undef()` into a zero-dimensional local scalar buffer rather
than a Bind/LetStmt node:
```
AllocBuffer(val, scope="local")
val[0] = T.undef()
A[0] = val[0] # for A[0] = val
A[val[0]] = 5 # for A[val] = 5
```
`RemoveStoreUndef` only tracked undef through Bind-bound Vars, so a store
whose value came from such a scalar buffer was no longer removed, and undef
reaching a buffer index through that buffer no longer raised. This regressed
`test_remove_let_undef` and `test_raise_error_for_undef_as_store_indices`.
This PR makes the locator record a buffer whose stored value contains undef
and treat any subsequent `BufferLoad` of it as undef, mirroring the prior
let-bound-Var propagation. The remover drops those undef stores, the now
dead `AllocBuffer` of the scalar buffer, and propagates the index-undef
error. The existing Bind/Var handling is retained for any remaining Bind
nodes.
All tests in `tests/python/s_tir/transform/test_s_tir_transform_remove_undef.py`
pass (6 passed).
--
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
Re: [PR] [BugFix][S-TIR] RemoveStoreUndef: track undef through local-scalar buffers [tvm]
Posted by "gemini-code-assist[bot] (via GitHub)" <gi...@apache.org>.
gemini-code-assist[bot] commented on code in PR #19733:
URL: https://github.com/apache/tvm/pull/19733#discussion_r3396554431
##########
src/s_tir/transform/remove_store_undef.cc:
##########
@@ -61,11 +69,15 @@ class StoreUndefLocator : public StmtExprVisitor {
<< "Error: T.undef() used in BufferStore expressions "
<< "must not have other side effects";
undef_stores_.insert(op);
+ // Record the destination buffer as undef-carrying so that any later
+ // BufferLoad of it propagates undef (this is the flattened form of an
+ // old let-bound undef variable, e.g. ``val = T.undef(); A[0] = val``).
+ undef_buffers_.insert(op->buffer->data.get());
Review Comment:

Unconditionally treating any buffer that has an undef store as undef-carrying is unsafe for non-scalar buffers (e.g., arrays) or buffers with mixed stores. If a multi-dimensional or non-scalar buffer has a single element stored with `T.undef()`, this implementation will:
1. Treat all subsequent loads from that buffer (at any index) as undef.
2. Completely remove the `AllocBuffer` statement for that buffer, leaving other valid stores/loads to an unallocated buffer, causing compilation or runtime errors.
To prevent this, we should only track undef propagation for **scalar buffers** (constant size of 1) and ensure they are **only** ever stored with undef values (no mixed stores).
```c
undef_stores_.insert(op);
// Record the destination buffer as undef-carrying so that any later
// BufferLoad of it propagates undef (this is the flattened form of an
// old let-bound undef variable, e.g. ``val = T.undef(); A[0] = val``).
bool is_scalar = true;
int64_t size = 1;
for (const auto& dim : op->buffer->shape) {
if (const auto* int_dim = dim.as<IntImmNode>()) {
size *= int_dim->value;
} else {
is_scalar = false;
break;
}
}
if (is_scalar && size == 1) {
undef_buffers_.insert(op->buffer->data.get());
}
```
--
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
Re: [PR] [BugFix][S-TIR] RemoveStoreUndef: track undef through local-scalar buffers [tvm]
Posted by "tqchen (via GitHub)" <gi...@apache.org>.
tqchen closed pull request #19733: [BugFix][S-TIR] RemoveStoreUndef: track undef through local-scalar buffers
URL: https://github.com/apache/tvm/pull/19733
--
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