1 ; RUN: opt -passes='loop-vectorize' -debug -S < %s 2>&1 | FileCheck %s
4 ; This checks we don't crash when the inner loop we're trying to vectorize
5 ; is a SCEV AddRec with respect to an outer loop.
7 ; In this case, the problematic PHI is:
8 ; %0 = phi i32 [ poison, %for.cond1.preheader ], [ %inc54, %for.body3 ]
9 ; Since %inc54 is the IV of the outer loop, and %0 equivalent to it,
10 ; we get the situation described above.
12 ; Code that leads to this situation can look something like:
22 ; The PHI is an artifact of the register promotion of c.
24 ; Note that we can no longer get the vectorizer to actually see such PHIs,
25 ; because LV now simplifies the loop internally, but the test is still
26 ; useful as a regression test, and in case loop-simplify behavior changes.
28 @c = external global i32, align 4
29 @a = external global i32, align 4
30 @b = external global [1 x i32], align 4
32 ; We can vectorize this loop because we are storing an invariant value into an
35 ; CHECK: LV: We can vectorize this loop!
39 %a.promoted2 = load i32, ptr @a, align 1
40 %c.promoted = load i32, ptr @c, align 1
41 br label %for.cond1.preheader
43 for.cond1.preheader: ; preds = %for.cond1.for.inc4_crit_edge, %entry
44 %inc54 = phi i32 [ %inc5, %for.cond1.for.inc4_crit_edge ], [ %c.promoted, %entry ]
45 %inc.lcssa3 = phi i32 [ %inc.lcssa, %for.cond1.for.inc4_crit_edge ], [ %a.promoted2, %entry ]
48 for.body3: ; preds = %for.body3, %for.cond1.preheader
49 %inc1 = phi i32 [ %inc.lcssa3, %for.cond1.preheader ], [ %inc, %for.body3 ]
50 %0 = phi i32 [ poison, %for.cond1.preheader ], [ %inc54, %for.body3 ]
51 %idxprom = sext i32 %0 to i64
52 %arrayidx = getelementptr inbounds [1 x i32], ptr @b, i64 0, i64 %idxprom
53 store i32 4, ptr %arrayidx, align 4
54 %inc = add nsw i32 %inc1, 1
55 %tobool2 = icmp eq i32 %inc, 0
56 br i1 %tobool2, label %for.cond1.for.inc4_crit_edge, label %for.body3
58 for.cond1.for.inc4_crit_edge: ; preds = %for.body3
59 %inc.lcssa = phi i32 [ %inc, %for.body3 ]
60 %.lcssa = phi i32 [ %inc54, %for.body3 ]
61 %inc5 = add nsw i32 %.lcssa, 1
62 br label %for.cond1.preheader