[all-commits] [llvm/llvm-project] 97dcbe: [LogicCombine 1/?] Implement a general way to simp...

chenglin.bi via All-commits all-commits at lists.llvm.org
Thu Mar 2 04:46:30 PST 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 97dcbea63e11d566cff0cd3a758cf1114cf1f633
      https://github.com/llvm/llvm-project/commit/97dcbea63e11d566cff0cd3a758cf1114cf1f633
  Author: chenglin.bi <chenglin.bi at linaro.org>
  Date:   2023-03-02 (Thu, 02 Mar 2023)

  Changed paths:
    A llvm/include/llvm/Analysis/LogicCombine.h
    A llvm/include/llvm/Analysis/LogicalExpr.h
    M llvm/lib/Analysis/CMakeLists.txt
    A llvm/lib/Analysis/LogicCombine.cpp
    M llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp
    M llvm/test/Transforms/AggressiveInstCombine/logic-combine.ll

  Log Message:
  -----------
  [LogicCombine 1/?] Implement a general way to simplify logical operations.

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,  Later we can enhance the code step by step.

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

Reviewed By: spatel

Differential Revision: https://reviews.llvm.org/D142803




More information about the All-commits mailing list