Skip to content

Commit 0828ecd

Browse files
committed
[FIX][TIRx] Preserve buffer shapes during statement simplification
1 parent e6d50ee commit 0828ecd

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

‎src/tirx/transform/stmt_simplify.cc‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,23 @@ UnchangedOr<Stmt> StmtSimplifier::Mutate_(const ForNode* op, InplaceMode inplace
138138
return Parent::Mutate_(op, inplace_mode);
139139
}
140140

141+
UnchangedOr<Expr> StmtSimplifier::Mutate_(const CallNode* op, InplaceMode inplace_mode) {
142+
// Buffer metadata is preserved by this pass, including its explicit shape operands.
143+
if (op->op.same_as(builtin::alloc_buffer())) return ffi::Unchanged();
144+
if (op->op.same_as(builtin::decl_buffer())) {
145+
auto data = this->Mutate(op->args[0], inplace_mode);
146+
if (data.UnchangedOrSameAs(op->args[0])) return ffi::Unchanged();
147+
if (inplace_mode == InplaceMode::kAllow) {
148+
const_cast<CallNode*>(op)->args.Set(0, std::move(data).ValueUnchecked());
149+
return ffi::Unchanged();
150+
}
151+
auto copy = ffi::make_object<CallNode>(*op);
152+
copy->args.Set(0, std::move(data).ValueUnchecked());
153+
return Expr(std::move(copy));
154+
}
155+
return Parent::Mutate_(op, inplace_mode);
156+
}
157+
141158
UnchangedOr<Stmt> StmtSimplifier::Mutate_(const BindNode* op, InplaceMode inplace_mode) {
142159
auto prim_value = op->value.as<PrimExpr>();
143160
if (!prim_value) {

‎src/tirx/transform/stmt_simplify.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ class StmtSimplifier : public IRMutatorWithAnalyzer {
7272

7373
UnchangedOr<Stmt> Mutate_(const BindNode* op, InplaceMode inplace_mode) override;
7474

75+
UnchangedOr<Expr> Mutate_(const CallNode* op, InplaceMode inplace_mode) override;
76+
7577
UnchangedOr<Stmt> Mutate_(const IfThenElseNode* op, InplaceMode inplace_mode) override;
7678

7779
// eliminate useless stores

0 commit comments

Comments
 (0)