1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -basic-aa -scoped-noalias-aa -memcpyopt -S %s -verify-memoryssa | FileCheck %s
6 ; A global constant of %T
7 @C = external constant %T
9 ; Ensure load-store forwarding of an aggregate is interpreted as
10 ; a memmove when the source and dest may alias
11 define void @test_memmove(%T* align 8 %a, %T* align 16 %b) {
12 ; CHECK-LABEL: @test_memmove(
13 ; CHECK-NEXT: [[TMP1:%.*]] = bitcast %T* [[B:%.*]] to i8*
14 ; CHECK-NEXT: [[TMP2:%.*]] = bitcast %T* [[A:%.*]] to i8*
15 ; CHECK-NEXT: call void @llvm.memmove.p0i8.p0i8.i64(i8* align 16 [[TMP1]], i8* align 8 [[TMP2]], i64 8, i1 false)
16 ; CHECK-NEXT: ret void
18 %val = load %T, %T* %a, align 8
19 store %T %val, %T* %b, align 16
23 ; Ensure load-store forwarding of an aggregate is interpreted as
24 ; a memcpy when the source and dest do not alias
25 define void @test_memcpy(%T* noalias align 8 %a, %T* noalias align 16 %b) {
26 ; CHECK-LABEL: @test_memcpy(
27 ; CHECK-NEXT: [[TMP1:%.*]] = bitcast %T* [[B:%.*]] to i8*
28 ; CHECK-NEXT: [[TMP2:%.*]] = bitcast %T* [[A:%.*]] to i8*
29 ; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 16 [[TMP1]], i8* align 8 [[TMP2]], i64 8, i1 false)
30 ; CHECK-NEXT: ret void
32 %val = load %T, %T* %a, align 8
33 store %T %val, %T* %b, align 16
37 define void @test_memcpy_constant(%T* %d) {
38 ; CHECK-LABEL: @test_memcpy_constant(
39 ; CHECK-NEXT: [[TMP1:%.*]] = bitcast %T* [[D:%.*]] to i8*
40 ; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 16 [[TMP1]], i8* align 8 getelementptr inbounds ([[T:%.*]], %T* @C, i32 0, i32 0), i64 8, i1 false)
41 ; CHECK-NEXT: ret void
43 %val = load %T, %T* @C, align 8
44 store %T %val, %T* %d, align 16
48 ; memcpy(%d, %a) should not be generated since store2 may-aliases load %a.
49 define void @f(%T* %a, %T* %b, %T* %c, %T* %d) {
51 ; CHECK-NEXT: [[VAL:%.*]] = load [[T:%.*]], %T* [[A:%.*]], align 4, !alias.scope !0
52 ; CHECK-NEXT: store [[T]] { i8 23, i32 23 }, %T* [[B:%.*]], align 4, !alias.scope !3
53 ; CHECK-NEXT: store [[T]] { i8 44, i32 44 }, %T* [[C:%.*]], align 4, !alias.scope !6, !noalias !3
54 ; CHECK-NEXT: store [[T]] [[VAL]], %T* [[D:%.*]], align 4, !alias.scope !9, !noalias !12
55 ; CHECK-NEXT: ret void
57 %val = load %T, %T* %a, !alias.scope !{!10}
59 ; store1 may-aliases the load
60 store %T { i8 23, i32 23 }, %T* %b, !alias.scope !{!11}
62 ; store2 may-aliases the load and store3
63 store %T { i8 44, i32 44 }, %T* %c, !alias.scope !{!12}, !noalias !{!11}
66 store %T %val, %T* %d, !alias.scope !{!13}, !noalias !{!10, !11}