@@ -2652,40 +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.
2663- if (const auto *CB = dyn_cast<CallBase>(U))
2664- if (auto *CalledFunc = CB->getCalledFunction ())
2665- for (const Argument &Arg : CalledFunc->args ())
2666- if (CB->getArgOperand (Arg.getArgNo ()) == V &&
2667- Arg.hasNonNullAttr (/* AllowUndefOrPoison */ false ) &&
2668- DT->dominates (CB, CtxI))
2669- return true ;
2664+ if (V->getType ()->isPointerTy ()) {
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+ }
2672+ }
26702673
26712674 // If the value is used as a load/store, then the pointer must be non null.
2672- if (V == getLoadStorePointerOperand (U)) {
2673- const Instruction *I = cast<Instruction>(U);
2674- if (!NullPointerIsDefined (I->getFunction (),
2675+ if (V == getLoadStorePointerOperand (UI)) {
2676+ if (!NullPointerIsDefined (UI->getFunction (),
26752677 V->getType ()->getPointerAddressSpace ()) &&
2676- DT->dominates (I , CtxI))
2678+ DT->dominates (UI , CtxI))
26772679 return true ;
26782680 }
26792681
2680- if ((match (U , m_IDiv (m_Value (), m_Specific (V))) ||
2681- match (U , m_IRem (m_Value (), m_Specific (V)))) &&
2682- 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))
26832685 return true ;
26842686
26852687 // Consider only compare instructions uniquely controlling a branch
26862688 Value *RHS;
26872689 CmpPredicate Pred;
2688- 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))))
26892691 continue ;
26902692
26912693 bool NonNullIfTrue;
@@ -2698,7 +2700,7 @@ static bool isKnownNonNullFromDominatingCondition(const Value *V,
26982700
26992701 SmallVector<const User *, 4 > WorkList;
27002702 SmallPtrSet<const User *, 4 > Visited;
2701- for (const auto *CmpU : U ->users ()) {
2703+ for (const auto *CmpU : UI ->users ()) {
27022704 assert (WorkList.empty () && " Should be!" );
27032705 if (Visited.insert (CmpU).second )
27042706 WorkList.push_back (CmpU);
0 commit comments