1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -passes=memcpyopt < %s -verify-memoryssa | FileCheck %s
4 %struct.MaskedType = type { i8, i8 }
6 declare void @llvm.lifetime.start.p0(i64, ptr nocapture) #0
7 declare void @llvm.lifetime.end.p0(i64, ptr nocapture) #0
8 declare void @MaskedFunction1(ptr, ptr addrspace(1))
9 declare void @MaskedFunction2(ptr, ptr)
11 define i8 @test_gep_not_modified(ptr %in0, ptr %in1) {
12 ; CHECK-LABEL: @test_gep_not_modified(
14 ; CHECK-NEXT: [[FUNCALLOC:%.*]] = alloca [[STRUCT_MASKEDTYPE:%.*]], align 4
15 ; CHECK-NEXT: [[PTRALLOC:%.*]] = alloca i8, align 1
16 ; CHECK-NEXT: call void @llvm.lifetime.start.p0(i64 4, ptr [[PTRALLOC]])
17 ; CHECK-NEXT: [[ADDRSPACECAST:%.*]] = addrspacecast ptr [[PTRALLOC]] to ptr addrspace(1)
18 ; CHECK-NEXT: call void @MaskedFunction1(ptr [[IN1:%.*]], ptr addrspace(1) [[ADDRSPACECAST]])
19 ; CHECK-NEXT: [[LOAD1:%.*]] = load i8, ptr [[PTRALLOC]], align 1
20 ; CHECK-NEXT: call void @llvm.lifetime.end.p0(i64 4, ptr [[PTRALLOC]])
21 ; CHECK-NEXT: [[GETELEMPTR1:%.*]] = getelementptr inbounds [[STRUCT_MASKEDTYPE]], ptr [[FUNCALLOC]], i32 0, i32 1
22 ; CHECK-NEXT: store i8 [[LOAD1]], ptr [[GETELEMPTR1]], align 1
23 ; CHECK-NEXT: ret i8 0
26 %funcAlloc = alloca %struct.MaskedType, align 4
27 %ptrAlloc = alloca i8, align 1
28 call void @llvm.lifetime.start.p0(i64 4, ptr %ptrAlloc) #0
29 %addrspaceCast = addrspacecast ptr %ptrAlloc to ptr addrspace(1)
30 call void @MaskedFunction1(ptr %in1, ptr addrspace(1) %addrspaceCast)
31 %load1 = load i8, ptr %ptrAlloc, align 1
32 call void @llvm.lifetime.end.p0(i64 4, ptr %ptrAlloc) #0
33 %getElemPtr1 = getelementptr inbounds %struct.MaskedType, ptr %funcAlloc, i32 0, i32 1
34 store i8 %load1, ptr %getElemPtr1, align 1
38 define i8 @test_gep_modified(ptr %in0, ptr %in1) {
39 ; CHECK-LABEL: @test_gep_modified(
41 ; CHECK-NEXT: [[FUNCALLOC:%.*]] = alloca [[STRUCT_MASKEDTYPE:%.*]], align 4
42 ; CHECK-NEXT: [[PTRALLOC:%.*]] = alloca i8, align 1
43 ; CHECK-NEXT: call void @llvm.lifetime.start.p0(i64 4, ptr [[PTRALLOC]])
44 ; CHECK-NEXT: [[GETELEMPTR1:%.*]] = getelementptr inbounds [[STRUCT_MASKEDTYPE]], ptr [[FUNCALLOC]], i32 0, i32 1
45 ; CHECK-NEXT: call void @MaskedFunction2(ptr [[IN1:%.*]], ptr [[GETELEMPTR1]])
46 ; CHECK-NEXT: call void @llvm.lifetime.end.p0(i64 4, ptr [[PTRALLOC]])
47 ; CHECK-NEXT: ret i8 0
50 %funcAlloc = alloca %struct.MaskedType, align 4
51 %ptrAlloc = alloca i8, align 1
52 call void @llvm.lifetime.start.p0(i64 4, ptr %ptrAlloc) #0
53 call void @MaskedFunction2(ptr %in1, ptr %ptrAlloc)
54 %load1 = load i8, ptr %ptrAlloc, align 1
55 call void @llvm.lifetime.end.p0(i64 4, ptr %ptrAlloc) #0
56 %getElemPtr1 = getelementptr inbounds %struct.MaskedType, ptr %funcAlloc, i32 0, i32 1
57 store i8 %load1, ptr %getElemPtr1, align 1