From f60fdf79894ebf2085efb5affdf720972d0b2e7d Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Wed, 29 Aug 2018 17:09:21 +0000 Subject: [PATCH] [InstCombine] Replace two calls to getNumUses() with !hasNUsesOrMore We were calling getNumUses to check for 1 or 2 uses. But getNumUses is linear in the number of uses. We can instead use !hasNUsesOrMore(3) which will stop the linear scan as soon as it determines there are at least 3 uses even if there are more. llvm-svn: 340939 --- lib/Transforms/InstCombine/InstCombineSelect.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Transforms/InstCombine/InstCombineSelect.cpp b/lib/Transforms/InstCombine/InstCombineSelect.cpp index 0313cc9bb06..3b79ea55a21 100644 --- a/lib/Transforms/InstCombine/InstCombineSelect.cpp +++ b/lib/Transforms/InstCombine/InstCombineSelect.cpp @@ -1822,7 +1822,7 @@ Instruction *InstCombiner::visitSelectInst(SelectInst &SI) { // MIN(~a, ~b) -> ~MAX(a, b) Value *A, *B; if (match(LHS, m_Not(m_Value(A))) && match(RHS, m_Not(m_Value(B))) && - (LHS->getNumUses() <= 2 || RHS->getNumUses() <= 2)) { + (!LHS->hasNUsesOrMore(3) || !RHS->hasNUsesOrMore(3))) { CmpInst::Predicate InvertedPred = getInverseMinMaxPred(SPF); Value *InvertedCmp = Builder.CreateICmp(InvertedPred, A, B); Value *NewSel = Builder.CreateSelect(InvertedCmp, A, B);