[llvm] r316957 - InferAddressSpaces: Fix bug about replacing addrspacecast
Yaxun Liu via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 30 14:19:41 PDT 2017
Author: yaxunl
Date: Mon Oct 30 14:19:41 2017
New Revision: 316957
URL: http://llvm.org/viewvc/llvm-project?rev=316957&view=rev
Log:
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
Modified:
llvm/trunk/lib/Transforms/Scalar/InferAddressSpaces.cpp
llvm/trunk/test/Transforms/InferAddressSpaces/AMDGPU/infer-addrspacecast.ll
Modified: llvm/trunk/lib/Transforms/Scalar/InferAddressSpaces.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/InferAddressSpaces.cpp?rev=316957&r1=316956&r2=316957&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/InferAddressSpaces.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/InferAddressSpaces.cpp Mon Oct 30 14:19:41 2017
@@ -971,6 +971,11 @@ bool InferAddressSpaces::rewriteWithNewA
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;
Modified: llvm/trunk/test/Transforms/InferAddressSpaces/AMDGPU/infer-addrspacecast.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InferAddressSpaces/AMDGPU/infer-addrspacecast.ll?rev=316957&r1=316956&r2=316957&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InferAddressSpaces/AMDGPU/infer-addrspacecast.ll (original)
+++ llvm/trunk/test/Transforms/InferAddressSpaces/AMDGPU/infer-addrspacecast.ll Mon Oct 30 14:19:41 2017
@@ -15,6 +15,19 @@ define void @addrspacecast_gep_addrspace
ret void
}
+; CHECK-LABEL: @addrspacecast_different_pointee_type(
+; CHECK: [[GEP:%.*]] = getelementptr i32, i32 addrspace(3)* %ptr, i64 9
+; CHECK: [[CAST:%.*]] = bitcast i32 addrspace(3)* [[GEP]] to i8 addrspace(3)*
+; CHECK-NEXT: store i8 8, i8 addrspace(3)* [[CAST]], align 8
+; CHECK-NEXT: ret void
+define void @addrspacecast_different_pointee_type(i32 addrspace(3)* %ptr) {
+ %asc0 = addrspacecast i32 addrspace(3)* %ptr to i32 addrspace(4)*
+ %gep0 = getelementptr i32, i32 addrspace(4)* %asc0, i64 9
+ %asc1 = addrspacecast i32 addrspace(4)* %gep0 to i8 addrspace(3)*
+ store i8 8, i8 addrspace(3)* %asc1, align 8
+ ret void
+}
+
; CHECK-LABEL: @addrspacecast_to_memory(
; CHECK: %gep0 = getelementptr i32, i32 addrspace(3)* %ptr, i64 9
; CHECK-NEXT: store volatile i32 addrspace(3)* %gep0, i32 addrspace(3)* addrspace(1)* undef
More information about the llvm-commits
mailing list