1; RUN: opt -mtriple=x86_64-unknown-linux-gnu -load-store-vectorizer -S -o - %s | FileCheck %s
2; RUN: opt -mtriple=x86_64-unknown-linux-gnu -aa-pipeline=basic-aa -passes='function(load-store-vectorizer)' -S -o - %s | FileCheck %s
3
4target datalayout = "e-m:e-i64:64-i128:128-n32:64-S128"
5
6%struct.buffer_t = type { i64, i8* }
7%struct.nested.buffer = type { %struct.buffer_t, %struct.buffer_t }
8
9; Check an i64 and i8* get vectorized, and that the two accesses
10; (load into buff.val and store to buff.p) preserve their order.
11; Vectorized loads should be inserted at the position of the first load,
12; and instructions which were between the first and last load should be
13; reordered preserving their relative order inasmuch as possible.
14
15; CHECK-LABEL: @preserve_order_64(
16; CHECK: load <2 x i64>
17; CHECK: %buff.val = load i8
18; CHECK: store i8 0
19define void @preserve_order_64(%struct.buffer_t* noalias %buff) #0 {
20entry:
21  %tmp1 = getelementptr inbounds %struct.buffer_t, %struct.buffer_t* %buff, i64 0, i32 1
22  %buff.p = load i8*, i8** %tmp1
23  %buff.val = load i8, i8* %buff.p
24  store i8 0, i8* %buff.p, align 8
25  %tmp0 = getelementptr inbounds %struct.buffer_t, %struct.buffer_t* %buff, i64 0, i32 0
26  %buff.int = load i64, i64* %tmp0, align 16
27  ret void
28}
29
30; Check reordering recurses correctly.
31
32; CHECK-LABEL: @transitive_reorder(
33; CHECK: load <2 x i64>
34; CHECK: %buff.val = load i8
35; CHECK: store i8 0
36define void @transitive_reorder(%struct.buffer_t* noalias %buff, %struct.nested.buffer* noalias %nest) #0 {
37entry:
38  %nest0_0 = getelementptr inbounds %struct.nested.buffer, %struct.nested.buffer* %nest, i64 0, i32 0
39  %tmp1 = getelementptr inbounds %struct.buffer_t, %struct.buffer_t* %nest0_0, i64 0, i32 1
40  %buff.p = load i8*, i8** %tmp1
41  %buff.val = load i8, i8* %buff.p
42  store i8 0, i8* %buff.p, align 8
43  %nest1_0 = getelementptr inbounds %struct.nested.buffer, %struct.nested.buffer* %nest, i64 0, i32 0
44  %tmp0 = getelementptr inbounds %struct.buffer_t, %struct.buffer_t* %nest1_0, i64 0, i32 0
45  %buff.int = load i64, i64* %tmp0, align 16
46  ret void
47}
48
49; Check for no vectorization over phi node
50
51; CHECK-LABEL: @no_vect_phi(
52; CHECK: load i8*
53; CHECK: load i8
54; CHECK: store i8 0
55; CHECK: load i64
56define void @no_vect_phi(i32* noalias %ptr, %struct.buffer_t* noalias %buff) {
57entry:
58  %tmp1 = getelementptr inbounds %struct.buffer_t, %struct.buffer_t* %buff, i64 0, i32 1
59  %buff.p = load i8*, i8** %tmp1
60  %buff.val = load i8, i8* %buff.p
61  store i8 0, i8* %buff.p, align 8
62  br label %"for something"
63
64"for something":
65  %index = phi i64 [ 0, %entry ], [ %index.next, %"for something" ]
66
67  %tmp0 = getelementptr inbounds %struct.buffer_t, %struct.buffer_t* %buff, i64 0, i32 0
68  %buff.int = load i64, i64* %tmp0, align 16
69
70  %index.next = add i64 %index, 8
71  %cmp_res = icmp eq i64 %index.next, 8
72  br i1 %cmp_res, label %ending, label %"for something"
73
74ending:
75  ret void
76}
77
78attributes #0 = { nounwind }
79