llvm.org GIT mirror llvm / 0bab0f2
Merging r332302: ------------------------------------------------------------------------ r332302 | kfischer | 2018-05-14 15:05:01 -0700 (Mon, 14 May 2018) | 15 lines [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/branches/release_60@333477 91177308-0d34-0410-b5e6-96231b3b80d8 Tom Stellard 1 year, 3 months ago
2 changed file(s) with 22 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
19461946 // addrspacecast between types is canonicalized as a bitcast, then an
19471947 // addrspacecast. To take advantage of the below bitcast + struct GEP, look
19481948 // through the addrspacecast.
1949 Value *ASCStrippedPtrOp = PtrOp;
19491950 if (AddrSpaceCastInst *ASC = dyn_cast(PtrOp)) {
19501951 // X = bitcast A addrspace(1)* to B addrspace(1)*
19511952 // Y = addrspacecast A addrspace(1)* to B addrspace(2)*
19521953 // Z = gep Y, <...constant indices...>
19531954 // Into an addrspacecasted GEP of the struct.
19541955 if (BitCastInst *BC = dyn_cast(ASC->getOperand(0)))
1955 PtrOp = BC;
1956 ASCStrippedPtrOp = BC;
19561957 }
19571958
19581959 /// See if we can simplify:
19601961 /// Y = gep X, <...constant indices...>
19611962 /// into a gep of the original struct. This is important for SROA and alias
19621963 /// analysis of unions. If "A" is also a bitcast, wait for A/X to be merged.
1963 if (BitCastInst *BCI = dyn_cast(PtrOp)) {
1964 if (BitCastInst *BCI = dyn_cast(ASCStrippedPtrOp)) {
19641965 Value *Operand = BCI->getOperand(0);
19651966 PointerType *OpType = cast(Operand->getType());
19661967 unsigned OffsetBits = DL.getPointerTypeSizeInBits(GEP.getType());
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 }