xref: /llvm-project/polly/test/DependenceInfo/nonaffine-condition-buildMemoryAccess.ll (revision e1f056f692d869708c1898d9d65a69ac5584a0ed)
1; RUN: opt %loadNPMPolly -passes=polly-codegen -polly-allow-nonaffine-loops -polly-allow-nonaffine -debug-only=polly-dependence < %s 2>&1 | FileCheck %s
2; REQUIRES: asserts
3
4; CHECK:        MayWriteAccess :=   [Reduction Type: NONE] [Scalar: 0]
5; CHECK-NEXT:       { Stmt_for_body__TO__for_inc11[i0] -> MemRef_A[o0] : 0 <= o0 <= 699 };
6; CHECK-NEXT:   MayWriteAccess :=   [Reduction Type: NONE] [Scalar: 0]
7; CHECK-NEXT:       { Stmt_for_body__TO__for_inc11[i0] -> MemRef_B[700] };
8
9; The if condition C[i] is a non-affine condition, which make the nested loop boxed. The memory access for A should be a range A[0...699]. The memory access for B should be simplified to B[700].
10;
11; int A[1000], B[1000], C[1000];
12;
13; void foo(int n, int m, int N) {
14;   for (int i = 0; i < 500; i+=1) { /* affine loop */
15;      C[i] += i;
16;      if (C[i]) { /* non-affine subregion */
17;          int j;
18;          for (j = 0; j < 700; j+=1) { /* boxed loop */
19;            A[j] = 1;
20;          }
21;          B[j] = 2;
22;      }
23;    }
24; }
25
26
27target datalayout = "e-m:e-i64:64-i128:128-n32:64-S128"
28
29@C = common global [1000 x i32] zeroinitializer, align 4
30@A = common global [1000 x i32] zeroinitializer, align 4
31@B = common global [1000 x i32] zeroinitializer, align 4
32
33; Function Attrs: norecurse nounwind
34define void @foo(i32 %n, i32 %m, i32 %N) #0 {
35entry:
36  br label %entry.split
37
38entry.split:                                      ; preds = %entry
39  br label %for.body
40
41for.cond.cleanup:                                 ; preds = %for.inc11
42  ret void
43
44for.body:                                         ; preds = %for.inc11, %entry.split
45  %indvars.iv25 = phi i64 [ 0, %entry.split ], [ %indvars.iv.next26, %for.inc11 ]
46  %arrayidx = getelementptr inbounds [1000 x i32], ptr @C, i64 0, i64 %indvars.iv25
47  %0 = load i32, ptr %arrayidx, align 4
48  %1 = trunc i64 %indvars.iv25 to i32
49  %add = add nsw i32 %0, %1
50  store i32 %add, ptr %arrayidx, align 4
51  %tobool = icmp eq i32 %add, 0
52  br i1 %tobool, label %for.inc11, label %for.body5.preheader
53
54for.body5.preheader:                              ; preds = %for.body
55  br label %for.body5
56
57for.body5:                                        ; preds = %for.body5.preheader, %for.body5
58  %indvars.iv = phi i64 [ %indvars.iv.next, %for.body5 ], [ 0, %for.body5.preheader ]
59  %arrayidx7 = getelementptr inbounds [1000 x i32], ptr @A, i64 0, i64 %indvars.iv
60  store i32 1, ptr %arrayidx7, align 4
61  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
62  %exitcond = icmp eq i64 %indvars.iv, 699
63  br i1 %exitcond, label %for.end, label %for.body5
64
65for.end:                                          ; preds = %for.body5
66  store i32 2, ptr getelementptr inbounds ([1000 x i32], ptr @B, i64 0, i64 700), align 4
67  br label %for.inc11
68
69for.inc11:                                        ; preds = %for.body, %for.end
70  %indvars.iv.next26 = add nuw nsw i64 %indvars.iv25, 1
71  %exitcond27 = icmp eq i64 %indvars.iv25, 499
72  br i1 %exitcond27, label %for.cond.cleanup, label %for.body
73}
74
75