[PATCH] D94180: [SimplifyCFG] Optimize CFG when null is passed to a function with nonnull argument
Johannes Doerfert via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 15 10:19:32 PST 2021
jdoerfert accepted this revision.
jdoerfert added a comment.
This revision is now accepted and ready to land.
Generally LGTM, assuming you are fine with my comments. If you want to continue the discussion, we can as well.
================
Comment at: llvm/lib/Transforms/Utils/SimplifyCFG.cpp:6548
/// Check if passing a value to an instruction will cause undefined behavior.
-static bool passingValueIsAlwaysUndefined(Value *V, Instruction *I) {
+static bool passingValueIsAlwaysUndefined(Value *V, Instruction *I, bool isUndefinedFromGEP) {
Constant *C = dyn_cast<Constant>(V);
----------------
Nit: style `IsUndefFrom...`
I would call it differently though. I tried to understand it from the name and I couldn't. Looking at the code longer, what it basically encodes is `PtrValueMayBeModified`. So if your `C` is `null` or `undef` and not modified, it will reach the call as `null` or `undef`. If it is (potentially) modified it might reach as something other than `null`.
================
Comment at: llvm/lib/Transforms/Utils/SimplifyCFG.cpp:6572
if (GEP->getPointerOperand() == I)
- return passingValueIsAlwaysUndefined(V, GEP);
+ return passingValueIsAlwaysUndefined(V, GEP, true);
+
----------------
`/* IsUndef... */ true`
================
Comment at: llvm/lib/Transforms/Utils/SimplifyCFG.cpp:6599
+
+ if (C->isNullValue()) {
+ for (const llvm::Use &Arg : CB->args())
----------------
================
Comment at: llvm/test/Transforms/SimplifyCFG/UnreachableEliminate.ll:209
+declare i8* @bar(i8* nonnull %p)
+declare i8* @baz(i8* noundef %p)
+
----------------
rename to `nonnull_noundef_arg`, `nonnull_arg`, etc. or something similar descriptive.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D94180/new/
https://reviews.llvm.org/D94180
More information about the llvm-commits
mailing list