1; RUN: opt %loadPolly -polly-scops -analyze < %s | FileCheck %s
2; RUN: opt %loadPolly -polly-ast -analyze < %s | FileCheck %s --check-prefix=AST
3;
4;    void f(int *A, int N) {
5;      for (int i = 0; i < N; i++)
6;        switch (i % 4) {
7;        case 0:
8;          A[i] += 1;
9;          break;
10;        case 1:
11;          break;
12;        case 2:
13;          A[i] += 2;
14;          break;
15;        case 3:
16;          break;
17;        }
18;    }
19
20; CHECK:      Statements {
21; CHECK-NEXT:     Stmt_sw_bb
22; CHECK-NEXT:         Domain :=
23; CHECK-NEXT:             [N] -> { Stmt_sw_bb[i0] : (i0) mod 4 = 0 and 0 <= i0 < N };
24; CHECK-NEXT:         Schedule :=
25; CHECK-NEXT:             [N] -> { Stmt_sw_bb[i0] -> [i0, 1] };
26; CHECK-NEXT:         ReadAccess :=    [Reduction Type: +] [Scalar: 0]
27; CHECK-NEXT:             [N] -> { Stmt_sw_bb[i0] -> MemRef_A[i0] };
28; CHECK-NEXT:         MustWriteAccess :=    [Reduction Type: +] [Scalar: 0]
29; CHECK-NEXT:             [N] -> { Stmt_sw_bb[i0] -> MemRef_A[i0] };
30; CHECK-NEXT:     Stmt_sw_bb_2
31; CHECK-NEXT:         Domain :=
32; CHECK-NEXT:             [N] -> { Stmt_sw_bb_2[i0] : (2 + i0) mod 4 = 0 and 2 <= i0 < N };
33; CHECK-NEXT:         Schedule :=
34; CHECK-NEXT:             [N] -> { Stmt_sw_bb_2[i0] -> [i0, 0] };
35; CHECK-NEXT:         ReadAccess :=    [Reduction Type: +] [Scalar: 0]
36; CHECK-NEXT:             [N] -> { Stmt_sw_bb_2[i0] -> MemRef_A[i0] };
37; CHECK-NEXT:         MustWriteAccess :=    [Reduction Type: +] [Scalar: 0]
38; CHECK-NEXT:             [N] -> { Stmt_sw_bb_2[i0] -> MemRef_A[i0] };
39; CHECK-NEXT: }
40
41; AST:      if (1)
42;
43; AST:         for (int c0 = 0; c0 < N; c0 += 4) {
44; AST-NEXT:      Stmt_sw_bb(c0);
45; AST-NEXT:      if (N >= c0 + 3)
46; AST-NEXT:        Stmt_sw_bb_2(c0 + 2);
47; AST-NEXT:    }
48;
49; AST:      else
50; AST-NEXT:     {  /* original code */ }
51
52target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
53
54define void @f(i32* %A, i32 %N) {
55entry:
56  %tmp = sext i32 %N to i64
57  br label %for.cond
58
59for.cond:                                         ; preds = %for.inc, %entry
60  %indvars.iv = phi i64 [ %indvars.iv.next, %for.inc ], [ 0, %entry ]
61  %cmp = icmp slt i64 %indvars.iv, %tmp
62  br i1 %cmp, label %for.body, label %for.end
63
64for.body:                                         ; preds = %for.cond
65  %tmp1 = trunc i64 %indvars.iv to i32
66  %rem = srem i32 %tmp1, 4
67  switch i32 %rem, label %sw.epilog [
68    i32 0, label %sw.bb
69    i32 1, label %sw.bb.1
70    i32 2, label %sw.bb.2
71    i32 3, label %sw.bb.6
72  ]
73
74sw.bb:                                            ; preds = %for.body
75  %arrayidx = getelementptr inbounds i32, i32* %A, i64 %indvars.iv
76  %tmp2 = load i32, i32* %arrayidx, align 4
77  %add = add nsw i32 %tmp2, 1
78  store i32 %add, i32* %arrayidx, align 4
79  br label %sw.epilog
80
81sw.bb.1:                                          ; preds = %for.body
82  br label %sw.epilog
83
84sw.bb.2:                                          ; preds = %for.body
85  %arrayidx4 = getelementptr inbounds i32, i32* %A, i64 %indvars.iv
86  %tmp3 = load i32, i32* %arrayidx4, align 4
87  %add5 = add nsw i32 %tmp3, 2
88  store i32 %add5, i32* %arrayidx4, align 4
89  br label %sw.epilog
90
91sw.bb.6:                                          ; preds = %for.body
92  br label %sw.epilog
93
94sw.epilog:                                        ; preds = %sw.bb.6, %sw.bb.2, %sw.bb.1, %sw.bb, %for.body
95  br label %for.inc
96
97for.inc:                                          ; preds = %sw.epilog
98  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
99  br label %for.cond
100
101for.end:                                          ; preds = %for.cond
102  ret void
103}
104