[PATCH] D51505: [WIP][IPSCCP] Use PredInfo to propagate nonnull and hook it up to IPSCCP.

Florian Hahn via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 30 13:47:25 PDT 2018


fhahn created this revision.

This is a POC patch to optimize code like below

  int l = strlen(s); // s has nonnull attribute at call site.
  if (!s) <-- remove this condition
      return -1;
  return len;

The basic idea is to treat calls with !nonnull arguments like if we had something like `assume arg != null` at the call site.

This patch hacks up PredicateInfo to treat nonnull arguments at call
sites similar to assumes, it inserts a ssa_copy for the argument and
replaces all uses of the argument dominated by the call with the copy.
The copy has a predicate info attached stating that the copy is non
null.

The second part of the patch extends IPSCCP to use that information and
ValueLattice::getCompare() to simplify EQ comparisons of notconstant
with constant.

The most hacky part are the changes  in PredicateInfo, but they should
be enough to highlight the idea.


https://reviews.llvm.org/D51505

Files:
  include/llvm/Analysis/ValueLattice.h
  include/llvm/Transforms/Utils/PredicateInfo.h
  lib/Transforms/Scalar/SCCP.cpp
  lib/Transforms/Utils/PredicateInfo.cpp
  test/Transforms/SCCP/ipsccp-nonnull.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D51505.163400.patch
Type: text/x-patch
Size: 7759 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180830/6142e68f/attachment.bin>


More information about the llvm-commits mailing list