Fix SkipStages narrowing loaded by Select condition#9152
Open
abadams wants to merge 1 commit into
Open
Conversation
SkipStages::visit(Select) was combining each branch's `loaded` predicate with the select condition (via make_select / make_and). That's wrong: Halide's Select evaluates both branches and only picks one of the results, so any load inside either branch fires unconditionally. The `loaded` predicate must be the OR of both branches, ungated by the condition. The bug caused allocation bounds inference to size affected buffers down to zero whenever the runtime condition was false, while the generated code still emitted a vectorized load from them -- a heap OOB read that showed up intermittently as a valgrind use-after-free on the truncated_pyramid test. Keep `used` gated by the condition as before (with the same select/and collapse that fixed the exponential blow-up in #9147). Add a regression test in skip_stages.cpp that records the minimum producer allocation size through a custom malloc handler and verifies it's non-zero when the producer's only consumer is inside a runtime-false select branch. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #9152 +/- ##
=======================================
Coverage ? 69.35%
=======================================
Files ? 254
Lines ? 78219
Branches ? 18714
=======================================
Hits ? 54248
Misses ? 18481
Partials ? 5490 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
#9147 contained a bug: It treated Select like an if-then-else and combined the used and loaded flags in the same way. A select evaluates both sides, so the two flags need to be handled differently. This PR fixes it and adds a regression test. This is the cause of the recent failures in truncated_pyramid test - it has a Func which is loaded but not used.