From 7876feee666ee80633209573aa74ebb03f3bc5ee Mon Sep 17 00:00:00 2001 From: Dillon Date: Mon, 13 Jul 2026 21:16:02 -0700 Subject: [PATCH] Avoid substituting buffer bounds that are defined in terms of itself --- slinky/builder/slide_and_fold_storage.cc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/slinky/builder/slide_and_fold_storage.cc b/slinky/builder/slide_and_fold_storage.cc index f413a700..c47b0215 100644 --- a/slinky/builder/slide_and_fold_storage.cc +++ b/slinky/builder/slide_and_fold_storage.cc @@ -106,6 +106,12 @@ void substitute_bounds(box_expr& bounds, const symbol_map& buffers) { void substitute_bounds(symbol_map& buffers, var buffer_id, const box_expr& bounds) { scoped_trace trace("substitute_bounds"); auto dims = make_dims_from_bounds(bounds); + // Don't substitute buffer bounds that are defined in terms of itself, e.g. from define_undef_bounds. + // It seems to work to do this, but it can generate very large expensive expressions to simplify. + for (int d = 0; d < static_cast(dims.size()); ++d) { + if (depends_on(dims[d].bounds.min, buffer_id).buffer_bounds) dims[d].bounds.min = expr(); + if (depends_on(dims[d].bounds.max, buffer_id).buffer_bounds) dims[d].bounds.max = expr(); + } for (std::size_t i = 0; i < buffers.size(); ++i) { if (!buffers[i]) continue; for (interval_expr& j : *buffers[i]) {