[PATCH] D27283: Fix invalid addrspacecast due to combining alloca with global var

Yaxun Liu via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 30 14:33:17 PST 2016


yaxunl created this revision.
yaxunl added reviewers: tstellarAMD, arsenm, majnemer.
yaxunl added a subscriber: llvm-commits.
Herald added subscribers: nhaehnle, wdng.

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 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 instructions with 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.

A debug output is also added to amdgpu backend to facilitate debugging such issues.


https://reviews.llvm.org/D27283

Files:
  lib/Target/AMDGPU/SIISelLowering.cpp
  lib/Transforms/InstCombine/InstCombineInternal.h
  lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
  test/Transforms/InstCombine/memcpy-addrspace.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D27283.79811.patch
Type: text/x-patch
Size: 8058 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161130/e399ceb4/attachment.bin>


More information about the llvm-commits mailing list