]> granicus.if.org Git - llvm/commit
Merging r294786:
authorTom Stellard <tstellar@redhat.com>
Wed, 26 Apr 2017 20:04:01 +0000 (20:04 +0000)
committerTom Stellard <tstellar@redhat.com>
Wed, 26 Apr 2017 20:04:01 +0000 (20:04 +0000)
commit9d5771aefb4b3d61f64e6fb4a72ff51133a8aece
tree73af08b8601b5184344033d0d56ed939a4d9629a
parenta406bce730683f21bc20c5d3a50d98ddeee97344
Merging r294786:

------------------------------------------------------------------------
r294786 | yaxunl | 2017-02-10 16:46:07 -0500 (Fri, 10 Feb 2017) | 24 lines

Fix invalid addrspacecast due to combining alloca with global var

For function-scope variables with large initialisation list, FE usually
generates a global variable to hold the initializer, then generates
memcpy intrinsic to initialize the alloca. InstCombiner::visitAllocaInst
identifies such allocas which are accessed only by reading and replaces
them with the global variable. This is done by casting the global variable
to the type of the alloca and replacing all references.

However, when the global variable is in a different address space which
is disjoint with addr space 0 (e.g. for IR generated from OpenCL,
global variable cannot be in private addr space i.e. addr space 0), casting
the global variable to addr space 0 results in invalid IR for certain
targets (e.g. amdgpu).

To fix this issue, when the global variable is not in addr space 0,
instead of casting it to addr space 0, this patch chases down the uses
of alloca until reaching the load instructions, then replaces load from
alloca with load from the global variable. If during the chasing
bitcast and GEP are encountered, new bitcast and GEP based on the global
variable are generated and used in the load instructions.

Differential Revision: https://reviews.llvm.org/D27283

------------------------------------------------------------------------

git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_40@301452 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Transforms/InstCombine/InstCombineInternal.h
lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
test/Transforms/InstCombine/memcpy-addrspace.ll [new file with mode: 0644]