@@ -2652,43 +2652,42 @@ static bool isKnownNonNullFromDominatingCondition(const Value *V,
26522652 return false ;
26532653
26542654 unsigned NumUsesExplored = 0 ;
2655- for (const auto * U : V->users ()) {
2655+ for (auto & U : V->uses ()) {
26562656 // Avoid massive lists
26572657 if (NumUsesExplored >= DomConditionsMaxUses)
26582658 break ;
26592659 NumUsesExplored++;
26602660
2661+ const Instruction *UI = cast<Instruction>(U.getUser ());
26612662 // If the value is used as an argument to a call or invoke, then argument
26622663 // attributes may provide an answer about null-ness.
26632664 if (V->getType ()->isPointerTy ()) {
2664- if (const auto *CB = dyn_cast<CallBase>(U))
2665- if (auto *CalledFunc = CB->getCalledFunction ())
2666- for (const Argument &Arg : CalledFunc->args ())
2667- if (CB->getArgOperand (Arg.getArgNo ()) == V &&
2668- CB->paramHasNonNullAttr (Arg.getArgNo (),
2669- /* AllowUndefOrPoison=*/ false ) &&
2670- DT->dominates (CB, CtxI))
2671- return true ;
2665+ if (const auto *CB = dyn_cast<CallBase>(UI)) {
2666+ if (CB->isArgOperand (&U) &&
2667+ CB->paramHasNonNullAttr (CB->getArgOperandNo (&U),
2668+ /* AllowUndefOrPoison=*/ false ) &&
2669+ DT->dominates (CB, CtxI))
2670+ return true ;
2671+ }
26722672 }
26732673
26742674 // If the value is used as a load/store, then the pointer must be non null.
2675- if (V == getLoadStorePointerOperand (U)) {
2676- const Instruction *I = cast<Instruction>(U);
2677- if (!NullPointerIsDefined (I->getFunction (),
2675+ if (V == getLoadStorePointerOperand (UI)) {
2676+ if (!NullPointerIsDefined (UI->getFunction (),
26782677 V->getType ()->getPointerAddressSpace ()) &&
2679- DT->dominates (I , CtxI))
2678+ DT->dominates (UI , CtxI))
26802679 return true ;
26812680 }
26822681
2683- if ((match (U , m_IDiv (m_Value (), m_Specific (V))) ||
2684- match (U , m_IRem (m_Value (), m_Specific (V)))) &&
2685- isValidAssumeForContext (cast<Instruction>(U) , CtxI, DT))
2682+ if ((match (UI , m_IDiv (m_Value (), m_Specific (V))) ||
2683+ match (UI , m_IRem (m_Value (), m_Specific (V)))) &&
2684+ isValidAssumeForContext (UI , CtxI, DT))
26862685 return true ;
26872686
26882687 // Consider only compare instructions uniquely controlling a branch
26892688 Value *RHS;
26902689 CmpPredicate Pred;
2691- if (!match (U , m_c_ICmp (Pred, m_Specific (V), m_Value (RHS))))
2690+ if (!match (UI , m_c_ICmp (Pred, m_Specific (V), m_Value (RHS))))
26922691 continue ;
26932692
26942693 bool NonNullIfTrue;
@@ -2701,7 +2700,7 @@ static bool isKnownNonNullFromDominatingCondition(const Value *V,
27012700
27022701 SmallVector<const User *, 4 > WorkList;
27032702 SmallPtrSet<const User *, 4 > Visited;
2704- for (const auto *CmpU : U ->users ()) {
2703+ for (const auto *CmpU : UI ->users ()) {
27052704 assert (WorkList.empty () && " Should be!" );
27062705 if (Visited.insert (CmpU).second )
27072706 WorkList.push_back (CmpU);
0 commit comments