masahi commented on code in PR #13710:
URL: https://github.com/apache/tvm/pull/13710#discussion_r1063815756
##########
src/tir/ir/data_type_rewriter.cc:
##########
@@ -107,6 +107,26 @@ Stmt DataTypeLegalizer::VisitStmt_(const AttrStmtNode* op)
{
return StmtExprMutator::VisitStmt_(op);
}
+Stmt DataTypeLegalizer::VisitStmt_(const LetStmtNode* op) {
+ PrimExpr value = this->VisitExpr(op->value);
+ Stmt body = this->VisitStmt(op->body);
+ if (value.same_as(op->value) && body.same_as(op->body)) {
+ return GetRef<Stmt>(op);
+ } else if (value.dtype() == op->var->dtype) {
+ auto n = CopyOnWrite(op);
+ n->value = std::move(value);
+ n->body = std::move(body);
+ return Stmt(n);
+ } else {
+ auto new_var = op->var.copy_with_dtype(value.dtype());
+ Map<Var, PrimExpr> vmap{{op->var, new_var}};
+ auto new_body = SubstituteWithDataTypeLegalization(
+ std::move(body), [&](const Var& var) { return vmap.Get(var); });
+ // We need to visit the body again to insert additional casts
Review Comment:
We can pass `op->body` to `SubstituteWithDataTypeLegalization`, but we still
need to visit `new_body` after `SubstituteWithDataTypeLegalization`. In that
case, the output of the first visit,`this->VisitStmt(op->body)` at the top is
only used for the first two `if / else` branches.
So this doesn't work, because the body of the Let has outdated variable
dtype. Is this your understanding as well, or are you suggesting something else?
```
auto new_body = SubstituteWithDataTypeLegalization(
std::move(op->body), [&](const Var& var) { return vmap.Get(var); });
// We need to visit the body again to insert additional casts
return LetStmt(new_var, value, new_body, op->span);
```
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]