This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Use MULHU for more division by constant cases.
ClosedPublic

Authored by craig.topper on Dec 7 2021, 5:22 PM.

Details

Summary

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.

Diff Detail

Event Timeline

craig.topper created this revision.Dec 7 2021, 5:22 PM
craig.topper requested review of this revision.Dec 7 2021, 5:22 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 7 2021, 5:22 PM
Herald added a subscriber: MaskRay. · View Herald Transcript
asb accepted this revision.Dec 9 2021, 5:51 AM
This revision is now accepted and ready to land.Dec 9 2021, 5:51 AM