Skip to content

Use a bool& parameter for overflow tracking in IRMatcher#9119

Open
abadams wants to merge 3 commits intomainfrom
abadams/ir_match_flags
Open

Use a bool& parameter for overflow tracking in IRMatcher#9119
abadams wants to merge 3 commits intomainfrom
abadams/ir_match_flags

Conversation

@abadams
Copy link
Copy Markdown
Member

@abadams abadams commented May 3, 2026

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.

abadams and others added 3 commits May 3, 2026 14:28
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant