[PATCH] D82299: Add a pass to eliminate nullchecks after objects have been dereferenced (WIP)

Florian Hahn via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 22 07:30:14 PDT 2020


fhahn created this revision.
Herald added subscribers: dexonsmith, hiraditya, mgorny.
Herald added a project: LLVM.

This patch adds a new pass that keeps track of dereferenced objects and
eliminates null checks that are dominated by a memory instruction that
dereferences the underlying object.

Currently this works by collecting all object dereferences and null
checks with known underlying objects. Those are then sorted by DomTree DFS
numbers of their containing blocks and the relative order in a basic
block. Then we iterate over the list and keep track of the currently
dereferenced objects. We remove objects once we encounter a block that
is not dominated by the dereference instruction.

Currently this is O(N * log(N)), where N is the number of memory
instructions that dereference a known underlying object plus number of
null checks of known underlying objects. As it is, the compile time
impact is +0.33% geomean for -O3 ThinLTO
(http://llvm-compile-time-tracker.com/compare.php?from=a5bd75aab861df8cea8d1c6b88e764ad4a2c09ea&to=c02c43b0fe6648772d70c3f3de41a9e5e29e0628&stat=instructions)

It is probably possible to improve that if we would directly traverse
the dominator tree.

This currently results in 1924 compare simplifications on
MultiSource/SPEC2000/SPEC2006 with -O3 -flto.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D82299

Files:
  llvm/include/llvm/InitializePasses.h
  llvm/include/llvm/Transforms/Scalar.h
  llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
  llvm/lib/Transforms/Scalar/CMakeLists.txt
  llvm/lib/Transforms/Scalar/DereferenceNullCheckElimination.cpp
  llvm/lib/Transforms/Scalar/Scalar.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D82299.272414.patch
Type: text/x-patch
Size: 10788 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200622/fa353fe1/attachment-0001.bin>


More information about the llvm-commits mailing list