[PATCH] D114462: [InstSimplify] fold xor logic of 2 variables

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 23 11:03:44 PST 2021


spatel created this revision.
spatel added reviewers: rampitec, foad, lebedev.ri, MehrHeidar.
Herald added subscribers: hiraditya, mcrosier.
spatel requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

(a & b) ^ (~a | b) --> ~a

I was looking for a shortcut to reduce some of the complex logic folds that are currently up for review (D113216 <https://reviews.llvm.org/D113216> and others in that stack), and I found this missing from instcombine/instsimplify.

There is a trade-off in putting it into instsimplify: because we can't create new values here, we need a strict 'not' op (no undef elements). Otherwise, the fold is not valid:
https://alive2.llvm.org/ce/z/k_AGGj

If this was in instcombine instead, we could create the proper 'not'. But having the fold here benefits other passes like GVN that use instsimplify as an analysis. If I'm seeing it correctly, this is enough to catch the cases in D113216 <https://reviews.llvm.org/D113216> at -O2 without needing to add more pattern matching to instcombine.


https://reviews.llvm.org/D114462

Files:
  llvm/lib/Analysis/InstructionSimplify.cpp
  llvm/test/Transforms/InstSimplify/xor.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D114462.389258.patch
Type: text/x-patch
Size: 6318 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211123/370a8ed3/attachment.bin>


More information about the llvm-commits mailing list