summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp
diff options
context:
space:
mode:
authorYaxun Liu <Yaxun.Liu@amd.com>2017-10-30 21:19:41 +0000
committerYaxun Liu <Yaxun.Liu@amd.com>2017-10-30 21:19:41 +0000
commitd23f23d81cbb6730e745a996148adea237a77f84 (patch)
tree41c5cda7a52f175f35f3f4e1c59242d8f448c717 /llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp
parent5a166048f0ba7c73762b1abb144cf20cfe7a69d9 (diff)
downloadbcm5719-llvm-d23f23d81cbb6730e745a996148adea237a77f84.tar.gz
bcm5719-llvm-d23f23d81cbb6730e745a996148adea237a77f84.zip
InferAddressSpaces: Fix bug about replacing addrspacecast
InferAddressSpaces assumes the pointee type of addrspacecast is the same as the operand, which is not always true and causes invalid IR. This bug cause build failure in HCC. This patch fixes that. Differential Revision: https://reviews.llvm.org/D39432 llvm-svn: 316957
Diffstat (limited to 'llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp')
-rw-r--r--llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp5
1 files changed, 5 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp b/llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp
index fba80abf650..7d66c0f7382 100644
--- a/llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp
+++ b/llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp
@@ -971,6 +971,11 @@ bool InferAddressSpaces::rewriteWithNewAddressSpaces(
if (AddrSpaceCastInst *ASC = dyn_cast<AddrSpaceCastInst>(CurUser)) {
unsigned NewAS = NewV->getType()->getPointerAddressSpace();
if (ASC->getDestAddressSpace() == NewAS) {
+ if (ASC->getType()->getPointerElementType() !=
+ NewV->getType()->getPointerElementType()) {
+ NewV = CastInst::Create(Instruction::BitCast, NewV,
+ ASC->getType(), "", ASC);
+ }
ASC->replaceAllUsesWith(NewV);
DeadInstructions.push_back(ASC);
continue;
OpenPOWER on IntegriCloud