xref: /llvm-project/llvm/test/Transforms/LoopVectorize/scalar_after_vectorization.ll (revision 462cb3cd6cecd0511ecaf0e3ebcaba455ece587d)
1; RUN: opt < %s -force-vector-width=4 -force-vector-interleave=2 -passes=loop-vectorize,instcombine -S | FileCheck %s
2; RUN: opt < %s -force-vector-width=4 -force-vector-interleave=2 -passes=loop-vectorize -S | FileCheck %s --check-prefix=NO-IC
3
4target datalayout = "e-m:e-i64:64-i128:128-n32:64-S128"
5
6; CHECK-LABEL: @scalar_after_vectorization_0
7;
8; CHECK: vector.body:
9; CHECK:   %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
10; CHECK:   [[OFFSET_IDX:%.+]] = or disjoint i64 %index, 1
11; CHECK:   %[[T2:.+]] = add nuw nsw i64 [[OFFSET_IDX]], %tmp0
12; CHECK:   %[[T3:.+]] = sub nsw i64 %[[T2]], %x
13; CHECK:   %[[T4:.+]] = getelementptr inbounds i32, ptr %a, i64 %[[T3]]
14; CHECK:   %[[T6:.+]] = getelementptr inbounds nuw i8, ptr %[[T4]], i64 16
15; CHECK:   load <4 x i32>, ptr %[[T4]], align 4
16; CHECK:   load <4 x i32>, ptr %[[T6]], align 4
17; CHECK:   br {{.*}}, label %middle.block, label %vector.body
18;
19; NO-IC-LABEL: @scalar_after_vectorization_0
20;
21; NO-IC: vector.body:
22; NO-IC:   %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
23; NO-IC:   [[OFFSET_IDX:%.+]] = add i64 1, %index
24; NO-IC:   %[[T2:.+]] = add i64 [[OFFSET_IDX]], 0
25; NO-IC:   %[[T4:.+]] = add nuw nsw i64 %[[T2]], %tmp0
26; NO-IC:   %[[T6:.+]] = sub nsw i64 %[[T4]], %x
27; NO-IC:   %[[T8:.+]] = getelementptr inbounds i32, ptr %a, i64 %[[T6]]
28; NO-IC:   %[[T10:.+]] = getelementptr inbounds i32, ptr %[[T8]], i32 0
29; NO-IC:   %[[T12:.+]] = getelementptr inbounds i32, ptr %[[T8]], i32 4
30; NO-IC:   load <4 x i32>, ptr %[[T10]], align 4
31; NO-IC:   load <4 x i32>, ptr %[[T12]], align 4
32; NO-IC:   br {{.*}}, label %middle.block, label %vector.body
33;
34define void @scalar_after_vectorization_0(ptr noalias %a, ptr noalias %b, i64 %x, i64 %y) {
35
36outer.ph:
37  br label %outer.body
38
39outer.body:
40  %i = phi i64 [ 1, %outer.ph ], [ %i.next, %inner.end ]
41  %tmp0 = mul nuw nsw i64 %i, %x
42  br label %inner.ph
43
44inner.ph:
45  br label %inner.body
46
47inner.body:
48  %j = phi i64 [ 1, %inner.ph ], [ %j.next, %inner.body ]
49  %tmp1 = add nuw nsw i64 %j, %tmp0
50  %tmp2 = sub nsw i64 %tmp1, %x
51  %tmp3 = getelementptr inbounds i32, ptr %a, i64 %tmp2
52  %tmp4 = load i32, ptr %tmp3, align 4
53  %tmp5 = getelementptr inbounds i32, ptr %b, i64 %tmp1
54  store i32 %tmp4, ptr %tmp5, align 4
55  %j.next = add i64 %j, 1
56  %cond.j = icmp slt i64 %j.next, %y
57  br i1 %cond.j, label %inner.body, label %inner.end
58
59inner.end:
60  %i.next = add i64 %i, 1
61  %cond.i = icmp slt i64 %i.next, %y
62  br i1 %cond.i, label %outer.body, label %outer.end
63
64outer.end:
65  ret void
66}
67