[PATCH] D129650: [InstCombine] change conditions for transform of sub to xor

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 13 08:30:10 PDT 2022


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

As discussed in in D128123 <https://reviews.llvm.org/D128123>, converting sub to xor can cause codegen regressions, and it may not be reversible with respect to no-wrap as shown here:
https://alive2.llvm.org/ce/z/CgOlZU

The PhaseOrdering test is based on the example provided in the other review.

Generally, we prefer bitwise-logic to math ops in IR even if that means dropping no-wrap flags -- because that allows better bit-tracking. But as noted, we need to improve the backend before easing the conditions here to avoid sub-optimal codegen.

This makes the IR fold the same as SDAG other than avoiding the transform in the presence of nsw/nuw. We probably want to update SDAG too -- either with a similar check as here or with a TLI hook to restrict the fold for targets that prefer sub-from-constant form.


https://reviews.llvm.org/D129650

Files:
  llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
  llvm/test/Transforms/InstCombine/sub-xor.ll
  llvm/test/Transforms/PhaseOrdering/SystemZ/sub-xor.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D129650.444268.patch
Type: text/x-patch
Size: 15608 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220713/7f7f835e/attachment.bin>


More information about the llvm-commits mailing list