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; The SCoP contains a loop with multiple exit blocks (BBs after leaving
5; the loop). The current implementation of deriving their domain derives
6; only a common domain for all of the exit blocks. We disabled loops with
7; multiple exit blocks until this is fixed.
8; XFAIL: *
9;
10;    void f(int *A, int *B, int N) {
11;      for (int i = 0; i < N; i++) {
12;        A[i]++;
13;        switch (N) {
14;        case 0:
15;          B[i]++;
16;          break;
17;        default:
18;          return;
19;        }
20;      }
21;    }
22
23; CHECK:      Statements {
24; CHECK-NEXT:     Stmt_for_body
25; CHECK-NEXT:         Domain :=
26; CHECK-NEXT:             [N] -> { Stmt_for_body[0] : N > 0 };
27; CHECK-NEXT:         Schedule :=
28; CHECK-NEXT:             [N] -> { Stmt_for_body[i0] -> [0] };
29; CHECK-NEXT:         ReadAccess :=    [Reduction Type: +] [Scalar: 0]
30; CHECK-NEXT:             [N] -> { Stmt_for_body[i0] -> MemRef_A[0] };
31; CHECK-NEXT:         MustWriteAccess :=    [Reduction Type: +] [Scalar: 0]
32; CHECK-NEXT:             [N] -> { Stmt_for_body[i0] -> MemRef_A[0] };
33; CHECK-NEXT: }
34
35; AST:      if (1)
36;
37; AST:          if (N >= 1)
38; AST-NEXT:       Stmt_for_body(0);
39;
40; AST:      else
41; AST-NEXT:     {  /* original code */ }
42
43target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
44
45define void @f(i32* %A, i32* %B, i32 %N) {
46entry:
47  %tmp = sext i32 %N to i64
48  br label %for.cond
49
50for.cond:                                         ; preds = %for.inc, %entry
51  %indvars.iv = phi i64 [ %indvars.iv.next, %for.inc ], [ 0, %entry ]
52  %cmp = icmp slt i64 %indvars.iv, %tmp
53  br i1 %cmp, label %for.body, label %for.end.loopexit
54
55for.body:                                         ; preds = %for.cond
56  %arrayidx = getelementptr inbounds i32, i32* %A, i64 %indvars.iv
57  %tmp1 = load i32, i32* %arrayidx, align 4
58  %inc = add nsw i32 %tmp1, 1
59  store i32 %inc, i32* %arrayidx, align 4
60  switch i32 %N, label %sw.default [
61    i32 0, label %sw.bb
62  ]
63
64sw.bb:                                            ; preds = %for.body
65  %arrayidx2 = getelementptr inbounds i32, i32* %B, i64 %indvars.iv
66  %tmp2 = load i32, i32* %arrayidx2, align 4
67  %inc3 = add nsw i32 %tmp2, 1
68  store i32 %inc3, i32* %arrayidx2, align 4
69  br label %sw.epilog
70
71sw.default:                                       ; preds = %for.body
72  br label %for.end
73
74sw.epilog:                                        ; preds = %sw.bb
75  br label %for.inc
76
77for.inc:                                          ; preds = %sw.epilog
78  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
79  br label %for.cond
80
81for.end.loopexit:                                 ; preds = %for.cond
82  br label %for.end
83
84for.end:                                          ; preds = %for.end.loopexit, %sw.default
85  ret void
86}
87