[RISCV] Use MULHU for more division by constant cases.
authorCraig Topper <craig.topper@sifive.com>
Thu, 9 Dec 2021 16:53:46 +0000 (08:53 -0800)
committerCraig Topper <craig.topper@sifive.com>
Thu, 9 Dec 2021 17:10:14 +0000 (09:10 -0800)
commit6f7de819b9dc970f41fde72b62ca4d1c55320641
tree084bc6794dc0fd523bdc032a2a4ad0b1722fffd3
parent04b2f6ea8ab35136041af2e372e1a639a7d869a3
[RISCV] Use MULHU for more division by constant cases.

D113805 improved handling of i32 divu/remu on RV64. The basic idea
from that can be extended to (mul (and X, C2), C1) where C2 is any
mask constant.

We can replace the and with an SLLI by shifting by the number of
leading zeros in C2 if we also shift C1 left by XLen - lzcnt(C1)
bits. This will give the full product XLen additional trailing zeros,
putting the result in the output of MULHU. If we can't use ANDI,
ZEXT.H, or ZEXT.W, this will avoid materializing C2 in a register.

The downside is it make take 1 additional instruction to create C1.
But since that's not on the critical path, it can hopefully be
interleaved with other operations.

The previous tablegen pattern is replaced by custom isel code.

Reviewed By: asb

Differential Revision: https://reviews.llvm.org/D115310
llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
llvm/lib/Target/RISCV/RISCVInstrInfoM.td
llvm/test/CodeGen/RISCV/div.ll
llvm/test/CodeGen/RISCV/pr51206.ll
llvm/test/CodeGen/RISCV/urem-lkk.ll
llvm/test/CodeGen/RISCV/xaluo.ll