[PATCH] D94180: [SimplifyCFG] Optimize CFG when null is passed to a function with nonnull argument

Dávid Bolvanský via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 15 12:41:40 PST 2021


xbolva00 added inline comments.


================
Comment at: llvm/lib/Transforms/Utils/SimplifyCFG.cpp:6572
       if (GEP->getPointerOperand() == I)
-        return passingValueIsAlwaysUndefined(V, GEP);
+        return passingValueIsAlwaysUndefined(V, GEP, true);
+
----------------
nikic wrote:
> jdoerfert wrote:
> > `/* IsUndef... */ true`
> Could be more precise using something like:
> ```
> if (!GEP->isInBounds() || !GEP->hasAllZeroIndices())
>   IsUndefFromGEP = true;
> return passingValueIsAlwaysUndefined(V, GEP, IsUndefFromGEP);
> ```
> Though that makes the naming even more awkward. @jdoerfert's suggestion of `PtrValueMayBeModified` would make more sense.
Thanks, applied in new patch.


================
Comment at: llvm/lib/Transforms/Utils/SimplifyCFG.cpp:6591-6592
+    if (auto *CB = dyn_cast<CallBase>(Use)) {
+      if (NullPointerIsDefined(CB->getFunction()))
+        return false;
+      // A call to null is undefined.
----------------
lebedev.ri wrote:
> jdoerfert wrote:
> > xbolva00 wrote:
> > > lebedev.ri wrote:
> > > > And what if `C` is actually `undef`?
> > > So in this case, we require noundef attribute only (?) @aqjune
> > > 
> > > I will add a testcase.
> > `noundef undef` -> instant UB
> Yep, and will we watch it if the `null` ptr is defined?
Ops, fixed.

Added test for this case.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D94180/new/

https://reviews.llvm.org/D94180



More information about the llvm-commits mailing list