Skip to content

Unsigned shift of signed value during optimized signed divide that is only valid because of additional multiplication fails to simplify #4366

Description

@D0ntPanic

Sometimes the compiler can emit a pattern for optimized modulus where the optimized division component of the modulus
is not valid on its own. It can use an unsigned shift by a small amount during a signed division, which normally would
cause the result to be incorrect, but it can be correct if that result is later multiplied by a value, causing all
values to produce the correct result.

Because Binary Ninja first simplifies the optimized divide, then simplifies the modulus, it cannot simplify the
expression at all.

unsigned_shift

Binary with examples:

unsigned_shift.zip

See 12, 24, 36, 48, and others.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Component: CoreIssue needs changes to the coreCore: HLILIssue involves High Level ILEffort: LowIssues require < 1 week of workIL OptimizationIssue involving optimization of representation (not correctness)Impact: LowIssue is a papercut or has a good, supported workaround

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions