[LICM] Store promotion when memory is thread local
authorPhilip Reames <listmail@philipreames.com>
Wed, 9 Mar 2016 22:59:30 +0000 (22:59 +0000)
committerPhilip Reames <listmail@philipreames.com>
Wed, 9 Mar 2016 22:59:30 +0000 (22:59 +0000)
commitb54c8e6eea06a6771bf9eb1fb9f2bacad8111911
tree4637d542fa4339e5cb3a85d03591ddf58561dc12
parent1c82b7f64d44d5db2166ed0480554a7f5306c38b
[LICM] Store promotion when memory is thread local

This patch teaches LICM's implementation of store promotion to exploit the fact that the memory location being accessed might be provable thread local. The fact it's thread local weakens the requirements for where we can insert stores since no other thread can observe the write. This allows us perform store promotion even in cases where the store is not guaranteed to execute in the loop.

Two key assumption worth drawing out is that this assumes a) no-capture is strong enough to imply no-escape, and b) standard allocation functions like malloc, calloc, and operator new return values which can be assumed not to have previously escaped.

In future work, it would be nice to generalize this so that it works without directly seeing the allocation site. I believe that the nocapture return attribute should be suitable for this purpose, but haven't investigated carefully. It's also likely that we could support unescaped allocas with similar reasoning, but since SROA and Mem2Reg should destroy those, they're less interesting than they first might seem.

Differential Revision: http://reviews.llvm.org/D16783

llvm-svn: 263072
llvm/include/llvm/Transforms/Utils/LoopUtils.h
llvm/lib/Transforms/Scalar/LICM.cpp
llvm/test/Transforms/LICM/promote-tls.ll [new file with mode: 0644]