diff --git a/polly/test/ScopDetect/simple_loop.ll b/polly/test/ScopDetect/simple_loop.ll new file mode 100644 index 000000000000..bcb096d8db9f --- /dev/null +++ b/polly/test/ScopDetect/simple_loop.ll @@ -0,0 +1,30 @@ +; RUN: opt %loadPolly -polly-detect -analyze < %s | FileCheck %s + +; void f(long A[], long N) { +; long i; +; for (i = 0; i < N; ++i) +; A[i] = i; +; } + +target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128" +target triple = "x86_64-unknown-linux-gnu" + +define void @f(i64* %A, i64 %N) nounwind { +entry: + fence seq_cst + br label %for.i + +for.i: + %indvar = phi i64 [ 0, %entry ], [ %indvar.next, %for.i ] + %scevgep = getelementptr i64* %A, i64 %indvar + store i64 %indvar, i64* %scevgep + %indvar.next = add nsw i64 %indvar, 1 + %exitcond = icmp eq i64 %indvar.next, %N + br i1 %exitcond, label %return, label %for.i + +return: + fence seq_cst + ret void +} + +; CHECK: Valid Region for Scop: for.i => return diff --git a/polly/test/ScopDetect/simple_loop_two_phi_nodes.ll b/polly/test/ScopDetect/simple_loop_two_phi_nodes.ll new file mode 100644 index 000000000000..fbffcd78817f --- /dev/null +++ b/polly/test/ScopDetect/simple_loop_two_phi_nodes.ll @@ -0,0 +1,34 @@ +; RUN: opt %loadPolly -polly-detect -analyze < %s | FileCheck %s + +; void f(long A[], long N) { +; long i; +; long i_non_canonical = 1; +; for (i = 0; i < N; ++i) { +; A[i] = i_non_canonical; +; i_non_canonical += 1; +; } +; } + +target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128" +target triple = "x86_64-unknown-linux-gnu" + +define void @f(i64* %A, i64 %N) nounwind { +entry: + %cmp = icmp sgt i64 %N, 0 + br i1 %cmp, label %for.i, label %return + +for.i: + %indvar = phi i64 [ 0, %entry ], [ %indvar.next, %for.i ] + %indvar_non_canonical = phi i64 [ 1, %entry ], [ %indvar_non_canonical.next, %for.i ] + %scevgep = getelementptr i64* %A, i64 %indvar + store i64 %indvar_non_canonical, i64* %scevgep + %indvar.next = add nsw i64 %indvar, 1 + %indvar_non_canonical.next = add nsw i64 %indvar_non_canonical, 1 + %exitcond = icmp eq i64 %indvar.next, %N + br i1 %exitcond, label %return, label %for.i + +return: + ret void +} + +; CHECK-NOT: Valid Region for Scop diff --git a/polly/test/ScopDetect/simple_loop_with_param.ll b/polly/test/ScopDetect/simple_loop_with_param.ll new file mode 100644 index 000000000000..73e340141e26 --- /dev/null +++ b/polly/test/ScopDetect/simple_loop_with_param.ll @@ -0,0 +1,51 @@ +; RUN: opt %loadPolly -basicaa -polly-detect -analyze < %s | FileCheck %s + +; void f(long A[], long N, long *init_ptr) { +; long i, j; +; long i_non_canonical; +; +; for (i = 0; i < N; ++i) { +; init = *init_ptr; +; i_non_canonical = init; +; for (i = 0; i < N; ++i) { +; A[i] = i_non_canonical; +; i_non_canonical += 1; +; } +; } +; } + +target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128" +target triple = "x86_64-unknown-linux-gnu" + +define void @f(i64* noalias %A, i64 %N, i64* noalias %init_ptr) nounwind { +entry: + br label %for.i + +for.i: + %indvar.i = phi i64 [ 0, %entry ], [ %indvar.i.next, %for.i.end ] + %indvar.i.next = add nsw i64 %indvar.i, 1 + br label %entry.next + +entry.next: + %init = load i64* %init_ptr + br label %for.j + +for.j: + %indvar.j = phi i64 [ 0, %entry.next ], [ %indvar.j.next, %for.j ] + %indvar.j.non_canonical = phi i64 [ %init, %entry.next ], [ %indvar.j.non_canonical.next, %for.j ] + %scevgep = getelementptr i64* %A, i64 %indvar.j + store i64 %indvar.j.non_canonical, i64* %scevgep + %indvar.j.next = add nsw i64 %indvar.j, 1 + %indvar.j.non_canonical.next = add nsw i64 %indvar.j.non_canonical, 1 + %exitcond.j = icmp eq i64 %indvar.j.next, %N + br i1 %exitcond.j, label %for.i.end, label %for.j + +for.i.end: + %exitcond.i = icmp eq i64 %indvar.i.next, %N + br i1 %exitcond.i, label %return, label %for.i + +return: + ret void +} + +; CHECK-NOT: Valid Region for Scop diff --git a/polly/test/ScopDetect/simple_loop_with_param_2.ll b/polly/test/ScopDetect/simple_loop_with_param_2.ll new file mode 100644 index 000000000000..fa85556b405a --- /dev/null +++ b/polly/test/ScopDetect/simple_loop_with_param_2.ll @@ -0,0 +1,47 @@ +; RUN: opt %loadPolly -basicaa -polly-detect -analyze < %s | FileCheck %s + +; void f(long A[], int N, int *init_ptr) { +; long i, j; +; +; for (i = 0; i < N; ++i) { +; init = *init_ptr; +; for (i = 0; i < N; ++i) { +; A[i] = init + 2; +; } +; } +; } + +target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128" +target triple = "x86_64-unknown-linux-gnu" + +define void @f(i64* noalias %A, i64 %N, i64* noalias %init_ptr) nounwind { +entry: + br label %for.i + +for.i: + %indvar.i = phi i64 [ 0, %entry ], [ %indvar.i.next, %for.i.end ] + %indvar.i.next = add nsw i64 %indvar.i, 1 + br label %entry.next + +entry.next: + %init = load i64* %init_ptr + br label %for.j + +for.j: + %indvar.j = phi i64 [ 0, %entry.next ], [ %indvar.j.next, %for.j ] + %init_plus_two = add i64 %init, 2 + %scevgep = getelementptr i64* %A, i64 %indvar.j + store i64 %init_plus_two, i64* %scevgep + %indvar.j.next = add nsw i64 %indvar.j, 1 + %exitcond.j = icmp eq i64 %indvar.j.next, %N + br i1 %exitcond.j, label %for.i.end, label %for.j + +for.i.end: + %exitcond.i = icmp eq i64 %indvar.i.next, %N + br i1 %exitcond.i, label %return, label %for.i + +return: + ret void +} + +; CHECK: Valid Region for Scop: for.i => return