1; RUN: opt < %s -force-vector-width=2 -force-vector-interleave=2 -loop-vectorize -S | FileCheck %s
2
3target datalayout = "e-m:e-i64:64-i128:128-n32:64-S128"
4
5; CHECK-LABEL: @dead_instructions_01
6;
7; This test ensures that we don't generate trivially dead instructions prior to
8; instruction simplification. We don't need to generate instructions
9; corresponding to the original induction variable update or branch condition,
10; since we rewrite the loop structure.
11;
12; CHECK:     vector.body:
13; CHECK:       %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
14; CHECK:       %[[I0:.+]] = add i64 %index, 0
15; CHECK:       %[[I2:.+]] = add i64 %index, 2
16; CHECK:       getelementptr inbounds i64, i64* %a, i64 %[[I0]]
17; CHECK:       getelementptr inbounds i64, i64* %a, i64 %[[I2]]
18; CHECK-NOT:   add nuw nsw i64 %[[I0]], 1
19; CHECK-NOT:   add nuw nsw i64 %[[I2]], 1
20; CHECK-NOT:   icmp slt i64 {{.*}}, %n
21; CHECK:       %index.next = add i64 %index, 4
22; CHECK:       %[[CMP:.+]] = icmp eq i64 %index.next, %n.vec
23; CHECK:       br i1 %[[CMP]], label %middle.block, label %vector.body
24;
25define i64 @dead_instructions_01(i64 *%a, i64 %n) {
26entry:
27  br label %for.body
28
29for.body:
30  %i = phi i64 [ %i.next, %for.body ], [ 0, %entry ]
31  %r = phi i64 [ %tmp2, %for.body ], [ 0, %entry ]
32  %tmp0 = getelementptr inbounds i64, i64* %a, i64 %i
33  %tmp1 = load i64, i64* %tmp0, align 8
34  %tmp2 = add i64 %tmp1, %r
35  %i.next = add nuw nsw i64 %i, 1
36  %cond = icmp slt i64 %i.next, %n
37  br i1 %cond, label %for.body, label %for.end
38
39for.end:
40  %tmp3  = phi i64 [ %tmp2, %for.body ]
41  ret i64 %tmp3
42}
43
44
45; CHECK-LABEL: @pr47390
46;
47; This test ensures that the primary induction is not considered dead when
48; acting as the 'add' of another induction, and otherwise feeding only its own
49; 'add' (recognized earlier as 'dead'), when the tail of the loop is folded by
50; masking. Such masking uses the primary induction.
51;
52; CHECK:     vector.body:
53;
54define void @pr47390(i32 *%a) {
55entry:
56  br label %loop
57
58exit:
59  ret void
60
61loop:
62  %primary = phi i32 [ 0, %entry ], [ %primary_add, %loop ]
63  %use_primary = phi i32 [ -1, %entry ], [ %primary, %loop ]
64  %secondary = phi i32 [ 1, %entry ], [ %secondary_add, %loop ]
65  %primary_add = add i32 %primary, 1
66  %secondary_add = add i32 %secondary, 1
67  %gep = getelementptr inbounds i32, i32* %a, i32 %secondary
68  %load = load i32, i32* %gep, align 8
69  %cmp = icmp eq i32 %secondary, 5
70  br i1 %cmp, label %exit, label %loop
71}
72