Skip to content

Commit 5ed13a6

Browse files
committed
Merging r296163:
------------------------------------------------------------------------ r296163 | yaxunl | 2017-02-24 15:27:25 -0500 (Fri, 24 Feb 2017) | 9 lines [InstCombine] Fix bug in pointer replacement This optimisation was crashing when there was a chain of more than one bitcast instruction to replace, as a result of the changes in D27283. Patch by James Price. Differential Revision: https://reviews.llvm.org/D30347 ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_40@303166 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 12ceebf commit 5ed13a6

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ void PointerReplacer::replace(Instruction *I) {
306306
auto *NewI = new BitCastInst(V, NewT);
307307
IC.InsertNewInstWith(NewI, *BC);
308308
NewI->takeName(BC);
309-
WorkMap[GEP] = NewI;
309+
WorkMap[BC] = NewI;
310310
} else {
311311
llvm_unreachable("should never reach here");
312312
}

test/Transforms/InstCombine/memcpy-addrspace.ll

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,26 @@ entry:
2121
ret void
2222
}
2323

24+
; CHECK-LABEL: test_load_bitcast_chain
25+
; CHECK: %[[GEP:.*]] = getelementptr [8 x i32], [8 x i32] addrspace(2)* @test.data, i64 0, i64 %x
26+
; CHECK: %{{.*}} = load i32, i32 addrspace(2)* %[[GEP]]
27+
; CHECK-NOT: alloca
28+
; CHECK-NOT: call void @llvm.memcpy.p0i8.p2i8.i64
29+
; CHECK-NOT: addrspacecast
30+
; CHECK-NOT: load i32, i32*
31+
define void @test_load_bitcast_chain(i32 addrspace(1)* %out, i64 %x) {
32+
entry:
33+
%data = alloca [8 x i32], align 4
34+
%0 = bitcast [8 x i32]* %data to i8*
35+
call void @llvm.memcpy.p0i8.p2i8.i64(i8* %0, i8 addrspace(2)* bitcast ([8 x i32] addrspace(2)* @test.data to i8 addrspace(2)*), i64 32, i32 4, i1 false)
36+
%1 = bitcast i8* %0 to i32*
37+
%arrayidx = getelementptr inbounds i32, i32* %1, i64 %x
38+
%2 = load i32, i32* %arrayidx, align 4
39+
%arrayidx1 = getelementptr inbounds i32, i32 addrspace(1)* %out, i64 %x
40+
store i32 %2, i32 addrspace(1)* %arrayidx1, align 4
41+
ret void
42+
}
43+
2444
; CHECK-LABEL: test_call
2545
; CHECK: alloca
2646
; CHECK: call void @llvm.memcpy.p0i8.p2i8.i64

0 commit comments

Comments
 (0)