[PATCH] D135970: [InstCombine] try to determine "exact" for sdiv

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 14 10:00:48 PDT 2022


spatel created this revision.
spatel added reviewers: craig.topper, nikic.
Herald added subscribers: StephenFan, hiraditya, mcrosier.
Herald added a project: All.
spatel requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

If the divisor is a power-of-2 or negative-power-of-2 and the dividend is known to have >= trailing zeros than the divisor, the division is exact:
https://alive2.llvm.org/ce/z/UGBksM (general proof)
https://alive2.llvm.org/ce/z/D4yPS- (examples based on regression tests)

This isn't the most direct optimization (we could create ashr in these examples instead of relying on existing folds for exact divides), but it's possible that there's a more general constraint than just a pow2 divisor, so this might be extended in the future.

This should solve issue #58348 <https://github.com/llvm/llvm-project/issues/58348>.


https://reviews.llvm.org/D135970

Files:
  llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
  llvm/test/Transforms/InstCombine/sdiv-exact-by-negative-power-of-two.ll
  llvm/test/Transforms/InstCombine/sdiv-exact-by-power-of-two.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D135970.467811.patch
Type: text/x-patch
Size: 5116 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221014/2a00ef63/attachment.bin>


More information about the llvm-commits mailing list