[PATCH] D60056: Hoist/sink malloc/free's in LICM.

Nick Lewycky via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Mar 31 22:21:04 PDT 2019


nicholas created this revision.
Herald added subscribers: llvm-commits, asbirlea, jfb, hiraditya, mgorny.
Herald added a project: LLVM.

Hoist/sink malloc/free's in LICM.

Adds a new method on Instruction that answers the query of whether the given Instruction might allocate or free memory. Unlike builtin info which answers whether they are an allocation/deallocation call, this method indicates whether allocation behaviour is possible.

Adds a new analysis on loops called LoopAllocationInfo. This is tightly tied to the internal implementation of LICM, but is exposed in a public API because the relevant parts of LICM's externals, hoistRegion and sinkRegion, are also a public API.

One potentially surprising aspect of this optimization is that it is correct even if the loop exits in the middle, after the malloc and before the free. As long as there is only one live malloc at a time, there is no visible difference in behaviour. It is sufficient to show that we've found free() calls which cover all possible access to the loop backedge (the other option is that the code had a pre-existing double-free, which is undefined behaviour). The loop may thus exit with the malloc either allocated or freed, and we track which loop exits blocks should have frees added to them and which ones should not.

Clean up LICM. Remove dead parameter "FreeInLoop", fix some typos and trailing whitespace.

Add an optional list of blocks to avoid when looking for a path in isPotentiallyReachable. The leads to some ambiguous overloads, so update three callers.

Fix a bug in isPotentiallyReachable where it assumed that all blocks are reachable from entry.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D60056

Files:
  llvm/include/llvm/Analysis/CFG.h
  llvm/include/llvm/Analysis/LoopAllocationInfo.h
  llvm/include/llvm/IR/Instruction.h
  llvm/include/llvm/Transforms/Utils/LoopUtils.h
  llvm/lib/Analysis/BasicAliasAnalysis.cpp
  llvm/lib/Analysis/CFG.cpp
  llvm/lib/Analysis/CMakeLists.txt
  llvm/lib/Analysis/CaptureTracking.cpp
  llvm/lib/Analysis/LoopAllocationInfo.cpp
  llvm/lib/CodeGen/DwarfEHPrepare.cpp
  llvm/lib/IR/Instruction.cpp
  llvm/lib/Transforms/Scalar/LICM.cpp
  llvm/test/Transforms/LICM/allocs.ll
  llvm/unittests/Analysis/CFGTest.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D60056.193042.patch
Type: text/x-patch
Size: 51266 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190401/cfbfed99/attachment.bin>


More information about the llvm-commits mailing list