blob: afb1754983cd3efe832e7f158ee68cb599e9796f [file] [log] [blame]
Michael Kupersteinee31cbe2017-01-10 19:32:30 +00001; RUN: opt -passes='loop-vectorize' -debug -S < %s 2>&1 | FileCheck %s
2; REQUIRES: asserts
3
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.
6
7; In this case, the problematic PHI is:
8; %0 = phi i32 [ undef, %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.
11
12; This test uses the new PM, because with the old PM, running loop-vectorize
13; would explicitly run loop-simplify. Even though this loop is already in
14; simplified form, loop-simplify would still clean up the phi.
15; The reason this matters is that in a real optimizer pipeline, LICM can create
16; such PHIs, and since it preserves loop simplified form, the cleanup has
17; no chance to run.
18
19; Code that leads to this situation can look something like:
20;
21; int a, b[1], c;
22; void fn1 ()
23; {
24; for (; c; c++)
25; for (a = 0; a; a++)
26; b[c] = 4;
27; }
28;
29; The PHI is an artifact of the register promotion of c.
30
31@c = external global i32, align 4
32@a = external global i32, align 4
33@b = external global [1 x i32], align 4
34
35; CHECK: LV: PHI is a recurrence with respect to an outer loop.
36; CHECK: LV: Not vectorizing: Cannot prove legality.
37; CHECK-LABEL: @test
38define void @test() {
39entry:
40 %a.promoted2 = load i32, i32* @a, align 1
41 %c.promoted = load i32, i32* @c, align 1
42 br label %for.cond1.preheader
43
44for.cond1.preheader: ; preds = %for.cond1.for.inc4_crit_edge, %entry
45 %inc54 = phi i32 [ %inc5, %for.cond1.for.inc4_crit_edge ], [ %c.promoted, %entry ]
46 %inc.lcssa3 = phi i32 [ %inc.lcssa, %for.cond1.for.inc4_crit_edge ], [ %a.promoted2, %entry ]
47 br label %for.body3
48
49for.body3: ; preds = %for.body3, %for.cond1.preheader
50 %inc1 = phi i32 [ %inc.lcssa3, %for.cond1.preheader ], [ %inc, %for.body3 ]
51 %0 = phi i32 [ undef, %for.cond1.preheader ], [ %inc54, %for.body3 ]
52 %idxprom = sext i32 %0 to i64
53 %arrayidx = getelementptr inbounds [1 x i32], [1 x i32]* @b, i64 0, i64 %idxprom
54 store i32 4, i32* %arrayidx, align 4
55 %inc = add nsw i32 %inc1, 1
56 %tobool2 = icmp eq i32 %inc, 0
57 br i1 %tobool2, label %for.cond1.for.inc4_crit_edge, label %for.body3
58
59for.cond1.for.inc4_crit_edge: ; preds = %for.body3
60 %inc.lcssa = phi i32 [ %inc, %for.body3 ]
61 %.lcssa = phi i32 [ %inc54, %for.body3 ]
62 %inc5 = add nsw i32 %.lcssa, 1
63 br label %for.cond1.preheader
64}