[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 12:04:57 PDT 2022


efriedma added a comment.

In D130862#3691501 <https://reviews.llvm.org/D130862#3691501>, @hiraditya wrote:

>> a / 5, and a%10 etc.
>
> Is it possible that the processor already does these tricks internally to improve the performance of these operations?

We're concerned here about cases where the numerator doesn't fit into one word.  x86 has an instruction for division where the numerator is two words, but no other commonly used target does.  And even on x86, it's slow.

In D130862#3691456 <https://reviews.llvm.org/D130862#3691456>, @craig.topper wrote:

> In D130862#3691418 <https://reviews.llvm.org/D130862#3691418>, @efriedma wrote:
>
>> - 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.
>
> That's also what gcc does. This interacts poorly with DivRemPairs. If we have a both a division and remainder DivRemPairs rewrites the remainder in terms of division. If we're going to use remainder to do the division, then what DivRemPairs is doing is the wrong direction.
>
> My immediate next step was looking at extending this patch to UDIV using this method for the same constant divisors.

It might be worth to compare this to algorithm 4 from https://gmplib.org/~tege/division-paper.pdf .


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