Michael Kuperstein | ee31cbe | 2017-01-10 19:32:30 +0000 | [diff] [blame] | 1 | ; 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 | |
Michael Kuperstein | ee31cbe | 2017-01-10 19:32:30 +0000 | [diff] [blame] | 12 | ; Code that leads to this situation can look something like: |
| 13 | ; |
| 14 | ; int a, b[1], c; |
| 15 | ; void fn1 () |
| 16 | ; { |
| 17 | ; for (; c; c++) |
| 18 | ; for (a = 0; a; a++) |
| 19 | ; b[c] = 4; |
| 20 | ; } |
| 21 | ; |
| 22 | ; The PHI is an artifact of the register promotion of c. |
| 23 | |
Michael Kuperstein | 230867e | 2017-01-19 00:42:28 +0000 | [diff] [blame] | 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. |
| 27 | |
Michael Kuperstein | ee31cbe | 2017-01-10 19:32:30 +0000 | [diff] [blame] | 28 | @c = external global i32, align 4 |
| 29 | @a = external global i32, align 4 |
| 30 | @b = external global [1 x i32], align 4 |
| 31 | |
Michael Kuperstein | ee31cbe | 2017-01-10 19:32:30 +0000 | [diff] [blame] | 32 | ; CHECK: LV: Not vectorizing: Cannot prove legality. |
| 33 | ; CHECK-LABEL: @test |
| 34 | define void @test() { |
| 35 | entry: |
| 36 | %a.promoted2 = load i32, i32* @a, align 1 |
| 37 | %c.promoted = load i32, i32* @c, align 1 |
| 38 | br label %for.cond1.preheader |
| 39 | |
| 40 | for.cond1.preheader: ; preds = %for.cond1.for.inc4_crit_edge, %entry |
| 41 | %inc54 = phi i32 [ %inc5, %for.cond1.for.inc4_crit_edge ], [ %c.promoted, %entry ] |
| 42 | %inc.lcssa3 = phi i32 [ %inc.lcssa, %for.cond1.for.inc4_crit_edge ], [ %a.promoted2, %entry ] |
| 43 | br label %for.body3 |
| 44 | |
| 45 | for.body3: ; preds = %for.body3, %for.cond1.preheader |
| 46 | %inc1 = phi i32 [ %inc.lcssa3, %for.cond1.preheader ], [ %inc, %for.body3 ] |
| 47 | %0 = phi i32 [ undef, %for.cond1.preheader ], [ %inc54, %for.body3 ] |
| 48 | %idxprom = sext i32 %0 to i64 |
| 49 | %arrayidx = getelementptr inbounds [1 x i32], [1 x i32]* @b, i64 0, i64 %idxprom |
| 50 | store i32 4, i32* %arrayidx, align 4 |
| 51 | %inc = add nsw i32 %inc1, 1 |
| 52 | %tobool2 = icmp eq i32 %inc, 0 |
| 53 | br i1 %tobool2, label %for.cond1.for.inc4_crit_edge, label %for.body3 |
| 54 | |
| 55 | for.cond1.for.inc4_crit_edge: ; preds = %for.body3 |
| 56 | %inc.lcssa = phi i32 [ %inc, %for.body3 ] |
| 57 | %.lcssa = phi i32 [ %inc54, %for.body3 ] |
| 58 | %inc5 = add nsw i32 %.lcssa, 1 |
| 59 | br label %for.cond1.preheader |
| 60 | } |