diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp --- a/llvm/lib/Analysis/InstructionSimplify.cpp +++ b/llvm/lib/Analysis/InstructionSimplify.cpp @@ -3432,6 +3432,8 @@ if (Value *V = simplifyICmpOfBools(Pred, LHS, RHS, Q)) return V; + // TODO: Sink/common this with other potentially expensive calls that use + // ValueTracking? See comment below for isKnownNonEqual(). if (Value *V = simplifyICmpWithZero(Pred, LHS, RHS, Q)) return V; @@ -3637,7 +3639,9 @@ } // icmp eq|ne X, Y -> false|true if X != Y - if (ICmpInst::isEquality(Pred) && + // This is potentially expensive, and we have already computedKnownBits for + // compares with 0 above here, so only try this for a non-zero compare. + if (ICmpInst::isEquality(Pred) && !match(RHS, m_Zero()) && isKnownNonEqual(LHS, RHS, Q.DL, Q.AC, Q.CxtI, Q.DT, Q.IIQ.UseInstrInfo)) { return Pred == ICmpInst::ICMP_NE ? getTrue(ITy) : getFalse(ITy); }