gemini-code-assist[bot] commented on code in PR #18421:
URL: https://github.com/apache/tvm/pull/18421#discussion_r2532631337
##########
src/target/source/codegen_c.cc:
##########
@@ -1121,12 +1121,19 @@ void CodeGenC::VisitStmt_(const AssertStmtNode* op) {
void CodeGenC::VisitStmt_(const ForNode* op) {
std::string extent = PrintExpr(op->extent);
+ std::string step = op->step.has_value()? PrintExpr(*op->step) : "";
PrintIndent();
std::string vid = AllocVarID(op->loop_var.get());
ICHECK(is_zero(op->min));
stream << "for (";
PrintType(op->loop_var.dtype(), stream);
- stream << ' ' << vid << " = 0; " << vid << " < " << extent << "; ++" << vid
<< ") {\n";
+ stream << ' ' << vid << " = 0; " << vid << " < " << extent << "; ";
+ if (step.empty()) {
+ stream << "++" << vid;
+ } else {
+ stream << vid << " += " << step;
+ }
+ stream << ") {\n";
int for_scope = BeginScope();
PrintStmt(op->body);
this->EndScope(for_scope);
Review Comment:
It looks like you've made good progress on generalizing the C codegen for
`ForNode` to handle non-zero `min` and non-trivial `step`, which aligns with my
previous suggestion. However, I noticed that the `ICHECK(is_zero(op->min));` on
line 1129 is still present. This check will prevent the code from handling
non-zero `min` values, contradicting the new logic you've introduced. Please
remove this `ICHECK` to fully enable the generalized loop behavior.
This is a `high` severity issue as it prevents the intended functionality of
supporting non-zero `min` values in loops.
```suggestion
std::string begin_str = PrintExpr(op->min);
PrimExpr end = is_zero(op->min) ? op->extent :
arith::Analyzer().Simplify(op->min + op->extent);
std::string end_str = PrintExpr(end);
std::string step_str = op->step.has_value() ? PrintExpr(*op->step) : "";
PrintIndent();
std::string vid = AllocVarID(op->loop_var.get());
stream << "for (";
PrintType(op->loop_var.dtype(), stream);
stream << ' ' << vid << " = " << begin_str << "; " << vid << " < " <<
end_str << "; ";
if (step_str.empty()) {
stream << "++" << vid;
} else {
stream << vid << " += " << step_str;
}
stream << ") {\n";
int for_scope = BeginScope();
PrintStmt(op->body);
this->EndScope(for_scope);
```
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]