1; RUN: opt %loadPolly -polly-scops -analyze < %s | FileCheck %s
2;
3; We should not generate runtime check for ((int)r1 + (int)r2) as it is known not
4; to overflow. However (p + q) can, thus checks are needed.
5;
6; CHECK:      Invalid Context:
7; CHECK-NEXT:   [r1, r2, q, p] -> { : r2 > r1 and (p <= -2147483649 - q or r2 >= 128 + r1 or p >= 2147483648 - q) }
8;
9;    void wraps(int *A, int p, short q, char r1, char r2) {
10;      for (char i = r1; i < r2; i++)
11;        A[p + q] = A[(int)r1 + (int)r2];
12;    }
13;
14target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
15
16define void @wraps(i32* %A, i32 %p, i16 signext %q, i8 signext %r1, i8 signext %r2) {
17entry:
18  br label %for.cond
19
20for.cond:                                         ; preds = %for.inc, %entry
21  %i.0 = phi i8 [ %r1, %entry ], [ %inc, %for.inc ]
22  %cmp = icmp slt i8 %i.0, %r2
23  br i1 %cmp, label %for.body, label %for.end
24
25for.body:                                         ; preds = %for.cond
26  %conv3 = sext i8 %r1 to i64
27  %conv4 = sext i8 %r2 to i64
28  %add = add nsw i64 %conv3, %conv4
29  %arrayidx = getelementptr inbounds i32, i32* %A, i64 %add
30  %tmp = load i32, i32* %arrayidx, align 4
31  %conv5 = sext i16 %q to i32
32  %add6 = add nsw i32 %conv5, %p
33  %idxprom7 = sext i32 %add6 to i64
34  %arrayidx8 = getelementptr inbounds i32, i32* %A, i64 %idxprom7
35  store i32 %tmp, i32* %arrayidx8, align 4
36  br label %for.inc
37
38for.inc:                                          ; preds = %for.body
39  %inc = add i8 %i.0, 1
40  br label %for.cond
41
42for.end:                                          ; preds = %for.cond
43  ret void
44}
45