[TargetLowering][RISCV][X86] Support even divisors in expandDIVREMByConstant.
authorCraig Topper <craig.topper@sifive.com>
Sun, 23 Oct 2022 05:01:03 +0000 (22:01 -0700)
committerCraig Topper <craig.topper@sifive.com>
Sun, 23 Oct 2022 06:35:33 +0000 (23:35 -0700)
commitf6a7b47820904c5e69cc4f133d382c74a87c44e8
tree79750243022e45eaf72a50c8b9d7bd70ea495550
parentdb25f51e37baf3b804ec541a834d3fd0b6b44118
[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