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

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 20 03:04:48 PDT 2024


================
@@ -7190,6 +7190,29 @@ Instruction *InstCombinerImpl::visitICmpInst(ICmpInst &I) {
       }
     }
 
+    // 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
+    const APInt *C;
+    if (match(Op0, m_c_Xor(m_Specific(Op1), m_APInt(C))) && C->isNegative()) {
+      CmpInst::Predicate NewPred;
+      Pred = ICmpInst::getStrictPredicate(Pred);
+      switch (Pred) {
+      default:
+        llvm_unreachable("not a valid predicate");
----------------
nikic wrote:

Is this because InstSimplify is guaranteed to fold the eq/ne case?

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


More information about the llvm-commits mailing list