[llvm] [ValueTracking] Handle nonnull attributes at callsite (PR #124908)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 29 03:41:16 PST 2025
================
@@ -2660,13 +2660,16 @@ static bool isKnownNonNullFromDominatingCondition(const Value *V,
// If the value is used as an argument to a call or invoke, then argument
// attributes may provide an answer about null-ness.
- if (const auto *CB = dyn_cast<CallBase>(U))
- if (auto *CalledFunc = CB->getCalledFunction())
- for (const Argument &Arg : CalledFunc->args())
- if (CB->getArgOperand(Arg.getArgNo()) == V &&
- Arg.hasNonNullAttr(/* AllowUndefOrPoison */ false) &&
- DT->dominates(CB, CtxI))
- return true;
+ if (V->getType()->isPointerTy()) {
+ if (const auto *CB = dyn_cast<CallBase>(U))
+ if (auto *CalledFunc = CB->getCalledFunction())
+ for (const Argument &Arg : CalledFunc->args())
----------------
nikic wrote:
We should not be checking CalledFunc and its arguments at all, working only on CallBase.
Ideally, you would switch the iterator to work on uses() instead of users(), so we can get the argument number directly from the Use.
https://github.com/llvm/llvm-project/pull/124908
More information about the llvm-commits
mailing list