llvm.org GIT mirror llvm / 5a2d99b
Merging r259558: ------------------------------------------------------------------------ r259558 | Matthew.Arsenault | 2016-02-02 12:28:10 -0800 (Tue, 02 Feb 2016) | 4 lines AMDGPU: Handle promoting memmove Also add missing tests for the others. ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_38@271593 91177308-0d34-0410-b5e6-96231b3b80d8 Tom Stellard 3 years ago
2 changed file(s) with 89 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
267267
268268 switch (II->getIntrinsicID()) {
269269 case Intrinsic::memcpy:
270 case Intrinsic::memmove:
270271 case Intrinsic::memset:
271272 case Intrinsic::lifetime_start:
272273 case Intrinsic::lifetime_end:
273274 case Intrinsic::invariant_start:
274275 case Intrinsic::invariant_end:
275276 case Intrinsic::invariant_group_barrier:
277 case Intrinsic::objectsize:
276278 return true;
277279 default:
278280 return false;
449451 Intr->eraseFromParent();
450452 continue;
451453 }
454 case Intrinsic::memmove: {
455 MemMoveInst *MemMove = cast(Intr);
456 Builder.CreateMemMove(MemMove->getRawDest(), MemMove->getRawSource(),
457 MemMove->getLength(), MemMove->getAlignment(),
458 MemMove->isVolatile());
459 Intr->eraseFromParent();
460 continue;
461 }
452462 case Intrinsic::memset: {
453463 MemSetInst *MemSet = cast(Intr);
454464 Builder.CreateMemSet(MemSet->getRawDest(), MemSet->getValue(),
465475 // but the intrinsics need to be changed to accept pointers with any
466476 // address space.
467477 continue;
478 case Intrinsic::objectsize: {
479 Value *Src = Intr->getOperand(0);
480 Type *SrcTy = Src->getType()->getPointerElementType();
481 Function *ObjectSize = Intrinsic::getDeclaration(Mod,
482 Intrinsic::objectsize,
483 { Intr->getType(), PointerType::get(SrcTy, AMDGPUAS::LOCAL_ADDRESS) }
484 );
485
486 CallInst *NewCall
487 = Builder.CreateCall(ObjectSize, { Src, Intr->getOperand(1) });
488 Intr->replaceAllUsesWith(NewCall);
489 Intr->eraseFromParent();
490 continue;
491 }
468492 default:
469493 Intr->dump();
470494 llvm_unreachable("Don't know how to promote alloca intrinsic use.");
0 ; RUN: opt -S -mtriple=amdgcn-unknown-amdhsa -amdgpu-promote-alloca < %s | FileCheck %s
1
2 declare void @llvm.memcpy.p0i8.p1i8.i32(i8* nocapture, i8 addrspace(1)* nocapture, i32, i32, i1) #0
3 declare void @llvm.memcpy.p1i8.p0i8.i32(i8 addrspace(1)* nocapture, i8* nocapture, i32, i32, i1) #0
4
5 declare void @llvm.memmove.p0i8.p1i8.i32(i8* nocapture, i8 addrspace(1)* nocapture, i32, i32, i1) #0
6 declare void @llvm.memmove.p1i8.p0i8.i32(i8 addrspace(1)* nocapture, i8* nocapture, i32, i32, i1) #0
7
8 declare void @llvm.memset.p0i8.i32(i8* nocapture, i8, i32, i32, i1) #0
9
10 declare i32 @llvm.objectsize.i32.p0i8(i8*, i1) #1
11
12 ; CHECK-LABEL: @promote_with_memcpy(
13 ; CHECK: getelementptr [256 x [17 x i32]], [256 x [17 x i32]] addrspace(3)* @alloca, i32 0, i32 %{{[0-9]+}}
14 ; CHECK: call void @llvm.memcpy.p3i8.p1i8.i32(i8 addrspace(3)* %alloca.bc, i8 addrspace(1)* %in.bc, i32 68, i32 4, i1 false)
15 ; CHECK: call void @llvm.memcpy.p1i8.p3i8.i32(i8 addrspace(1)* %out.bc, i8 addrspace(3)* %alloca.bc, i32 68, i32 4, i1 false)
16 define void @promote_with_memcpy(i32 addrspace(1)* %out, i32 addrspace(1)* %in) #0 {
17 %alloca = alloca [17 x i32], align 16
18 %alloca.bc = bitcast [17 x i32]* %alloca to i8*
19 %in.bc = bitcast i32 addrspace(1)* %in to i8 addrspace(1)*
20 %out.bc = bitcast i32 addrspace(1)* %out to i8 addrspace(1)*
21 call void @llvm.memcpy.p0i8.p1i8.i32(i8* %alloca.bc, i8 addrspace(1)* %in.bc, i32 68, i32 4, i1 false)
22 call void @llvm.memcpy.p1i8.p0i8.i32(i8 addrspace(1)* %out.bc, i8* %alloca.bc, i32 68, i32 4, i1 false)
23 ret void
24 }
25
26 ; CHECK-LABEL: @promote_with_memmove(
27 ; CHECK: getelementptr [256 x [17 x i32]], [256 x [17 x i32]] addrspace(3)* @alloca.1, i32 0, i32 %{{[0-9]+}}
28 ; CHECK: call void @llvm.memmove.p3i8.p1i8.i32(i8 addrspace(3)* %alloca.bc, i8 addrspace(1)* %in.bc, i32 68, i32 4, i1 false)
29 ; CHECK: call void @llvm.memmove.p1i8.p3i8.i32(i8 addrspace(1)* %out.bc, i8 addrspace(3)* %alloca.bc, i32 68, i32 4, i1 false)
30 define void @promote_with_memmove(i32 addrspace(1)* %out, i32 addrspace(1)* %in) #0 {
31 %alloca = alloca [17 x i32], align 16
32 %alloca.bc = bitcast [17 x i32]* %alloca to i8*
33 %in.bc = bitcast i32 addrspace(1)* %in to i8 addrspace(1)*
34 %out.bc = bitcast i32 addrspace(1)* %out to i8 addrspace(1)*
35 call void @llvm.memmove.p0i8.p1i8.i32(i8* %alloca.bc, i8 addrspace(1)* %in.bc, i32 68, i32 4, i1 false)
36 call void @llvm.memmove.p1i8.p0i8.i32(i8 addrspace(1)* %out.bc, i8* %alloca.bc, i32 68, i32 4, i1 false)
37 ret void
38 }
39
40 ; CHECK-LABEL: @promote_with_memset(
41 ; CHECK: getelementptr [256 x [17 x i32]], [256 x [17 x i32]] addrspace(3)* @alloca.2, i32 0, i32 %{{[0-9]+}}
42 ; CHECK: call void @llvm.memset.p3i8.i32(i8 addrspace(3)* %alloca.bc, i8 7, i32 68, i32 4, i1 false)
43 define void @promote_with_memset(i32 addrspace(1)* %out, i32 addrspace(1)* %in) #0 {
44 %alloca = alloca [17 x i32], align 16
45 %alloca.bc = bitcast [17 x i32]* %alloca to i8*
46 %in.bc = bitcast i32 addrspace(1)* %in to i8 addrspace(1)*
47 %out.bc = bitcast i32 addrspace(1)* %out to i8 addrspace(1)*
48 call void @llvm.memset.p0i8.i32(i8* %alloca.bc, i8 7, i32 68, i32 4, i1 false)
49 ret void
50 }
51
52 ; CHECK-LABEL: @promote_with_objectsize(
53 ; CHECK: [[PTR:%[0-9]+]] = getelementptr [256 x [17 x i32]], [256 x [17 x i32]] addrspace(3)* @alloca.3, i32 0, i32 %{{[0-9]+}}
54 ; CHECK: call i32 @llvm.objectsize.i32.p3i8(i8 addrspace(3)* %alloca.bc, i1 false)
55 define void @promote_with_objectsize(i32 addrspace(1)* %out) #0 {
56 %alloca = alloca [17 x i32], align 16
57 %alloca.bc = bitcast [17 x i32]* %alloca to i8*
58 %size = call i32 @llvm.objectsize.i32.p0i8(i8* %alloca.bc, i1 false)
59 store i32 %size, i32 addrspace(1)* %out
60 ret void
61 }
62
63 attributes #0 = { nounwind }
64 attributes #1 = { nounwind readnone }