You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by GitBox <gi...@apache.org> on 2023/01/06 18:20:49 UTC

[GitHub] [tvm] vinx13 commented on a diff in pull request #13710: [TIR] Fix dtype mismatch error due to LetStmt

vinx13 commented on code in PR #13710:
URL: https://github.com/apache/tvm/pull/13710#discussion_r1063673395


##########
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:
   it's possible to do this without revisiting. We can only visit value at the beginning, and update the vmap before visiting body



-- 
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: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org