[PATCH] D50058: Fix InstCombine address space assert
Ewan Crawford via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 31 06:09:40 PDT 2018
EwanCrawford created this revision.
EwanCrawford added reviewers: majnemer, spatel.
Workaround bug where the InstCombine pass was asserting on the IR added in lit test, where we have a bitcast instruction after a GEP from an addrspace cast.
The second bitcast in the test was getting combined into `bitcast <16 x i32>* %0 to <16 x i32> addrspace(3)*`, which looks like it should be an addrspace cast instruction instead. Otherwise if control flow is allowed to continue as it is now we create a GEP instruction `<badref> = getelementptr inbounds <16 x i32>, <16 x i32>* %0, i32 0`. However because the type of this instruction doesn't match the address space we hit an assert when replacing the bitcast with that GEP.
void llvm::Value::doRAUW(llvm::Value*, bool): Assertion `New->getType() == getType() && "replaceAllUses of value with new value of different type!"' failed.
Repository:
rL LLVM
https://reviews.llvm.org/D50058
Files:
lib/Transforms/InstCombine/InstCombineCasts.cpp
test/Transforms/InstCombine/gep-addrspace.ll
Index: test/Transforms/InstCombine/gep-addrspace.ll
===================================================================
--- test/Transforms/InstCombine/gep-addrspace.ll
+++ test/Transforms/InstCombine/gep-addrspace.ll
@@ -51,3 +51,21 @@
%.fca.1.insert = insertvalue { i8, i8 } zeroinitializer, i8 %3, 1
ret { i8, i8 } %.fca.1.insert
}
+
+declare spir_func <16 x i32> @my_extern_func()
+
+; check that a bitcast is not generated when we need an addrspace cast
+define void @bitcast_after_gep(<16 x i32>*) {
+entry:
+; CHECK-LABEL: @bitcast_after_gep
+ %1 = bitcast <16 x i32>* %0 to [16 x i32]*
+ %2 = addrspacecast [16 x i32]* %1 to [16 x i32] addrspace(3)*
+ %3 = getelementptr inbounds [16 x i32], [16 x i32] addrspace(3)* %2, i64 0, i64 0
+; CHECK: %1 = addrspacecast <16 x i32>* %0 to <16 x i32> addrspace(3)*
+ %4 = bitcast i32 addrspace(3)* %3 to <16 x i32> addrspace(3)*
+; CHECK: %call = call spir_func <16 x i32> @my_extern_func()
+ %call = call spir_func <16 x i32> @my_extern_func()
+; CHECK: store <16 x i32> %call, <16 x i32> addrspace(3)* %1
+ store <16 x i32> %call, <16 x i32> addrspace(3)* %4
+ ret void
+}
Index: lib/Transforms/InstCombine/InstCombineCasts.cpp
===================================================================
--- lib/Transforms/InstCombine/InstCombineCasts.cpp
+++ lib/Transforms/InstCombine/InstCombineCasts.cpp
@@ -2243,6 +2243,12 @@
Type *DstElTy = DstPTy->getElementType();
Type *SrcElTy = SrcPTy->getElementType();
+ // Casting pointers between the same type, but with different address spaces
+ // is an addrspace cast rather than a bitcast.
+ if ((DstElTy == SrcElTy) &&
+ (DstPTy->getAddressSpace() != SrcPTy->getAddressSpace()))
+ return new AddrSpaceCastInst(Src, DestTy);
+
// If we are casting a alloca to a pointer to a type of the same
// size, rewrite the allocation instruction to allocate the "right" type.
// There is no need to modify malloc calls because it is their bitcast that
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D50058.158209.patch
Type: text/x-patch
Size: 2003 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180731/084ddb80/attachment.bin>
More information about the llvm-commits
mailing list