[PATCH] D94180: [SimplifyCFG] Optimize CFG when null is passed to a function with nonnull argument.
Nikita Popov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 6 11:28:05 PST 2021
nikic added a reviewer: aqjune.
nikic added a subscriber: aqjune.
nikic added inline comments.
================
Comment at: llvm/lib/Transforms/Utils/SimplifyCFG.cpp:6598
+ // Passing null to a nonnnull argument is undefined.
+ for (const llvm::Use &Arg : CB->args())
+ if (Arg == I &&
----------------
Why `llvm::`?
================
Comment at: llvm/lib/Transforms/Utils/SimplifyCFG.cpp:6600
+ if (Arg == I &&
+ CB->paramHasAttr(CB->getArgOperandNo(&Arg), Attribute::NonNull))
+ return true;
----------------
Two issues:
1. I believe this is subtle incorrect in conjunction with the GEP rule above. Accessing memory at `gep null, x` is always UB, but passing it to a nonnull argument isn't UB as long as x is not zero.
2. I'm not sure what the current state on this is (@aqjune), but I believe the plan is to make passing null to nonnull argument poison rather than UB. This optimization would only be valid using nonnull + noundef.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D94180/new/
https://reviews.llvm.org/D94180
More information about the llvm-commits
mailing list