[llvm] [InstCombine] simplify `icmp pred x, ~x` (PR #73990)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 8 01:52:32 PST 2023
================
@@ -7060,6 +7060,49 @@ Instruction *InstCombinerImpl::visitICmpInst(ICmpInst &I) {
return new ICmpInst(I.getSwappedPredicate(Pred), Builder.CreateXor(X, Y),
Z);
+ // Transform X s< ~X --> X s< 0
+ // X s> ~X --> X s> -1
+ // X s>= ~X --> X s> -1
+ // X s<= ~X --> X s< 0
+ // X u< ~X --> X s> -1
+ // X u> ~X --> X s< 0
+ // X u<= ~X --> X s> -1
+ // X u>= ~X --> X s< 0
+ // X == ~X --> false
+ // X != ~X --> true
+ if (match(&I, m_c_ICmp(Pred, m_Value(X), m_Not(m_Deferred(X))))) {
+ CmpInst::Predicate PredEqRemoved;
+ Constant *Const;
+ APInt C;
+ switch (Pred) {
+ case ICmpInst::ICMP_EQ:
+ return replaceInstUsesWith(I, ConstantInt::getFalse(I.getType()));
+ break;
----------------
nikic wrote:
No need for break after return.
https://github.com/llvm/llvm-project/pull/73990
More information about the llvm-commits
mailing list