[llvm] [SelectionDAG] Use Magic Algorithm for Splitting UDIV/UREM by Constant (PR #154968)

Marius Kamp via llvm-commits llvm-commits at lists.llvm.org
Sat Apr 18 09:02:47 PDT 2026


mskamp wrote:

I've rebased this pull request on the latest changes to the chunk-based algorithm.

Regarding the choice of approaches (i.e., the chunk-based approach vs. the magic algorithm), I've done some benchmarks and thought a bit about the optimal choice. When we have an `UMUL_LOHI` instruction on the target (as is the case for x86-64), the magic algorithm is almost always better for `UDIV` than the chunk-based approach according to my measurements so far. For `UREM`, the chunk-based approach is better, of course. But things get complicated when we don't have an `UMUL_LOHI` or no `UADDO_CARRY` instruction. As a reasonable choice definitely needs more work, I'd stick with using the magic algorithm only for the divisors not supported by the chunk-based algortihm for this PR and investigate a better choice in follow-up work.

https://github.com/llvm/llvm-project/pull/154968


More information about the llvm-commits mailing list