[opt:ra] Add range analysis support for Encode op. #3670
+187
−4
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.
Takes a whack at range analysis for the encode IR op.
Fast exact case (small input range): If the input’s IntervalSet contains only a small number of concrete values (<= kMaxIterationSize), we enumerate each possible input value, compute encode result exactly, and union the results. This produces an exact output set and is still cheap because the input set is small by construction.
Fallback (large input range): If the input range is large, we avoid enumerating it. Instead, we extract a ternary mask for the input bits (known-0 / known-1 / unknown) from the input interval set, and compute each output bit using the encode op definition ("output bit j is the OR of input bits whose index has bit j set"). If any input bit is known-1 the output bit is known-1; if none are known-1 but at least one is unknown the output bit is unknown, otherwise it’s known-0. We convert that output ternary mask into an IntervalSet (interval_ops::FromTernary), which is conservative but fast.
Fuzzed multiprocess for >15 mins on a many-core machine.