[PATCH] D142803: [AggressiveInstCombine] Implement a general way to simplify complex logical operations.

chenglin.bi via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Jan 28 02:15:47 PST 2023


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

This patch involves boolean ring to simplify logical operations. We can treat `&` as ring multiplication and `^` as ring addition.
So we need to canonicalize all other operations to `*` `+`. Like:

  a & b -> a * b
  a ^ b -> a + b
  ~a -> a + 1
  a | b -> a * b + a + b
  c ? a : b -> c * a + (c + 1) * b

In the code, we use a mask set to represent an expression. Every value that is not comes from logical operations could be a bit in the mask.
The mask itself is a multiplication chain. The mask set is an addiction chain.
We can calculate two expressions based on boolean algebras.

For now, the initial patch only enabled on and/or/xor, and only optimized for branch condition. 
Later we can enhance the code step by step.

Reference: https://en.wikipedia.org/wiki/Boolean_ring


https://reviews.llvm.org/D142803

Files:
  llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp
  llvm/test/Transforms/AggressiveInstCombine/complex-logic-ops.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D142803.492988.patch
Type: text/x-patch
Size: 8468 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230128/5d5f6f04/attachment.bin>


More information about the llvm-commits mailing list