xref: /llvm-project/llvm/test/Transforms/LoopVectorize/vectorize-once.ll (revision eb16435b5e5df68d2410bbe4c08ef8ce8aa8b2f4)
1; RUN: opt < %s -loop-vectorize -force-vector-interleave=1 -force-vector-width=4 -dce -instcombine -S -simplifycfg | FileCheck %s
2
3target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
4
5;
6; We want to make sure that we are vectorizeing the scalar loop only once
7; even if the pass manager runs the vectorizer multiple times due to inlining.
8
9
10; This test checks that we add metadata to vectorized loops
11; CHECK-LABEL: @_Z4foo1Pii(
12; CHECK: <4 x i32>
13; CHECK: llvm.loop
14; CHECK: ret
15
16; This test comes from the loop:
17;
18;int foo (int *A, int n) {
19;  return std::accumulate(A, A + n, 0);
20;}
21define i32 @_Z4foo1Pii(i32* %A, i32 %n) #0 {
22entry:
23  %idx.ext = sext i32 %n to i64
24  %add.ptr = getelementptr inbounds i32, i32* %A, i64 %idx.ext
25  %cmp3.i = icmp eq i32 %n, 0
26  br i1 %cmp3.i, label %_ZSt10accumulateIPiiET0_T_S2_S1_.exit, label %for.body.i
27
28for.body.i:                                       ; preds = %entry, %for.body.i
29  %__init.addr.05.i = phi i32 [ %add.i, %for.body.i ], [ 0, %entry ]
30  %__first.addr.04.i = phi i32* [ %incdec.ptr.i, %for.body.i ], [ %A, %entry ]
31  %0 = load i32, i32* %__first.addr.04.i, align 4
32  %add.i = add nsw i32 %0, %__init.addr.05.i
33  %incdec.ptr.i = getelementptr inbounds i32, i32* %__first.addr.04.i, i64 1
34  %cmp.i = icmp eq i32* %incdec.ptr.i, %add.ptr
35  br i1 %cmp.i, label %_ZSt10accumulateIPiiET0_T_S2_S1_.exit, label %for.body.i
36
37_ZSt10accumulateIPiiET0_T_S2_S1_.exit:            ; preds = %for.body.i, %entry
38  %__init.addr.0.lcssa.i = phi i32 [ 0, %entry ], [ %add.i, %for.body.i ]
39  ret i32 %__init.addr.0.lcssa.i
40}
41
42; This test checks that we don't vectorize loops that are marked with the "width" == 1 metadata.
43; CHECK-LABEL: @_Z4foo2Pii(
44; CHECK-NOT: <4 x i32>
45; CHECK: llvm.loop
46; CHECK: ret
47define i32 @_Z4foo2Pii(i32* %A, i32 %n) #0 {
48entry:
49  %idx.ext = sext i32 %n to i64
50  %add.ptr = getelementptr inbounds i32, i32* %A, i64 %idx.ext
51  %cmp3.i = icmp eq i32 %n, 0
52  br i1 %cmp3.i, label %_ZSt10accumulateIPiiET0_T_S2_S1_.exit, label %for.body.i
53
54for.body.i:                                       ; preds = %entry, %for.body.i
55  %__init.addr.05.i = phi i32 [ %add.i, %for.body.i ], [ 0, %entry ]
56  %__first.addr.04.i = phi i32* [ %incdec.ptr.i, %for.body.i ], [ %A, %entry ]
57  %0 = load i32, i32* %__first.addr.04.i, align 4
58  %add.i = add nsw i32 %0, %__init.addr.05.i
59  %incdec.ptr.i = getelementptr inbounds i32, i32* %__first.addr.04.i, i64 1
60  %cmp.i = icmp eq i32* %incdec.ptr.i, %add.ptr
61  br i1 %cmp.i, label %_ZSt10accumulateIPiiET0_T_S2_S1_.exit, label %for.body.i, !llvm.loop !0
62
63_ZSt10accumulateIPiiET0_T_S2_S1_.exit:            ; preds = %for.body.i, %entry
64  %__init.addr.0.lcssa.i = phi i32 [ 0, %entry ], [ %add.i, %for.body.i ]
65  ret i32 %__init.addr.0.lcssa.i
66}
67
68attributes #0 = { nounwind readonly ssp uwtable "fp-contract-model"="standard" "no-frame-pointer-elim" "frame-pointer"="non-leaf" "realign-stack" "relocation-model"="pic" "ssp-buffers-size"="8" }
69
70; CHECK: !0 = distinct !{!0, !1}
71; CHECK: !1 = !{!"llvm.loop.isvectorized", i32 1}
72; CHECK: !2 = distinct !{!2, !3, !1}
73; CHECK: !3 = !{!"llvm.loop.unroll.runtime.disable"}
74
75!0 = !{!0, !1}
76!1 = !{!"llvm.loop.vectorize.width", i32 1}
77