Skip to content

Extend limited-divisor-space and variable power-of-two optimizations to sdiv. - #5161

Draft
copybara-service[bot] wants to merge 1 commit into
mainfrom
test_1001108234
Draft

copybara-service[bot] wants to merge 1 commit into
mainfrom
test_1001108234

Conversation

@copybara-service

Copy link
Copy Markdown

Extend limited-divisor-space and variable power-of-two optimizations to sdiv.

Signed division (sdiv) previously handled only single constant divisors inline in MatchSignedDivide and variable power-of-two divisors in a separate MatchSDivByVariablePowerOfTwo helper, missing lookup-table generation when range or state analysis restricts a signed divisor to a small set of values.

Generalize MatchWithLimitedDivisorSpace and its supporting division helpers (DivisionConstants, DivisionByPowerOfTwo, ComputeDivisionConstants, MakeDivByZeroResult, GetPow2Shift, MakePow2ShiftNode, MakeDivByConstantValues, MakeDivByPowerOfTwo, MakeDivLutNode, and GetPow2DivStrategy) to handle both Op::kUDiv and Op::kSDiv. Signed divisors with power-of-two magnitude (including ±1, ±2^k, and MinSigned) use shift/negate operations, while arbitrary signed constants use multiplication by invariant integers and arithmetic shifts. Remove the duplicate constant-divisor logic in MatchSignedDivide and the standalone MatchSDivByVariablePowerOfTwo helper.

…to sdiv.

Signed division (`sdiv`) previously handled only single constant divisors inline in `MatchSignedDivide` and variable power-of-two divisors in a separate `MatchSDivByVariablePowerOfTwo` helper, missing lookup-table generation when range or state analysis restricts a signed divisor to a small set of values.

Generalize `MatchWithLimitedDivisorSpace` and its supporting division helpers (`DivisionConstants`, `DivisionByPowerOfTwo`, `ComputeDivisionConstants`, `MakeDivByZeroResult`, `GetPow2Shift`, `MakePow2ShiftNode`, `MakeDivByConstantValues`, `MakeDivByPowerOfTwo`, `MakeDivLutNode`, and `GetPow2DivStrategy`) to handle both `Op::kUDiv` and `Op::kSDiv`. Signed divisors with power-of-two magnitude (including `±1`, `±2^k`, and `MinSigned`) use shift/negate operations, while arbitrary signed constants use multiplication by invariant integers and arithmetic shifts. Remove the duplicate constant-divisor logic in `MatchSignedDivide` and the standalone `MatchSDivByVariablePowerOfTwo` helper.

PiperOrigin-RevId: 1001108234

This branch has not been deployed

No deployments
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