diff --git a/lib/Analysis/ScalarEvolution.cpp b/lib/Analysis/ScalarEvolution.cpp index 9c6941f0d31..18c136fc0a6 100644 --- a/lib/Analysis/ScalarEvolution.cpp +++ b/lib/Analysis/ScalarEvolution.cpp @@ -2580,6 +2580,24 @@ SCEVHandle ScalarEvolution::createSCEV(Value *V) { return getNotSCEV(getUMaxExpr(getNotSCEV(getSCEV(LHS)), getNotSCEV(getSCEV(RHS)))); break; + case ICmpInst::ICMP_NE: + // n != 0 ? n : 1 -> umax(n, 1) + if (LHS == U->getOperand(1) && + isa(U->getOperand(2)) && + cast(U->getOperand(2))->isOne() && + isa(RHS) && + cast(RHS)->isZero()) + return getUMaxExpr(getSCEV(LHS), getSCEV(U->getOperand(2))); + break; + case ICmpInst::ICMP_EQ: + // n == 0 ? 1 : n -> umax(n, 1) + if (LHS == U->getOperand(2) && + isa(U->getOperand(1)) && + cast(U->getOperand(1))->isOne() && + isa(RHS) && + cast(RHS)->isZero()) + return getUMaxExpr(getSCEV(LHS), getSCEV(U->getOperand(1))); + break; default: break; }