[all-commits] [llvm/llvm-project] 696406: [SelectionDAG] Use Magic Algorithm for Splitting U...
Marius Kamp via All-commits
all-commits at lists.llvm.org
Fri May 1 10:24:29 PDT 2026
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 696406fbd585e497ebc766f0f066fa660b4b57fc
https://github.com/llvm/llvm-project/commit/696406fbd585e497ebc766f0f066fa660b4b57fc
Author: Marius Kamp <msk at posteo.org>
Date: 2026-05-01 (Fri, 01 May 2026)
Changed paths:
M llvm/include/llvm/CodeGen/TargetLowering.h
M llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
M llvm/test/CodeGen/RISCV/urem-vector-lkk.ll
M llvm/test/CodeGen/X86/divide-by-constant.ll
M llvm/test/CodeGen/X86/divmod128.ll
M llvm/test/CodeGen/X86/i128-udiv.ll
Log Message:
-----------
[SelectionDAG] Use Magic Algorithm for Splitting UDIV/UREM by Constant (#154968)
For integer types twice as large as a legal type, we have previously
generated a library call if another splitting technique was not
applicable.
With this change, we use an adaption of the Magic algorithm. This
algorithm is also used for UDIV/UREM by constants on legal types. The
implementation introduced here is a simple port of the already existing
implementation to types twice the size of a legal type. The core idea of
this algorithm is to replace (udiv x c) for a constant c with the bits
higher or equal to the s-th bit of the multiplication of x by (2^s +
o)/c
for some s and o. More details are available in Henry S. Warren, Jr.:
"Hacker's Delight", chapter 10.
An efficient handling of UDIV/UREM by constants on types twice as large
as a legal type is mostly relevant for 32-bit platforms. But some
projects may also benefit on 64-bit platforms. For example, the `fmt`
library for C++ uses 128-bit unsigned divisions by 100 and 10000, which
have not been covered by the previously existing optimizations.
Closes #137514.
To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications
More information about the All-commits
mailing list