[PATCH] D142803: [ComplexLogicCombine 1/?] Implement a general way to simplify complex logical operations.

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 15 11:41:42 PST 2023


spatel added a comment.

In D142803#4128062 <https://reviews.llvm.org/D142803#4128062>, @bcl5980 wrote:

> In D142803#4124135 <https://reviews.llvm.org/D142803#4124135>, @spatel wrote:
>
>> I'm still trying to understand how this works, so I only looked at the high-level comments to start.
>>
>> Is it possible to convert existing logic tests in InstCombien/InstSimplify to use branches, then run those tests with "opt -aggressive-instcombine" and verify that the results are correct?
>
> @spatel I try to run all tests of InstCombine and some of current tests can be improved. The detail diff is D144071 <https://reviews.llvm.org/D144071>.

Nice! The results look promising. I'm still trying to understand how this works by reading the code (rather than reading the wikipedia reference page). 
I'm confused, so it's still just a couple of high-level questions/comments.



================
Comment at: llvm/include/llvm/Analysis/LogicalExpr.h:16
+// (0b1111 + 0b1001 + 0b0010 + 0b1101) * (0b0001 + 0b0101)
+// -->
+// (0b1111 + 0b1001 + 0b0010 + 0b1101) * 0b0001+ (0b1111 + 0b1001 + 0b0010 +
----------------
I'm still confused by the notation. Each "-->" step needs a comment to describe exactly what is happening. If we are not showing some unique math/logic property with each of the terms in the equation/set, then it would be easier to follow the logic with a smaller example.

In this step, we are splitting the RHS masks to operate over the LHS? But are those "+" and "*" symbols representing real math operations or are they bitwise logical operations?


================
Comment at: llvm/include/llvm/Analysis/LogicalExpr.h:20
+// -->
+// (0b1111 | 0b0001) + (0b1001 | 0b0001) + (0b0010 | 0b0001) + (0b1101 | 0b0001)
+// + (0b1111 | 0b0101) + (0b1001 | 0b0101) + (0b0010 | 0b0101) + (0b1101 |
----------------
Here we have distributed the RHS mask values over the LHS mask values? Why did "*" become "|"?


================
Comment at: llvm/include/llvm/Analysis/LogicalExpr.h:24
+// -->
+// 0b1111 + 0b1001 + 0b0010 + 0b1101 + 0b1111 + 0b1101 + 0b0111 + 0b1101
+// -->
----------------
I don't know what operation was done there. It's not logical-or or multiplication?


================
Comment at: llvm/test/Transforms/AggressiveInstCombine/complex-logic.ll:4
+
+define i1 @test1(i1 %a, i1 %b, i1 %c, i1 %d)  {
+; CHECK-LABEL: @test1(
----------------
We're going to need more tests than this. Name each test to suggest what it demonstrates (or add test comments, so that is clear).
 
We should build up to the complex examples. Start with single value logic to prove that works:

```
define i32 @x_and_not_x(i32 %x) {
  %notx = xor i32 %x, -1
  %r = and i32 %x, %notx
  ret i32 %r
}

```
...and more like that. Next, show some 2 value tests. Then, show 3 values and finally 4 values.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142803/new/

https://reviews.llvm.org/D142803



More information about the llvm-commits mailing list