[llvm] [InstCombine] simplify `icmp pred x, ~x` (PR #73990)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Sun Oct 6 08:32:21 PDT 2024


================
@@ -4605,6 +4605,27 @@ static Instruction *foldICmpXorXX(ICmpInst &I, const SimplifyQuery &Q,
       isKnownNonZero(A, Q.DL, /*Depth=*/0, Q.AC, Q.CxtI, Q.DT))
     return new ICmpInst(PredOut, Op0, Op1);
 
+  // These transform works when C is negative.
+  // X s< X^C, X s<= X^C, X u> X^C, X u>= X^C  --> X s< 0
+  // X s> X^C, X s>= X^C, X u< X^C, X u<= X^C  --> X s>= 0
+  if (match(A, m_Negative())) {
+    CmpInst::Predicate NewPred;
+    switch (ICmpInst::getStrictPredicate(Pred)) {
+    default:
+      llvm_unreachable("not a valid predicate");
----------------
nikic wrote:

```suggestion
      return nullptr;
```
I'd conservatively return nullptr here. I'm not completely certain that we're guaranteed to not see equality predicates at this point.

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


More information about the llvm-commits mailing list