Use a bool& parameter for overflow tracking in IRMatcher#9119
Open
Use a bool& parameter for overflow tracking in IRMatcher#9119
Conversation
Previously the high bit of halide_type_t::lanes was repurposed as a sticky signed-integer-overflow flag during constant folding. That bit collides with real lane counts for vectors with many lanes. Replace it with a bool& overflow parameter threaded through make_folded_const and constant_fold_bin_op, with each folding entry point declaring its own local flag. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Previously make_folded_const returned void and reported overflow via a bool& out parameter. Per review, callers could miss handling overflow because the parameter is easy to overlook. Make the function return the overflow flag directly, marked [[nodiscard]] so the compiler enforces that callers consider it. Callers that recurse accumulate via |=; consume sites (Overflows, Overflow predicates, evaluate_predicate's gating logic) read the return value directly. The constant_fold_bin_op helpers still take bool& since they already return the computed value. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
[[nodiscard]] is a C++11 attribute and must precede the storage-class/inline specifier; placing it after HALIDE_ALWAYS_INLINE (which expands to "inline __attribute__((always_inline))") trips "an attribute list cannot appear here" in clang-tidy. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Previously the high bit of halide_type_t::lanes was repurposed as a sticky signed-integer-overflow flag during constant folding. That bit collides with real lane counts for vectors with many lanes. Replace it with a bool& overflow parameter threaded through make_folded_const and constant_fold_bin_op, with each folding entry point declaring its own local flag.
This is in preparation for increasing the limit on vector lanes, but also makes the code less clever and more explicit. Slight code size reduction.
Edit: It is now returned as a no-discard bool, rather than being an out parameter.