[llvm] [InstCombine] simplify `icmp pred x, ~x` (PR #73990)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 22 08:45:57 PDT 2024
================
@@ -4540,14 +4540,45 @@ static Instruction *foldICmpXorXX(ICmpInst &I, const SimplifyQuery &Q,
if (!match(Op0, m_c_Xor(m_Specific(Op1), m_Value(A))))
return nullptr;
+ CmpInst::Predicate StrictPred = ICmpInst::getStrictPredicate(Pred);
+ // Transform
+ // X s< ~X, X s<= ~X, X u> ~X, X u>= ~X
+ // --> X s< 0
+ // X s> ~X, X s>= ~X, X u< ~X, X u<= ~X
+ // --> X s> -1
+ // X == ~X --> false
+ // X != ~X --> true
+ if (match(Op0, m_Not(m_Specific(Op1)))) {
+ CmpInst::Predicate NewPred;
+ switch (StrictPred) {
+ case ICmpInst::ICMP_EQ:
+ return IC.replaceInstUsesWith(I, ConstantInt::getFalse(I.getType()));
+ case ICmpInst::ICMP_NE:
+ return IC.replaceInstUsesWith(I, ConstantInt::getTrue(I.getType()));
+ case ICmpInst::ICMP_SLT:
+ case ICmpInst::ICMP_UGT:
+ NewPred = ICmpInst::ICMP_SGT;
----------------
goldsteinn wrote:
Fair enough.
https://github.com/llvm/llvm-project/pull/73990
More information about the llvm-commits
mailing list