[PATCH] D129622: [InstCombine] add fold (X > C - 1) ^ (X < C + 1) --> X != C

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 18 11:58:21 PDT 2022


spatel added inline comments.


================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp:3234
+         PredR == CmpInst::ICMP_SGT && match(RHS1, m_APInt(C1))))
+      if (*C1 + 2 == *C2 && (C1->isNegative() || C2->isNonNegative()))
+        return Builder.CreateICmpNE(LHS0,
----------------
There is no check that LHS0 is the same as RHS0. Please correct that and add a test similar to this:


```
define i1 @xor_of_icmps_to_ne_no_common_operand(i64 %a, i64 %z) {
  %b = icmp sgt i64 %z, 4
  %c = icmp slt i64 %a, 6
  %xor = xor i1 %b, %c
  ret i1 %xor
}
```


================
Comment at: llvm/test/Transforms/InstCombine/set.ll:257
+
+define i1 @xor_of_icmps_neg_non-neg_to_eq(i8 %x) {
+; CHECK-LABEL: @xor_of_icmps_neg_non-neg_to_eq(
----------------
Similar to my comment from D129726:
You may pre-commit tests in "NFC" patches. You can push that kind of patch without pre-commit review on Phabricator. It would be good to test at least 2 more code patterns:
1. Use a vector type with "splat" constants.
2. Add extra uses of the icmps.



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129622



More information about the llvm-commits mailing list