[PATCH] D136788: [InstCombine] improve demanded bits for Sub operand 0

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 26 13:49:48 PDT 2022


spatel created this revision.
spatel added reviewers: foad, bcl5980, craig.topper.
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 copying the code that was added for `add` with D130075 <https://reviews.llvm.org/D130075>. (That patch removed a fallthrough in the cases, but we can probably still share at least some code again as a follow-up cleanup, but I didn't want to risk it here.)

The reasoning is similar to the carry propagation for `add`: if we don't demand low bits of the subtraction and the subtrahend (aka RHS or operand 1) is known zero in those low bits, then there can't be any borrowing required from the higher bits of operand 0, so they don't matter.

Also, the no-wrap flags can be propagated (and I think that should be true for `add` too).

Here's an attempt to prove that in Alive2:
https://alive2.llvm.org/ce/z/xqh7Pa
(can add nsw or nuw from `src` and `tgt`, and it should still pass)


https://reviews.llvm.org/D136788

Files:
  llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
  llvm/test/Transforms/InstCombine/sub.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D136788.470917.patch
Type: text/x-patch
Size: 4780 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221026/fb63e4c8/attachment.bin>


More information about the llvm-commits mailing list