[llvm] [InstCombine] Fold xored one-complemented operand comparisons (PR #69882)

via llvm-commits llvm-commits at lists.llvm.org
Sun Oct 22 15:23:24 PDT 2023


================
@@ -4,6 +4,212 @@
 declare void @llvm.assume(i1)
 declare void @barrier()
 
+; test for (~x ^ y) < ~z
+define i1 @test_xor1(i8 %x, i8 %y, i8 %z) {
+; CHECK-LABEL: @test_xor1(
+; CHECK-NEXT:    [[TMP1:%.*]] = xor i8 [[X:%.*]], [[Y:%.*]]
+; CHECK-NEXT:    [[R:%.*]] = icmp sgt i8 [[TMP1]], [[Z:%.*]]
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %xor = xor i8 %x, -1
+  %xor2 = xor i8 %xor, %y
+  %nz = xor i8 %z, -1
+  %r = icmp slt i8 %xor2, %nz
+  ret i1 %r
+}
----------------
goldsteinn wrote:

This tests currrently has no diff from your patch.
`(xor (not A), B)` is canonicalized to `(not (xor A, B))` if `(not A)` has one use.

To make your tests meaningful you need to add something along the lines of:
```
declare void @use.i8(i8)
...
  call void @use.i8(i8 %xor)
```

at the end.

https://github.com/llvm/llvm-project/pull/69882


More information about the llvm-commits mailing list