1 ; RUN: opt < %s -loop-vectorize -force-vector-width=4 -S | FileCheck %s
3 ; The three test-cases below are all based on modified versions of a simple copy-loop:
5 ; void foo(unsigned *src, unsigned *dst, unsigned nElts) {
6 ; for (unsigned i = 0; i < nElts; ++i) {
7 ; unsigned tmp = src[i];
12 ; In the first version, there are no nontemporal stores or loads, and so vectorization
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).
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.
25 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
26 target triple = "x86_64"
28 ; CHECK-LABEL: @vectorTest(
29 define void @vectorTest(i32* noalias readonly %src, i32* noalias %dst, i32 %nElts) {
31 %cmp8 = icmp eq i32 %nElts, 0
32 br i1 %cmp8, label %for.cond.cleanup, label %for.body.preheader
34 for.body.preheader: ; preds = %entry
35 %wide.trip.count = zext i32 %nElts to i64
38 for.cond.cleanup: ; preds = %for.body, %entry
41 for.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
56 ; CHECK-LABEL: @vectorNTStoreTest(
57 ; Check that the vectorized type of the store does not appear.
59 define void @vectorNTStoreTest(i32* noalias readonly %src, i32* noalias %dst, i32 %nElts) {
61 %cmp8 = icmp eq i32 %nElts, 0
62 br i1 %cmp8, label %for.cond.cleanup, label %for.body.preheader
64 for.body.preheader: ; preds = %entry
65 %wide.trip.count = zext i32 %nElts to i64
68 for.cond.cleanup: ; preds = %for.body, %entry
71 for.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
84 ; CHECK-LABEL: @vectorNTLoadTest(
85 ; Check that the vectorized type of the load does not appear.
87 define void @vectorNTLoadTest(i32* noalias readonly %src, i32* noalias %dst, i32 %nElts) {
89 %cmp8 = icmp eq i32 %nElts, 0
90 br i1 %cmp8, label %for.cond.cleanup, label %for.body.preheader
92 for.body.preheader: ; preds = %entry
93 %wide.trip.count = zext i32 %nElts to i64
96 for.cond.cleanup: ; preds = %for.body, %entry
99 for.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