[GlobalsAA] Teach GlobalsAA about nocapture
authorJames Molloy <james.molloy@arm.com>
Fri, 25 Sep 2015 15:39:29 +0000 (15:39 +0000)
committerJames Molloy <james.molloy@arm.com>
Fri, 25 Sep 2015 15:39:29 +0000 (15:39 +0000)
commit2b27648132b6a731c4edfba89747832c6a1bec56
treeb127c4610343f19dae659917fdd6c451c6d9ce84
parent054da58c5398a721d4dab7af63d7de8d7a1e1a1c
[GlobalsAA] Teach GlobalsAA about nocapture

Arguments to function calls marked "nocapture" can be marked as
non-escaping. However, nocapture is defined in terms of the lifetime
of the callee, and if the callee can directly or indirectly recurse to
the caller, the semantics of nocapture are invalid.

Therefore, we eagerly discover which SCC each function belongs to,
and later can check if callee and caller of a callsite belong to
the same SCC, in which case there could be recursion.

This means that we can't be so optimistic in
getModRefInfo(ImmutableCallsite) - previously we assumed all call
arguments never aliased with an escaping global. Now we need to check,
because a global could now be passed as an argument but still not
escape.

This also solves a related conformance problem: MemCpyOptimizer can
turn non-escaping stores of globals into calls to intrinsics like
llvm.memcpy/llvm/memset. This confuses GlobalsAA, which knows the
global can't escape and so returns NoModRef when queried, when
obviously a memcpy/memset call does indeed reference and modify its
arguments.

This fixes PR24800, PR24801, and PR24802.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@248576 91177308-0d34-0410-b5e6-96231b3b80d8
include/llvm/Analysis/GlobalsModRef.h
lib/Analysis/GlobalsModRef.cpp
test/Analysis/GlobalsModRef/memset-escape.ll [new file with mode: 0644]
test/Analysis/GlobalsModRef/nocapture.ll [new file with mode: 0644]