[Polly][PATCH 8/8] [RTC] Annotate the IslAst with runtime alias checks.

Johannes Doerfert doerfert at cs.uni-saarland.de
Sun Aug 10 00:50:29 PDT 2014


  This check will also generate the code for runtime alias checks, thus
  make -polly-use-runtime-alias-checks=true save for the isl code
  generator.
---
 lib/CodeGen/IslAst.cpp                           | 24 ++++++++++
 test/Isl/Ast/alias_simple_1.ll                   | 58 +++++++++++++++++++++++
 test/Isl/Ast/alias_simple_2.ll                   | 58 +++++++++++++++++++++++
 test/Isl/Ast/alias_simple_3.ll                   | 59 ++++++++++++++++++++++++
 test/Isl/Ast/aliasing_multiple_alias_groups.ll   | 54 ++++++++++++++++++++++
 test/Isl/Ast/aliasing_parametric_simple_1.ll     | 39 ++++++++++++++++
 test/Isl/Ast/aliasing_parametric_simple_2.ll     | 43 +++++++++++++++++
 test/Isl/CodeGen/aliasing_parametric_simple_1.ll | 43 +++++++++++++++++
 test/Isl/CodeGen/aliasing_parametric_simple_2.ll | 57 +++++++++++++++++++++++
 9 files changed, 435 insertions(+)
 create mode 100644 test/Isl/Ast/alias_simple_1.ll
 create mode 100644 test/Isl/Ast/alias_simple_2.ll
 create mode 100644 test/Isl/Ast/alias_simple_3.ll
 create mode 100644 test/Isl/Ast/aliasing_multiple_alias_groups.ll
 create mode 100644 test/Isl/Ast/aliasing_parametric_simple_1.ll
 create mode 100644 test/Isl/Ast/aliasing_parametric_simple_2.ll
 create mode 100644 test/Isl/CodeGen/aliasing_parametric_simple_1.ll
 create mode 100644 test/Isl/CodeGen/aliasing_parametric_simple_2.ll

diff --git a/lib/CodeGen/IslAst.cpp b/lib/CodeGen/IslAst.cpp
index 500e219..d326c94 100644
--- a/lib/CodeGen/IslAst.cpp
+++ b/lib/CodeGen/IslAst.cpp
@@ -299,6 +299,30 @@ void IslAst::buildRunCondition(__isl_keep isl_ast_build *Build) {
   RunCondition = isl_ast_build_expr_from_pw_aff(Build, Cond);
   RunCondition = isl_ast_expr_eq(RunCondition,
                                  isl_ast_build_expr_from_pw_aff(Build, PwOne));
+
+  // Create the alias checks from the minimal/maximal accesses in each alias
+  // groups. This operation is by construction quadratic in the number of
+  // elements in each alias group.
+  isl_ast_expr *NonAliasGroup, *MinExpr, *MaxExpr;
+  for (const Scop::MinMaxVectorTy *MinMaxAccesses : S->getAliasGroups()) {
+    auto AccEnd = MinMaxAccesses->end();
+    for (auto AccIt0 = MinMaxAccesses->begin(); AccIt0 != AccEnd; ++AccIt0) {
+      for (auto AccIt1 = AccIt0 + 1; AccIt1 != AccEnd; ++AccIt1) {
+        MinExpr = isl_ast_expr_addr_of(isl_ast_build_access_from_pw_multi_aff(
+            Build, isl_pw_multi_aff_copy(AccIt0->first)));
+        MaxExpr = isl_ast_expr_addr_of(isl_ast_build_access_from_pw_multi_aff(
+            Build, isl_pw_multi_aff_copy(AccIt1->second)));
+        NonAliasGroup = isl_ast_expr_lt(MaxExpr, MinExpr);
+        MinExpr = isl_ast_expr_addr_of(isl_ast_build_access_from_pw_multi_aff(
+            Build, isl_pw_multi_aff_copy(AccIt1->first)));
+        MaxExpr = isl_ast_expr_addr_of(isl_ast_build_access_from_pw_multi_aff(
+            Build, isl_pw_multi_aff_copy(AccIt0->second)));
+        NonAliasGroup =
+            isl_ast_expr_or(NonAliasGroup, isl_ast_expr_lt(MaxExpr, MinExpr));
+        RunCondition = isl_ast_expr_and(RunCondition, NonAliasGroup);
+      }
+    }
+  }
 }
 
 IslAst::IslAst(Scop *Scop, Dependences &D) : S(Scop) {
diff --git a/test/Isl/Ast/alias_simple_1.ll b/test/Isl/Ast/alias_simple_1.ll
new file mode 100644
index 0000000..7cbd5e3
--- /dev/null
+++ b/test/Isl/Ast/alias_simple_1.ll
@@ -0,0 +1,58 @@
+; RUN: opt %loadPolly -polly-use-runtime-alias-checks -polly-ast -analyze < %s | FileCheck %s --check-prefix=NOAA
+; RUN: opt %loadPolly -polly-use-runtime-alias-checks -polly-ast -analyze -basicaa < %s | FileCheck %s --check-prefix=BASI
+; RUN: opt %loadPolly -polly-use-runtime-alias-checks -polly-ast -analyze -tbaa < %s | FileCheck %s --check-prefix=TBAA
+; RUN: opt %loadPolly -polly-use-runtime-alias-checks -polly-ast -analyze -scev-aa < %s | FileCheck %s --check-prefix=SCEV
+; RUN: opt %loadPolly -polly-use-runtime-alias-checks -polly-ast -analyze -globalsmodref-aa < %s | FileCheck %s --check-prefix=GLOB
+;
+;    int A[1024];
+;
+;
+;    void jd(float *B, int N) {
+;      for (int i = 0; i < N; i++)
+;        A[i] = B[i];
+;    }
+;
+; NOAA: if (1 == 1 && (&MemRef_A[N - 1] < &MemRef_B[0] || &MemRef_B[N - 1] < &MemRef_A[0]))
+; BASI: if (1 == 1 && (&MemRef_A[N - 1] < &MemRef_B[0] || &MemRef_B[N - 1] < &MemRef_A[0]))
+; TBAA: if (1 == 1)
+; SCEV: if (1 == 1 && (&MemRef_A[N - 1] < &MemRef_B[0] || &MemRef_B[N - 1] < &MemRef_A[0]))
+; GLOB: if (1 == 1 && (&MemRef_A[N - 1] < &MemRef_B[0] || &MemRef_B[N - 1] < &MemRef_A[0]))
+;
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+
+ at A = common global [1024 x i32] zeroinitializer, align 16
+
+define void @jd(float* nocapture readonly %B, i32 %N) {
+entry:
+  %cmp6 = icmp sgt i32 %N, 0
+  br i1 %cmp6, label %for.body.preheader, label %for.end
+
+for.body.preheader:                               ; preds = %entry
+  br label %for.body
+
+for.body:                                         ; preds = %for.body.preheader, %for.body
+  %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %for.body.preheader ]
+  %arrayidx = getelementptr inbounds float* %B, i64 %indvars.iv
+  %tmp = load float* %arrayidx, align 4, !tbaa !1
+  %conv = fptosi float %tmp to i32
+  %arrayidx2 = getelementptr inbounds [1024 x i32]* @A, i64 0, i64 %indvars.iv
+  store i32 %conv, i32* %arrayidx2, align 4, !tbaa !5
+  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
+  %lftr.wideiv1 = trunc i64 %indvars.iv.next to i32
+  %exitcond2 = icmp eq i32 %lftr.wideiv1, %N
+  br i1 %exitcond2, label %for.end.loopexit, label %for.body
+
+for.end.loopexit:                                 ; preds = %for.body
+  br label %for.end
+
+for.end:                                          ; preds = %for.end.loopexit, %entry
+  ret void
+}
+
+!0 = metadata !{metadata !""}
+!1 = metadata !{metadata !2, metadata !2, i64 0}
+!2 = metadata !{metadata !"float", metadata !3, i64 0}
+!3 = metadata !{metadata !"omnipotent char", metadata !4, i64 0}
+!4 = metadata !{metadata !"Simple C/C++ TBAA"}
+!5 = metadata !{metadata !6, metadata !6, i64 0}
+!6 = metadata !{metadata !"int", metadata !3, i64 0}
diff --git a/test/Isl/Ast/alias_simple_2.ll b/test/Isl/Ast/alias_simple_2.ll
new file mode 100644
index 0000000..59097b2
--- /dev/null
+++ b/test/Isl/Ast/alias_simple_2.ll
@@ -0,0 +1,58 @@
+; RUN: opt %loadPolly -polly-use-runtime-alias-checks -polly-ast -analyze < %s | FileCheck %s --check-prefix=NOAA
+; RUN: opt %loadPolly -polly-use-runtime-alias-checks -polly-ast -analyze -basicaa < %s | FileCheck %s --check-prefix=BASI
+; RUN: opt %loadPolly -polly-use-runtime-alias-checks -polly-ast -analyze -tbaa < %s | FileCheck %s --check-prefix=TBAA
+; RUN: opt %loadPolly -polly-use-runtime-alias-checks -polly-ast -analyze -scev-aa < %s | FileCheck %s --check-prefix=SCEV
+; RUN: opt %loadPolly -polly-use-runtime-alias-checks -polly-ast -analyze -globalsmodref-aa < %s | FileCheck %s --check-prefix=GLOB
+;
+;    int A[1024], B[1024];
+;
+;
+;    void jd(int N) {
+;      for (int i = 0; i < N; i++)
+;        A[i] = B[i];
+;    }
+;
+; NOAA: if (1 == 1 && (&MemRef_A[N - 1] < &MemRef_B[0] || &MemRef_B[N - 1] < &MemRef_A[0]))
+; BASI: if (1 == 1)
+; TBAA: if (1 == 1 && (&MemRef_A[N - 1] < &MemRef_B[0] || &MemRef_B[N - 1] < &MemRef_A[0]))
+; SCEV: if (1 == 1 && (&MemRef_A[N - 1] < &MemRef_B[0] || &MemRef_B[N - 1] < &MemRef_A[0]))
+; GLOB: if (1 == 1 && (&MemRef_A[N - 1] < &MemRef_B[0] || &MemRef_B[N - 1] < &MemRef_A[0]))
+;
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+
+ at A = common global [1024 x i32] zeroinitializer, align 16
+ at B = common global [1024 x i32] zeroinitializer, align 16
+
+define void @jd(i32 %N) {
+entry:
+  %cmp6 = icmp sgt i32 %N, 0
+  br i1 %cmp6, label %for.body.preheader, label %for.end
+
+for.body.preheader:                               ; preds = %entry
+  br label %for.body
+
+for.body:                                         ; preds = %for.body.preheader, %for.body
+  %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %for.body.preheader ]
+  %arrayidx = getelementptr inbounds  [1024 x i32]* @B, i64 0, i64 %indvars.iv
+  %tmp = load i32* %arrayidx, align 4, !tbaa !5
+  %arrayidx2 = getelementptr inbounds [1024 x i32]* @A, i64 0, i64 %indvars.iv
+  store i32 %tmp, i32* %arrayidx2, align 4, !tbaa !5
+  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
+  %lftr.wideiv1 = trunc i64 %indvars.iv.next to i32
+  %exitcond2 = icmp eq i32 %lftr.wideiv1, %N
+  br i1 %exitcond2, label %for.end.loopexit, label %for.body
+
+for.end.loopexit:                                 ; preds = %for.body
+  br label %for.end
+
+for.end:                                          ; preds = %for.end.loopexit, %entry
+  ret void
+}
+
+!0 = metadata !{metadata !""}
+!1 = metadata !{metadata !2, metadata !2, i64 0}
+!2 = metadata !{metadata !"float", metadata !3, i64 0}
+!3 = metadata !{metadata !"omnipotent char", metadata !4, i64 0}
+!4 = metadata !{metadata !"Simple C/C++ TBAA"}
+!5 = metadata !{metadata !6, metadata !6, i64 0}
+!6 = metadata !{metadata !"int", metadata !3, i64 0}
diff --git a/test/Isl/Ast/alias_simple_3.ll b/test/Isl/Ast/alias_simple_3.ll
new file mode 100644
index 0000000..c34e779
--- /dev/null
+++ b/test/Isl/Ast/alias_simple_3.ll
@@ -0,0 +1,59 @@
+; RUN: opt %loadPolly -polly-use-runtime-alias-checks -polly-ast -analyze < %s | FileCheck %s --check-prefix=NOAA
+; RUN: opt %loadPolly -polly-use-runtime-alias-checks -polly-ast -analyze -basicaa < %s | FileCheck %s --check-prefix=BASI
+; RUN: opt %loadPolly -polly-use-runtime-alias-checks -polly-ast -analyze -tbaa < %s | FileCheck %s --check-prefix=TBAA
+; RUN: opt %loadPolly -polly-use-runtime-alias-checks -polly-ast -analyze -scev-aa < %s | FileCheck %s --check-prefix=SCEV
+; RUN: opt %loadPolly -polly-use-runtime-alias-checks -polly-ast -analyze -globalsmodref-aa < %s | FileCheck %s --check-prefix=GLOB
+;
+;    int A[1024];
+;    float B[1024];
+;
+;    void jd(int N) {
+;      for (int i = 0; i < N; i++)
+;        A[i] = B[i];
+;    }
+;
+; NOAA: if (1 == 1 && (&MemRef_A[N - 1] < &MemRef_B[0] || &MemRef_B[N - 1] < &MemRef_A[0]))
+; BASI: if (1 == 1)
+; TBAA: if (1 == 1)
+; SCEV: if (1 == 1 && (&MemRef_A[N - 1] < &MemRef_B[0] || &MemRef_B[N - 1] < &MemRef_A[0]))
+; GLOB: if (1 == 1 && (&MemRef_A[N - 1] < &MemRef_B[0] || &MemRef_B[N - 1] < &MemRef_A[0]))
+;
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+
+ at A = common global [1024 x i32] zeroinitializer, align 16
+ at B = common global [1024 x float] zeroinitializer, align 16
+
+define void @jd(i32 %N) {
+entry:
+  %cmp6 = icmp sgt i32 %N, 0
+  br i1 %cmp6, label %for.body.preheader, label %for.end
+
+for.body.preheader:                               ; preds = %entry
+  br label %for.body
+
+for.body:                                         ; preds = %for.body.preheader, %for.body
+  %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %for.body.preheader ]
+  %arrayidx = getelementptr inbounds  [1024 x float]* @B, i64 0, i64 %indvars.iv
+  %tmp = load float* %arrayidx, align 4, !tbaa !1
+  %conv = fptosi float %tmp to i32
+  %arrayidx2 = getelementptr inbounds [1024 x i32]* @A, i64 0, i64 %indvars.iv
+  store i32 %conv, i32* %arrayidx2, align 4, !tbaa !5
+  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
+  %lftr.wideiv1 = trunc i64 %indvars.iv.next to i32
+  %exitcond2 = icmp eq i32 %lftr.wideiv1, %N
+  br i1 %exitcond2, label %for.end.loopexit, label %for.body
+
+for.end.loopexit:                                 ; preds = %for.body
+  br label %for.end
+
+for.end:                                          ; preds = %for.end.loopexit, %entry
+  ret void
+}
+
+!0 = metadata !{metadata !""}
+!1 = metadata !{metadata !2, metadata !2, i64 0}
+!2 = metadata !{metadata !"float", metadata !3, i64 0}
+!3 = metadata !{metadata !"omnipotent char", metadata !4, i64 0}
+!4 = metadata !{metadata !"Simple C/C++ TBAA"}
+!5 = metadata !{metadata !6, metadata !6, i64 0}
+!6 = metadata !{metadata !"int", metadata !3, i64 0}
diff --git a/test/Isl/Ast/aliasing_multiple_alias_groups.ll b/test/Isl/Ast/aliasing_multiple_alias_groups.ll
new file mode 100644
index 0000000..a80ae8f
--- /dev/null
+++ b/test/Isl/Ast/aliasing_multiple_alias_groups.ll
@@ -0,0 +1,54 @@
+; RUN: opt %loadPolly -polly-use-runtime-alias-checks=true -polly-ast -analyze          < %s | FileCheck %s --check-prefix=NOAA
+; RUN: opt %loadPolly -polly-use-runtime-alias-checks=true -polly-ast -analyze -tbaa    < %s | FileCheck %s --check-prefix=TBAA
+;
+;    void jd(int *Int0, int *Int1, float *Float0, float *Float1) {
+;      for (int i = 0; i < 1024; i++) {
+;        Int0[i] = Int1[i];
+;        Float0[i] = Float1[i];
+;      }
+;    }
+;
+; NOAA:      if (1 == 1 && (
+; NOAA-DAG:    &MemRef_Float0[1023] < &MemRef_Int0[0] || &MemRef_Int0[1023] < &MemRef_Float0[0]
+; NOAA-DAG:    &MemRef_Float1[1023] < &MemRef_Int0[0] || &MemRef_Int0[1023] < &MemRef_Float1[0]
+; NOAA-DAG:    &MemRef_Int1[1023] < &MemRef_Int0[0] || &MemRef_Int0[1023] < &MemRef_Int1[0]
+; NOAA-DAG:    &MemRef_Float1[1023] < &MemRef_Float0[0] || &MemRef_Float0[1023] < &MemRef_Float1[0]
+; NOAA-DAG:    &MemRef_Int1[1023] < &MemRef_Float0[0] || &MemRef_Float0[1023] < &MemRef_Int1[0]
+; NOAA-DAG:    &MemRef_Int1[1023] < &MemRef_Float1[0] || &MemRef_Float1[1023] < &MemRef_Int1[0]
+; NOAA:      ))
+;
+; TBAA:      if (1 == 1 && (
+; TBAA-DAG:    &MemRef_Int0[1023] < &MemRef_Int1[0] || &MemRef_Int1[1023] < &MemRef_Int0[0]
+; TBAA-DAG:    &MemRef_Float1[1023] < &MemRef_Float0[0] || &MemRef_Float0[1023] < &MemRef_Float1[0]
+; TBAA:      ))
+;
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+
+define void @jd(i32* nocapture %Int0, i32* nocapture readonly %Int1, float* nocapture %Float0, float* nocapture readonly %Float1) {
+entry:
+  br label %for.body
+
+for.body:                                         ; preds = %for.body, %entry
+  %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
+  %arrayidx = getelementptr inbounds i32* %Int1, i64 %indvars.iv
+  %tmp = load i32* %arrayidx, align 4, !tbaa !0
+  %arrayidx2 = getelementptr inbounds i32* %Int0, i64 %indvars.iv
+  store i32 %tmp, i32* %arrayidx2, align 4, !tbaa !0
+  %arrayidx4 = getelementptr inbounds float* %Float1, i64 %indvars.iv
+  %tmp1 = load float* %arrayidx4, align 4, !tbaa !4
+  %arrayidx6 = getelementptr inbounds float* %Float0, i64 %indvars.iv
+  store float %tmp1, float* %arrayidx6, align 4, !tbaa !4
+  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
+  %exitcond = icmp eq i64 %indvars.iv.next, 1024
+  br i1 %exitcond, label %for.end, label %for.body
+
+for.end:                                          ; preds = %for.body
+  ret void
+}
+
+!0 = metadata !{metadata !1, metadata !1, i64 0}
+!1 = metadata !{metadata !"int", metadata !2, i64 0}
+!2 = metadata !{metadata !"omnipotent char", metadata !3, i64 0}
+!3 = metadata !{metadata !"Simple C/C++ TBAA"}
+!4 = metadata !{metadata !5, metadata !5, i64 0}
+!5 = metadata !{metadata !"float", metadata !2, i64 0}
diff --git a/test/Isl/Ast/aliasing_parametric_simple_1.ll b/test/Isl/Ast/aliasing_parametric_simple_1.ll
new file mode 100644
index 0000000..09413af
--- /dev/null
+++ b/test/Isl/Ast/aliasing_parametric_simple_1.ll
@@ -0,0 +1,39 @@
+; RUN: opt %loadPolly -polly-use-runtime-alias-checks -polly-ast -analyze %s | FileCheck %s
+;
+;    void jd(int *A, int *B, int c) {
+;      for (int i = 0; i < 1024; i++)
+;        A[i] = B[c];
+;    }
+;
+; CHECK: if (1 == 1 && (&MemRef_A[1023] < &MemRef_B[c] || &MemRef_B[c] < &MemRef_A[0]))
+; CHECK:     for (int c1 = 0; c1 <= 1023; c1 += 1)
+; CHECK:       Stmt_for_body(c1);
+; CHECK: else
+; CHECK:     /* original code */
+;
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+
+define void @jd(i32* %A, i32* %B, i32 %c) {
+entry:
+  br label %for.cond
+
+for.cond:                                         ; preds = %for.inc, %entry
+  %indvars.iv = phi i64 [ %indvars.iv.next, %for.inc ], [ 0, %entry ]
+  %exitcond = icmp ne i64 %indvars.iv, 1024
+  br i1 %exitcond, label %for.body, label %for.end
+
+for.body:                                         ; preds = %for.cond
+  %idxprom = sext i32 %c to i64
+  %arrayidx = getelementptr inbounds i32* %B, i64 %idxprom
+  %tmp = load i32* %arrayidx, align 4
+  %arrayidx2 = getelementptr inbounds i32* %A, i64 %indvars.iv
+  store i32 %tmp, i32* %arrayidx2, align 4
+  br label %for.inc
+
+for.inc:                                          ; preds = %for.body
+  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
+  br label %for.cond
+
+for.end:                                          ; preds = %for.cond
+  ret void
+}
diff --git a/test/Isl/Ast/aliasing_parametric_simple_2.ll b/test/Isl/Ast/aliasing_parametric_simple_2.ll
new file mode 100644
index 0000000..4b9c889
--- /dev/null
+++ b/test/Isl/Ast/aliasing_parametric_simple_2.ll
@@ -0,0 +1,43 @@
+; RUN: opt %loadPolly -polly-use-runtime-alias-checks -polly-ast -analyze < %s | FileCheck %s
+;
+;    void jd(int *A, int *B, int c) {
+;      for (int i = 0; i < 1024; i++)
+;        A[i] = B[c - 10] + B[5];
+;    }
+;
+; CHECK: if (1 == 1 && (&MemRef_A[1023] < &MemRef_B[c >= 15 ? 5 : c - 10] || &MemRef_B[c <= 15 ? 5 : c - 10] < &MemRef_A[0]))
+; CHECK:     for (int c1 = 0; c1 <= 1023; c1 += 1)
+; CHECK:       Stmt_for_body(c1);
+; CHECK: else
+; CHECK:    /* original code */
+;
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+
+define void @jd(i32* %A, i32* %B, i32 %c) {
+entry:
+  br label %for.cond
+
+for.cond:                                         ; preds = %for.inc, %entry
+  %indvars.iv = phi i64 [ %indvars.iv.next, %for.inc ], [ 0, %entry ]
+  %exitcond = icmp ne i64 %indvars.iv, 1024
+  br i1 %exitcond, label %for.body, label %for.end
+
+for.body:                                         ; preds = %for.cond
+  %sub = add nsw i32 %c, -10
+  %idxprom = sext i32 %sub to i64
+  %arrayidx = getelementptr inbounds i32* %B, i64 %idxprom
+  %tmp = load i32* %arrayidx, align 4
+  %arrayidx1 = getelementptr inbounds i32* %B, i64 5
+  %tmp1 = load i32* %arrayidx1, align 4
+  %add = add nsw i32 %tmp, %tmp1
+  %arrayidx3 = getelementptr inbounds i32* %A, i64 %indvars.iv
+  store i32 %add, i32* %arrayidx3, align 4
+  br label %for.inc
+
+for.inc:                                          ; preds = %for.body
+  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
+  br label %for.cond
+
+for.end:                                          ; preds = %for.cond
+  ret void
+}
diff --git a/test/Isl/CodeGen/aliasing_parametric_simple_1.ll b/test/Isl/CodeGen/aliasing_parametric_simple_1.ll
new file mode 100644
index 0000000..cdb38be
--- /dev/null
+++ b/test/Isl/CodeGen/aliasing_parametric_simple_1.ll
@@ -0,0 +1,43 @@
+; RUN: opt %loadPolly -polly-codegen-isl -polly-use-runtime-alias-checks -S < %s | FileCheck %s
+;
+;    void jd(int *A, int *B, int c) {
+;      for (int i = 0; i < 1024; i++)
+;        A[i] = B[c];
+;    }
+;
+; CHECK:  %[[AMax:[._a-zA-Z0-9]*]] = getelementptr i32* %A, i64 1023
+; CHECK:  %[[BMin:[._a-zA-Z0-9]*]] = getelementptr i32* %B, i32 %c
+; CHECK:  %[[AltB:[._a-zA-Z0-9]*]] = icmp ult i32* %[[AMax]], %[[BMin]]
+; CHECK:  %[[BMax:[._a-zA-Z0-9]*]] = getelementptr i32* %B, i32 %c
+; CHECK:  %[[AMin:[._a-zA-Z0-9]*]] = getelementptr i32* %A, i64 0
+; CHECK:  %[[BltA:[._a-zA-Z0-9]*]] = icmp ult i32* %[[BMax]], %[[AMin]]
+; CHECK:  %[[NoAlias:[._a-zA-Z0-9]*]] = or i1 %[[AltB]], %[[BltA]]
+; CHECK:  %[[RTC:[._a-zA-Z0-9]*]] = and i1 true, %[[NoAlias]]
+; CHECK:  br i1 %[[RTC]], label %polly.start, label %for.cond
+;
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+
+define void @jd(i32* %A, i32* %B, i32 %c) {
+entry:
+  br label %for.cond
+
+for.cond:                                         ; preds = %for.inc, %entry
+  %indvars.iv = phi i64 [ %indvars.iv.next, %for.inc ], [ 0, %entry ]
+  %exitcond = icmp ne i64 %indvars.iv, 1024
+  br i1 %exitcond, label %for.body, label %for.end
+
+for.body:                                         ; preds = %for.cond
+  %idxprom = sext i32 %c to i64
+  %arrayidx = getelementptr inbounds i32* %B, i64 %idxprom
+  %tmp = load i32* %arrayidx, align 4
+  %arrayidx2 = getelementptr inbounds i32* %A, i64 %indvars.iv
+  store i32 %tmp, i32* %arrayidx2, align 4
+  br label %for.inc
+
+for.inc:                                          ; preds = %for.body
+  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
+  br label %for.cond
+
+for.end:                                          ; preds = %for.cond
+  ret void
+}
diff --git a/test/Isl/CodeGen/aliasing_parametric_simple_2.ll b/test/Isl/CodeGen/aliasing_parametric_simple_2.ll
new file mode 100644
index 0000000..2062985
--- /dev/null
+++ b/test/Isl/CodeGen/aliasing_parametric_simple_2.ll
@@ -0,0 +1,57 @@
+; RUN: opt %loadPolly -polly-codegen-isl -polly-use-runtime-alias-checks -S < %s | FileCheck %s
+;
+;    void jd(int *A, int *B, int c) {
+;      for (int i = 0; i < 1024; i++)
+;        A[i] = B[c - 10] + B[5];
+;    }
+;
+; CHECK:  %[[AMax:[._a-zA-Z0-9]*]] = getelementptr i32* %A, i64 1023
+; CHECK:  %[[m0:[._a-zA-Z0-9]*]] = sext i32 %c to i64
+; CHECK:  %[[m1:[._a-zA-Z0-9]*]] = icmp sge i64 %[[m0]], 15
+; CHECK:  %[[m2:[._a-zA-Z0-9]*]] = sext i32 %c to i64
+; CHECK:  %[[m3:[._a-zA-Z0-9]*]] = sub nsw i64 %[[m2]], 10
+; CHECK:  %[[m4:[._a-zA-Z0-9]*]] = select i1 %[[m1]], i64 5, i64 %[[m3]]
+; CHECK:  %[[BMin:[._a-zA-Z0-9]*]] = getelementptr i32* %B, i64 %[[m4]]
+; CHECK:  %[[AltB:[._a-zA-Z0-9]*]] = icmp ult i32* %[[AMax]], %[[BMin]]
+; CHECK:  %[[M0:[._a-zA-Z0-9]*]] = sext i32 %c to i64
+; CHECK:  %[[M1:[._a-zA-Z0-9]*]] = icmp sle i64 %[[M0]], 15
+; CHECK:  %[[M2:[._a-zA-Z0-9]*]] = sext i32 %c to i64
+; CHECK:  %[[M3:[._a-zA-Z0-9]*]] = sub nsw i64 %[[M2]], 10
+; CHECK:  %[[M4:[._a-zA-Z0-9]*]] = select i1 %[[M1]], i64 5, i64 %[[M3]]
+; CHECK:  %[[BMax:[._a-zA-Z0-9]*]] = getelementptr i32* %B, i64 %[[M4]]
+; CHECK:  %[[AMin:[._a-zA-Z0-9]*]] = getelementptr i32* %A, i64 0
+; CHECK:  %[[BltA:[._a-zA-Z0-9]*]] = icmp ult i32* %[[BMax]], %[[AMin]]
+; CHECK:  %[[NoAlias:[._a-zA-Z0-9]*]] = or i1 %[[AltB]], %[[BltA]]
+; CHECK:  %[[RTC:[._a-zA-Z0-9]*]] = and i1 true, %[[NoAlias]]
+; CHECK:  br i1 %[[RTC]], label %polly.start, label %for.cond
+;
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+
+define void @jd(i32* %A, i32* %B, i32 %c) {
+entry:
+  br label %for.cond
+
+for.cond:                                         ; preds = %for.inc, %entry
+  %indvars.iv = phi i64 [ %indvars.iv.next, %for.inc ], [ 0, %entry ]
+  %exitcond = icmp ne i64 %indvars.iv, 1024
+  br i1 %exitcond, label %for.body, label %for.end
+
+for.body:                                         ; preds = %for.cond
+  %sub = add nsw i32 %c, -10
+  %idxprom = sext i32 %sub to i64
+  %arrayidx = getelementptr inbounds i32* %B, i64 %idxprom
+  %tmp = load i32* %arrayidx, align 4
+  %arrayidx1 = getelementptr inbounds i32* %B, i64 5
+  %tmp1 = load i32* %arrayidx1, align 4
+  %add = add nsw i32 %tmp, %tmp1
+  %arrayidx3 = getelementptr inbounds i32* %A, i64 %indvars.iv
+  store i32 %add, i32* %arrayidx3, align 4
+  br label %for.inc
+
+for.inc:                                          ; preds = %for.body
+  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
+  br label %for.cond
+
+for.end:                                          ; preds = %for.cond
+  ret void
+}
-- 
2.0.4




More information about the llvm-commits mailing list