• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; RUN: opt < %s -loop-vectorize -force-vector-width=4 -S | FileCheck %s
2
3; The three test-cases below are all based on modified versions of a simple copy-loop:
4;
5; void foo(unsigned *src, unsigned *dst, unsigned nElts) {
6;   for (unsigned i = 0; i < nElts; ++i) {
7;     unsigned tmp = src[i];
8;     dst[i] = tmp;
9;   }
10; }
11;
12; In the first version, there are no nontemporal stores or loads, and so vectorization
13; is safely done.
14;
15; In the second version, the store into dst[i] has the nontemporal hint.  The alignment
16; on X86_64 for 'unsigned' is 4, so the vector store generally will not be aligned to the
17; vector size (of 16 here).  Unaligned nontemporal vector stores are not supported on X86_64,
18; and so the vectorization is suppressed (because when vectorizing it, the nontemoral hint
19; would not be honored in the final code-gen).
20;
21; The third version is analogous to the second, except rather than the store, it is the
22; load from 'src[i]' that has the nontemporal hint.  Vectorization is suppressed in this
23; case because (like stores) unaligned nontemoral vector loads are not supported on X86_64.
24
25target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
26target triple = "x86_64"
27
28; CHECK-LABEL: @vectorTest(
29define void @vectorTest(i32* noalias readonly %src, i32* noalias %dst, i32 %nElts) {
30entry:
31  %cmp8 = icmp eq i32 %nElts, 0
32  br i1 %cmp8, label %for.cond.cleanup, label %for.body.preheader
33
34for.body.preheader:                               ; preds = %entry
35  %wide.trip.count = zext i32 %nElts to i64
36  br label %for.body
37
38for.cond.cleanup:                                 ; preds = %for.body, %entry
39  ret void
40
41for.body:                                         ; preds = %for.body, %for.body.preheader
42  %indvars.iv = phi i64 [ 0, %for.body.preheader ], [ %indvars.iv.next, %for.body ]
43; Check that we vectorized the load, and that there is no nontemporal hint.
44; CHECK: %wide.load = load <4 x i32>, <4 x i32>* %{{[0-9]+}}, align 4{{$}}
45  %arrayidx = getelementptr inbounds i32, i32* %src, i64 %indvars.iv
46  %0 = load i32, i32* %arrayidx, align 4
47; Check that we vectorized the store, and that there is no nontemporal hint.
48; CHECK: store <4 x i32> %wide.load, <4 x i32>* %{{[0-9]+}}, align 4{{$}}
49  %arrayidx2 = getelementptr inbounds i32, i32* %dst, i64 %indvars.iv
50  store i32 %0, i32* %arrayidx2, align 4
51  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
52  %exitcond = icmp eq i64 %indvars.iv.next, %wide.trip.count
53  br i1 %exitcond, label %for.cond.cleanup, label %for.body
54}
55
56; CHECK-LABEL: @vectorNTStoreTest(
57; Check that the vectorized type of the store does not appear.
58; CHECK-NOT: 4 x i32
59define void @vectorNTStoreTest(i32* noalias readonly %src, i32* noalias %dst, i32 %nElts) {
60entry:
61  %cmp8 = icmp eq i32 %nElts, 0
62  br i1 %cmp8, label %for.cond.cleanup, label %for.body.preheader
63
64for.body.preheader:                               ; preds = %entry
65  %wide.trip.count = zext i32 %nElts to i64
66  br label %for.body
67
68for.cond.cleanup:                                 ; preds = %for.body, %entry
69  ret void
70
71for.body:                                         ; preds = %for.body, %for.body.preheader
72  %indvars.iv = phi i64 [ 0, %for.body.preheader ], [ %indvars.iv.next, %for.body ]
73  %arrayidx = getelementptr inbounds i32, i32* %src, i64 %indvars.iv
74  %0 = load i32, i32* %arrayidx, align 4
75  %arrayidx2 = getelementptr inbounds i32, i32* %dst, i64 %indvars.iv
76; Check that the store is not vectorized and that we don't lose the !nontemporal hint in it.
77; CHECK: store i32 %{{[0-9]+}}, i32* %arrayidx2, align 4, !nontemporal !4
78  store i32 %0, i32* %arrayidx2, align 4, !nontemporal !0
79  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
80  %exitcond = icmp eq i64 %indvars.iv.next, %wide.trip.count
81  br i1 %exitcond, label %for.cond.cleanup, label %for.body
82}
83
84; CHECK-LABEL: @vectorNTLoadTest(
85; Check that the vectorized type of the load does not appear.
86; CHECK-NOT: 4 x i32
87define void @vectorNTLoadTest(i32* noalias readonly %src, i32* noalias %dst, i32 %nElts) {
88entry:
89  %cmp8 = icmp eq i32 %nElts, 0
90  br i1 %cmp8, label %for.cond.cleanup, label %for.body.preheader
91
92for.body.preheader:                               ; preds = %entry
93  %wide.trip.count = zext i32 %nElts to i64
94  br label %for.body
95
96for.cond.cleanup:                                 ; preds = %for.body, %entry
97  ret void
98
99for.body:                                         ; preds = %for.body, %for.body.preheader
100  %indvars.iv = phi i64 [ 0, %for.body.preheader ], [ %indvars.iv.next, %for.body ]
101  %arrayidx = getelementptr inbounds i32, i32* %src, i64 %indvars.iv
102; Check that the load is not vectorized and that we don't lose the !nontemporal hint in it.
103; CHECK: load i32, i32* %arrayidx, align 4, !nontemporal !4
104  %0 = load i32, i32* %arrayidx, align 4, !nontemporal !0
105  %arrayidx2 = getelementptr inbounds i32, i32* %dst, i64 %indvars.iv
106  store i32 %0, i32* %arrayidx2, align 4
107  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
108  %exitcond = icmp eq i64 %indvars.iv.next, %wide.trip.count
109  br i1 %exitcond, label %for.cond.cleanup, label %for.body
110}
111
112!0 = !{i32 1}
113