xref: /llvm-project/llvm/test/Transforms/LoopVectorize/interleaved-accesses-2.ll (revision 29441e4f5fa5f5c7709f7cf180815ba97f611297)
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2; RUN: opt -S -passes=loop-vectorize,instcombine -force-vector-width=4 -force-vector-interleave=1 -enable-interleaved-mem-accesses=true < %s | FileCheck %s
3
4target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
5
6; Check that the interleaved-mem-access analysis currently does not create an
7; interleave group for the access to array 'in' due to the possibly wrapping
8; unsigned 'out_ix' index.
9;
10; In this test the interleave-group of the loads is not full (has gaps), so
11; the wrapping checks are necessary. Here this cannot be done statically so
12; runtime checks are needed, but with Assume=false getPtrStride cannot add
13; runtime checks and as a result we can't create the interleave-group.
14;
15; #include <stdlib.h>
16; void test(ptr __restrict__ out, ptr __restrict__ in, size_t size)
17; {
18;    for (size_t out_offset = 0; out_offset < size; ++out_offset)
19;      {
20;        float t0 = in[2*out_offset];
21;        out[out_offset] = t0;
22;      }
23; }
24
25define void @_Z4testPfS_m(ptr noalias nocapture %out, ptr noalias nocapture readonly %in, i64 %size) local_unnamed_addr {
26; CHECK-LABEL: define void @_Z4testPfS_m(
27; CHECK-SAME: ptr noalias captures(none) [[OUT:%.*]], ptr noalias readonly captures(none) [[IN:%.*]], i64 [[SIZE:%.*]]) local_unnamed_addr {
28; CHECK-NEXT:  [[ENTRY:.*:]]
29; CHECK-NEXT:    [[CMP7:%.*]] = icmp eq i64 [[SIZE]], 0
30; CHECK-NEXT:    br i1 [[CMP7]], label %[[FOR_COND_CLEANUP:.*]], label %[[FOR_BODY_PREHEADER:.*]]
31; CHECK:       [[FOR_BODY_PREHEADER]]:
32; CHECK-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[SIZE]], 5
33; CHECK-NEXT:    br i1 [[MIN_ITERS_CHECK]], label %[[SCALAR_PH:.*]], label %[[VECTOR_PH:.*]]
34; CHECK:       [[VECTOR_PH]]:
35; CHECK-NEXT:    [[N_MOD_VF:%.*]] = and i64 [[SIZE]], 3
36; CHECK-NEXT:    [[TMP0:%.*]] = icmp eq i64 [[N_MOD_VF]], 0
37; CHECK-NEXT:    [[TMP1:%.*]] = select i1 [[TMP0]], i64 4, i64 [[N_MOD_VF]]
38; CHECK-NEXT:    [[N_VEC:%.*]] = sub i64 [[SIZE]], [[TMP1]]
39; CHECK-NEXT:    br label %[[VECTOR_BODY:.*]]
40; CHECK:       [[VECTOR_BODY]]:
41; CHECK-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, %[[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], %[[VECTOR_BODY]] ]
42; CHECK-NEXT:    [[DOTIDX:%.*]] = shl i64 [[INDEX]], 3
43; CHECK-NEXT:    [[TMP2:%.*]] = getelementptr inbounds i8, ptr [[IN]], i64 [[DOTIDX]]
44; CHECK-NEXT:    [[WIDE_VEC:%.*]] = load <8 x i32>, ptr [[TMP2]], align 4
45; CHECK-NEXT:    [[STRIDED_VEC:%.*]] = shufflevector <8 x i32> [[WIDE_VEC]], <8 x i32> poison, <4 x i32> <i32 0, i32 2, i32 4, i32 6>
46; CHECK-NEXT:    [[TMP3:%.*]] = getelementptr inbounds float, ptr [[OUT]], i64 [[INDEX]]
47; CHECK-NEXT:    store <4 x i32> [[STRIDED_VEC]], ptr [[TMP3]], align 4
48; CHECK-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 4
49; CHECK-NEXT:    [[TMP4:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
50; CHECK-NEXT:    br i1 [[TMP4]], label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !llvm.loop [[LOOP0:![0-9]+]]
51; CHECK:       [[MIDDLE_BLOCK]]:
52; CHECK-NEXT:    br label %[[SCALAR_PH]]
53; CHECK:       [[SCALAR_PH]]:
54; CHECK-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], %[[MIDDLE_BLOCK]] ], [ 0, %[[FOR_BODY_PREHEADER]] ]
55; CHECK-NEXT:    br label %[[FOR_BODY:.*]]
56; CHECK:       [[FOR_COND_CLEANUP_LOOPEXIT:.*]]:
57; CHECK-NEXT:    br label %[[FOR_COND_CLEANUP]]
58; CHECK:       [[FOR_COND_CLEANUP]]:
59; CHECK-NEXT:    ret void
60; CHECK:       [[FOR_BODY]]:
61; CHECK-NEXT:    [[OUT_OFFSET_08:%.*]] = phi i64 [ [[INC:%.*]], %[[FOR_BODY]] ], [ [[BC_RESUME_VAL]], %[[SCALAR_PH]] ]
62; CHECK-NEXT:    [[ARRAYIDX_IDX:%.*]] = shl i64 [[OUT_OFFSET_08]], 3
63; CHECK-NEXT:    [[ARRAYIDX:%.*]] = getelementptr inbounds i8, ptr [[IN]], i64 [[ARRAYIDX_IDX]]
64; CHECK-NEXT:    [[TMP5:%.*]] = load i32, ptr [[ARRAYIDX]], align 4
65; CHECK-NEXT:    [[ARRAYIDX1:%.*]] = getelementptr inbounds float, ptr [[OUT]], i64 [[OUT_OFFSET_08]]
66; CHECK-NEXT:    store i32 [[TMP5]], ptr [[ARRAYIDX1]], align 4
67; CHECK-NEXT:    [[INC]] = add nuw i64 [[OUT_OFFSET_08]], 1
68; CHECK-NEXT:    [[EXITCOND:%.*]] = icmp eq i64 [[INC]], [[SIZE]]
69; CHECK-NEXT:    br i1 [[EXITCOND]], label %[[FOR_COND_CLEANUP_LOOPEXIT]], label %[[FOR_BODY]], !llvm.loop [[LOOP3:![0-9]+]]
70;
71entry:
72  %cmp7 = icmp eq i64 %size, 0
73  br i1 %cmp7, label %for.cond.cleanup, label %for.body.preheader
74
75for.body.preheader:
76  br label %for.body
77
78for.cond.cleanup.loopexit:
79  br label %for.cond.cleanup
80
81for.cond.cleanup:
82  ret void
83
84for.body:
85  %out_offset.08 = phi i64 [ %inc, %for.body ], [ 0, %for.body.preheader ]
86  %mul = shl i64 %out_offset.08, 1
87  %arrayidx = getelementptr inbounds float, ptr %in, i64 %mul
88  %0 = load i32, ptr %arrayidx, align 4
89  %arrayidx1 = getelementptr inbounds float, ptr %out, i64 %out_offset.08
90  store i32 %0, ptr %arrayidx1, align 4
91  %inc = add nuw i64 %out_offset.08, 1
92  %exitcond = icmp eq i64 %inc, %size
93  br i1 %exitcond, label %for.cond.cleanup.loopexit, label %for.body
94}
95;.
96; CHECK: [[LOOP0]] = distinct !{[[LOOP0]], [[META1:![0-9]+]], [[META2:![0-9]+]]}
97; CHECK: [[META1]] = !{!"llvm.loop.isvectorized", i32 1}
98; CHECK: [[META2]] = !{!"llvm.loop.unroll.runtime.disable"}
99; CHECK: [[LOOP3]] = distinct !{[[LOOP3]], [[META2]], [[META1]]}
100;.
101