Skip to content

Optimise modulo comparison operation #54650

@ilinpv

Description

@ilinpv

When the result of a modulo by constant is compared against another constant we can sometimes avoid the expensive modulo instructions as described in https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87290

For example

int
mod16 (int a, int b)
{
  return a % 16 == 13;
}

with -O2 using this on aarch64 GCC produces better code: https://godbolt.org/z/9K8Gd1Eaf

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions