-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ClampUnsafeAccesses pass. #6294
Conversation
Inject clamps around func calls h(...) when all the following conditions hold: 1. The call is in an indexing context, such as: f(x) = g(h(x)); 2. The schedule for f uses RoundUp or ShiftInwards 3. h is not compute_at within f's produce node 4. The FuncValueBounds of h are smaller than those of its type Conditions (3) and (4) are not yet implemented.
src/ClampUnsafeAccesses.cpp
Outdated
if (is_inside_indexing) { | ||
auto bounds = func_bounds.at({call->name, call->value_index}); | ||
if (bounds_smaller_than_type(bounds, call->type)) { | ||
// TODO: check that the clamped function's allocation bounds might be wider than its compute bounds |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please open an issue or reuse the existing issue to track this, and add the issue ID to the comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I figured this PR was blocked on implementing this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Opened issue #6297 to track this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It fixes a miscompilation. I think we can live with a few extra ops instead in the short term.
// TODO(#6297): check that the clamped function's allocation bounds might be wider than its compute bounds | ||
|
||
auto [new_args, changed] = mutate_with_changes(call->args); | ||
Expr new_call = changed ? call : Call::make(call->type, call->name, new_args, call->call_type, call->func, call->value_index, call->image, call->param); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(resurrecting a zombie PR...)
Uh, is this right? Shouldn't it be !changed ? call : ...
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeeeep, that looks like a typo. Want to try changing it to see if tests fail?
Inject clamps around func calls h(...) when all the following conditions hold:
Fixes #6131