[PATCH] D140733: [InstSimplify] fold exact divide to poison if it is known to not divide evenly

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 28 11:27:56 PST 2022


spatel created this revision.
spatel added reviewers: lebedev.ri, liaolucy, 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.

This is related to the discussion in D140665 <https://reviews.llvm.org/D140665>. I was looking over the demanded bits implementation in IR and noticed that we just bail out of a potential fold if a `udiv` is `exact`:
DemandedBits source link <https://github.com/llvm/llvm-project/blob/82be8a1d2b00f6e89096b86f670a8be894c7b9e6/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp#L799>

Also, see tests added with 7f0c11509e8f <https://reviews.llvm.org/rG7f0c11509e8f410f646febd17b52b6a253bbffe5>.

Then, I saw that we could lose a fold to poison if we zap the `exact` with that transform, so this patch tries to catch that as a preliminary step.

Alive2 proofs:
https://alive2.llvm.org/ce/z/c9CMsJ


https://reviews.llvm.org/D140733

Files:
  llvm/lib/Analysis/InstructionSimplify.cpp
  llvm/test/Transforms/InstCombine/udiv-simplify.ll
  llvm/test/Transforms/InstSimplify/div.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D140733.485525.patch
Type: text/x-patch
Size: 3726 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221228/663ff5bc/attachment.bin>


More information about the llvm-commits mailing list