Skip to content

Commit

Permalink
Don't deduce unreachability from predicated out of bounds stores (#7874)
Browse files Browse the repository at this point in the history
Fixes #7873
  • Loading branch information
abadams authored Oct 4, 2023
1 parent a24071c commit c31e8f7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/Simplify_Stmts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,12 +300,13 @@ Stmt Simplify::visit(const Store *op) {
ExprInfo index_info;
Expr index = mutate(op->index, &index_info);

// If the store is fully out of bounds, drop it.
// If the store is fully unconditional and out of bounds, drop it.
// This should only occur inside branches that make the store unreachable,
// but perhaps the branch was hard to prove constant true or false. This
// provides an alternative mechanism to simplify these unreachable stores.
string alloc_extent_name = op->name + ".total_extent_bytes";
if (bounds_and_alignment_info.contains(alloc_extent_name)) {
if (is_const_one(op->predicate) &&
bounds_and_alignment_info.contains(alloc_extent_name)) {
if (index_info.max_defined && index_info.max < 0) {
in_unreachable = true;
return Evaluate::make(unreachable());
Expand Down
20 changes: 20 additions & 0 deletions test/correctness/fuzz_schedule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,26 @@ int main(int argc, char **argv) {
check_blur_output(buf, correct);
}

// https://github.com/halide/Halide/issues/7873
{
Func input("input");
Func local_sum("local_sum");
Func blurry("blurry");
Var x("x"), y("y");
RVar yryf;
input(x, y) = 2 * x + 5 * y;
RDom r(-2, 5, -2, 5, "rdom_r");
local_sum(x, y) = 0;
local_sum(x, y) += input(x + r.x, y + r.y);
blurry(x, y) = cast<int32_t>(local_sum(x, y) / 25);
Var xo, xi;
local_sum.split(x, xo, xi, 4, TailStrategy::PredicateStores);
local_sum.update(0).unscheduled();
Pipeline p({blurry});
Buffer<int> buf = p.realize({32, 32});
check_blur_output(buf, correct);
}

printf("Success!\n");

return 0;
Expand Down

0 comments on commit c31e8f7

Please sign in to comment.