[TargetLowering][RISCV][X86] Support even divisors in expandDIVREMByConstant.
authorCraig Topper <craig.topper@sifive.com>
Mon, 10 Oct 2022 17:46:29 +0000 (10:46 -0700)
committerCraig Topper <craig.topper@sifive.com>
Mon, 10 Oct 2022 18:02:22 +0000 (11:02 -0700)
commitd4facda414b6b9b8b1a34bc7e6b7c15172775318
tree43855f4bcefda57d374bf6492e8934f2cb53aa96
parent9eb11856cf1fa62c5408594fafc973eb2d380cdb
[TargetLowering][RISCV][X86] Support even divisors in expandDIVREMByConstant.

If the divisor is even, we can first shift the dividend and divisor
right by the number of trailing zeros. Now the divisor is odd and we
can do the original algorithm to calculate a remainder. Then we shift
that remainder left by the number of trailing zeros and add the bits
that were shifted out of the dividend.

Reviewed By: RKSimon

Differential Revision: https://reviews.llvm.org/D135541
llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
llvm/test/CodeGen/RISCV/split-udiv-by-constant.ll
llvm/test/CodeGen/RISCV/split-urem-by-constant.ll
llvm/test/CodeGen/X86/divide-by-constant.ll
llvm/test/CodeGen/X86/divmod128.ll