[PATCH] D130862: [LegalizeTypes] Improve splitting for urem by constant for some constants.

Eli Friedman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 1 10:30:07 PDT 2022


efriedma added a comment.

Do you have an overall plan written up somewhere?

There are a few different ways you could extend this:

- This could be extended to handle factors of two: for example, `a % 10` -> `((a / 2) % 5) * 2 + (a % 2)`.
- This could be extended to handle more factors by slicing up numbers differently.  e.g. for `a % 7`, slice the number into three 30-bit pieces, since 2^30 mod 7 = 1.
- This could possibly be used to implement division: e.g. `a / 5` -> `(a - (a % 5)) * inverse(5)`.  Not sure if this is more efficient than other approaches; might depend on the target.

On the general topic of division by constants, see also discussion on https://github.com/llvm/llvm-project/issues/56153


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130862/new/

https://reviews.llvm.org/D130862



More information about the llvm-commits mailing list