1 ; RUN: opt %loadPolly -polly-stmt-granularity=bb -polly-print-scops -disable-output \
2 ; RUN: -polly-invariant-load-hoisting=true < %s | FileCheck %s
4 ; See http://research.microsoft.com/pubs/151917/divmodnote-letter.pdf
7 ; for (long i = 0; i < 10; i++) {
9 ; A[8 / -3] = A[8 % -3];
10 ; A[-8 / 3] = A[-8 % 3];
11 ; A[-8 / -3] = A[-8 % -3];
12 ; A[1 / 2] = A[1 % 2];
13 ; A[1 / -2] = A[1 % -2];
14 ; A[-1 / 2] = A[-1 % 2];
15 ; A[-1 / -2] = A[-1 % -2];
19 ; CHECK: { Stmt_for_body[i0] -> MemRef_R[2] };
20 ; CHECK: { Stmt_for_body[i0] -> MemRef_R[2] };
21 ; CHECK: { Stmt_for_body[i0] -> MemRef_R[-2] };
22 ; CHECK: { Stmt_for_body[i0] -> MemRef_R[-2] };
23 ; CHECK: { Stmt_for_body[i0] -> MemRef_R[1] };
24 ; CHECK: { Stmt_for_body[i0] -> MemRef_R[1] };
25 ; CHECK: { Stmt_for_body[i0] -> MemRef_R[-1] };
26 ; CHECK: { Stmt_for_body[i0] -> MemRef_R[-1] };
27 ; CHECK: { Stmt_for_body[i0] -> MemRef_D[2] };
28 ; CHECK: { Stmt_for_body[i0] -> MemRef_D[-2] };
29 ; CHECK: { Stmt_for_body[i0] -> MemRef_D[-2] };
30 ; CHECK: { Stmt_for_body[i0] -> MemRef_D[2] };
31 ; CHECK: { Stmt_for_body[i0] -> MemRef_D[0] };
32 ; CHECK: { Stmt_for_body[i0] -> MemRef_D[0] };
33 ; CHECK: { Stmt_for_body[i0] -> MemRef_D[0] };
34 ; CHECK: { Stmt_for_body[i0] -> MemRef_D[0] };
36 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
38 define void @f(ptr %D, ptr %R) {
42 for.cond: ; preds = %for.inc, %entry
43 %i.0 = phi i64 [ 0, %entry ], [ %inc, %for.inc ]
44 %exitcond = icmp ne i64 %i.0, 10
45 br i1 %exitcond, label %for.body, label %for.end
47 for.body: ; preds = %for.cond
49 %arrayidx = getelementptr inbounds i64, ptr %R, i64 %rem
50 %tmp = load i64, ptr %arrayidx, align 8
52 %arrayidx1 = getelementptr inbounds i64, ptr %D, i64 %div
53 store i64 %tmp, ptr %arrayidx1, align 8
54 %rem2 = srem i64 8, -3
55 %arrayidx3 = getelementptr inbounds i64, ptr %R, i64 %rem2
56 %tmp1 = load i64, ptr %arrayidx3, align 8
57 %div5 = sdiv i64 8, -3
58 %arrayidx6 = getelementptr inbounds i64, ptr %D, i64 %div5
59 store i64 %tmp1, ptr %arrayidx6, align 8
60 %rem8 = srem i64 -8, 3
61 %arrayidx9 = getelementptr inbounds i64, ptr %R, i64 %rem8
62 %tmp2 = load i64, ptr %arrayidx9, align 8
63 %div11 = sdiv i64 -8, 3
64 %arrayidx12 = getelementptr inbounds i64, ptr %D, i64 %div11
65 store i64 %tmp2, ptr %arrayidx12, align 8
66 %rem15 = srem i64 -8, -3
67 %arrayidx16 = getelementptr inbounds i64, ptr %R, i64 %rem15
68 %tmp3 = load i64, ptr %arrayidx16, align 8
69 %div19 = sdiv i64 -8, -3
70 %arrayidx20 = getelementptr inbounds i64, ptr %D, i64 %div19
71 store i64 %tmp3, ptr %arrayidx20, align 8
72 %rem29 = srem i64 1, 2
73 %arrayidx30 = getelementptr inbounds i64, ptr %R, i64 %rem29
74 %tmp5 = load i64, ptr %arrayidx30, align 8
75 %div31 = sdiv i64 1, 2
76 %arrayidx32 = getelementptr inbounds i64, ptr %D, i64 %div31
77 store i64 %tmp5, ptr %arrayidx32, align 8
78 %rem34 = srem i64 1, -2
79 %arrayidx35 = getelementptr inbounds i64, ptr %R, i64 %rem34
80 %tmp6 = load i64, ptr %arrayidx35, align 8
81 %div37 = sdiv i64 1, -2
82 %arrayidx38 = getelementptr inbounds i64, ptr %D, i64 %div37
83 store i64 %tmp6, ptr %arrayidx38, align 8
84 %rem40 = srem i64 -1, 2
85 %arrayidx41 = getelementptr inbounds i64, ptr %R, i64 %rem40
86 %tmp7 = load i64, ptr %arrayidx41, align 8
87 %div43 = sdiv i64 -1, 2
88 %arrayidx44 = getelementptr inbounds i64, ptr %D, i64 %div43
89 store i64 %tmp7, ptr %arrayidx44, align 8
90 %rem47 = srem i64 -1, -2
91 %arrayidx48 = getelementptr inbounds i64, ptr %R, i64 %rem47
92 %tmp8 = load i64, ptr %arrayidx48, align 8
93 %div51 = sdiv i64 -1, -2
94 %arrayidx52 = getelementptr inbounds i64, ptr %D, i64 %div51
95 store i64 %tmp8, ptr %arrayidx52, align 8
98 for.inc: ; preds = %for.body
99 %inc = add nuw nsw i64 %i.0, 1
102 for.end: ; preds = %for.cond