enjustli opened a new issue #8355:
URL: https://github.com/apache/tvm/issues/8355


   In such case:
   ```python
   let pid = 0
   for (i, 0, 13) {
     if (tir.likely((((pid*13) + i) < 101))) {
       C[((pid*13) + i)] = 0h
     }
     for (j, 0, 82) {
       if (tir.likely((((pid*13) + i) < 101))) {
         C[((pid*13) + i)] = function(C[((pid*13) + i)], A[((i*82) + j)])
       }
     }
   }
   ```
   if simplify skip_index_ is true, the index in output stmt still has `pid`.
   
   I found the bug in tvm/src/tir/transforms/simplify.cc 
   ```c++
   Stmt VisitStmt_(const LetStmtNode* op) {
       PrimExpr value = this->VisitExpr(op->value);
       if (CanInlineLetStmt(op)) {
         // it is fine to discard the let binding
         // because the call to simplify will always inline the var.
         analyzer_->Bind(op->var, value);
         return this->VisitStmt(op->body);
       }
       Stmt body;
       if (const auto* ptr = op->value.as<CallNode>()) {
         if (ptr->op.same_as(tx::stc_builtin::tid_map())) {
           auto range = tx::tir::GetRangeFromArray(ptr->args);
           With<VTIDContext> ctx0(analyzer_, op->var, vtid_map_[op->var.get()], 
range);
           With<ConstraintContext> ctx1(analyzer_, op->var >= range->min);
           With<ConstraintContext> ctx2(analyzer_, op->var <= (range->min + 
range->extent - 1));
           body = this->VisitStmt(op->body);
         }
       }
       if (!body.defined()) {
         body = this->VisitStmt(op->body);
       }
       if (value.same_as(op->value) && body.same_as(op->body)) {
         return GetRef<Stmt>(op);
       } else {
         auto n = this->CopyOnWrite(op);
         n->value = std::move(value);
         n->body = std::move(body);
         return Stmt(n);
       }
     }
   
     // eliminate useless stores
     Stmt VisitStmt_(const StoreNode* op) final {
       if (skip_index_) {
         auto value = this->VisitExpr(op->value);
         auto index = Analyzer().Simplify(op->index);
         if (value.same_as(op->value) && index.same_as(op->index)) {
           return GetRef<Stmt>(op);
         }
         return Store(op->buffer_var, value, index, op->predicate);
       }
   
       Stmt stmt = Parent::VisitStmt_(op);
       op = stmt.as<StoreNode>();
       if (const LoadNode* load = op->value.as<LoadNode>()) {
         if (load->buffer_var.same_as(op->buffer_var) &&
             tir::ExprDeepEqual()(load->index, op->index)) {
           return Evaluate(0);
         }
       }
       return GetRef<Stmt>(op);
     }
   ```
   
   
   
   
   


-- 
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]


Reply via email to