llvm.org GIT mirror llvm / abb2646
[InstCombine] fix crash due to ignored addrspacecast Summary: Part of the InstCombine code for simplifying GEPs looks through addrspacecasts. However, this was done by updating a variable also used by the next transformation, for marking GEPs as inbounds. This led to replacing a GEP with a similar instruction in a different addrspace, which caused an assertion failure in RAUW. This caused julia issue https://github.com/JuliaLang/julia/issues/27055 Patch by Jeff Bezanson <jeff@juliacomputing.com> Reviewed By: arsenm Differential Revision: https://reviews.llvm.org/D46722 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@332302 91177308-0d34-0410-b5e6-96231b3b80d8 Keno Fischer 1 year, 5 months ago
2 changed file(s) with 24 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
19361936 // addrspacecast between types is canonicalized as a bitcast, then an
19371937 // addrspacecast. To take advantage of the below bitcast + struct GEP, look
19381938 // through the addrspacecast.
1939 Value *ASCStrippedPtrOp = PtrOp;
19391940 if (auto *ASC = dyn_cast(PtrOp)) {
19401941 // X = bitcast A addrspace(1)* to B addrspace(1)*
19411942 // Y = addrspacecast A addrspace(1)* to B addrspace(2)*
19421943 // Z = gep Y, <...constant indices...>
19431944 // Into an addrspacecasted GEP of the struct.
19441945 if (auto *BC = dyn_cast(ASC->getOperand(0)))
1945 PtrOp = BC;
1946 }
1947
1948 if (auto *BCI = dyn_cast(PtrOp)) {
1946 ASCStrippedPtrOp = BC;
1947 }
1948
1949 if (auto *BCI = dyn_cast(ASCStrippedPtrOp)) {
19491950 Value *SrcOp = BCI->getOperand(0);
19501951 PointerType *SrcType = cast(BCI->getSrcTy());
19511952 Type *SrcEltType = SrcType->getElementType();
3131 ret void
3232 }
3333
34 declare void @escape_alloca(i16*)
35
36 ; check that addrspacecast is not ignored (leading to an assertion failure)
37 ; when trying to mark a GEP as inbounds
38 define { i8, i8 } @inbounds_after_addrspacecast() {
39 top:
40 ; CHECK-LABEL: @inbounds_after_addrspacecast
41 %0 = alloca i16, align 2
42 call void @escape_alloca(i16* %0)
43 %tmpcast = bitcast i16* %0 to [2 x i8]*
44 ; CHECK: addrspacecast [2 x i8]* %tmpcast to [2 x i8] addrspace(11)*
45 %1 = addrspacecast [2 x i8]* %tmpcast to [2 x i8] addrspace(11)*
46 ; CHECK: getelementptr [2 x i8], [2 x i8] addrspace(11)* %1, i64 0, i64 1
47 %2 = getelementptr [2 x i8], [2 x i8] addrspace(11)* %1, i64 0, i64 1
48 ; CHECK: addrspace(11)
49 %3 = load i8, i8 addrspace(11)* %2, align 1
50 %.fca.1.insert = insertvalue { i8, i8 } zeroinitializer, i8 %3, 1
51 ret { i8, i8 } %.fca.1.insert
52 }