diff options
author | Alexey Bataev <a.bataev@hotmail.com> | 2015-04-22 11:59:37 +0000 |
---|---|---|
committer | Alexey Bataev <a.bataev@hotmail.com> | 2015-04-22 11:59:37 +0000 |
commit | 62dbb979c0bd3ab34d0b60b6fedfb66321d81dcf (patch) | |
tree | 0508793fb5118827e38d856e37c22957cf3ffc41 /clang/test/OpenMP/for_codegen.cpp | |
parent | 592cee666e17edd4402f355f36af51f41915efbe (diff) | |
download | bcm5719-llvm-62dbb979c0bd3ab34d0b60b6fedfb66321d81dcf.tar.gz bcm5719-llvm-62dbb979c0bd3ab34d0b60b6fedfb66321d81dcf.zip |
[OPENMP] Fix use of unsigned counters in loops with zero trip count.
Patch fixes bugs in codegen for loops with unsigned counters and zero trip count. Previously preconditions for all loops were built using logic (Upper - Lower) > 0. But if the loop is a loop with zero trip count, then Upper - Lower is < 0 only for signed integer, for unsigned we're running into an underflow situation.
In this patch we're using original Lower<Upper condition to check that loop body can be executed at least once. Also this allows to skip code generation for loops, if it is known that preconditions for the loop are always false.
Differential Revision: http://reviews.llvm.org/D9103
llvm-svn: 235500
Diffstat (limited to 'clang/test/OpenMP/for_codegen.cpp')
-rw-r--r-- | clang/test/OpenMP/for_codegen.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/clang/test/OpenMP/for_codegen.cpp b/clang/test/OpenMP/for_codegen.cpp index a53af80ac64..85f1ba69b27 100644 --- a/clang/test/OpenMP/for_codegen.cpp +++ b/clang/test/OpenMP/for_codegen.cpp @@ -315,6 +315,31 @@ void runtime(float *a, float *b, float *c, float *d) { // CHECK: ret void } +// CHECK-LABEL: test_precond +void test_precond() { + // CHECK: [[A_ADDR:%.+]] = alloca i8, + // CHECK: [[I_ADDR:%.+]] = alloca i8, + char a = 0; + // CHECK: store i32 0, i32* [[IV_ADDR:%.+]], + // CHECK: [[A:%.+]] = load i8, i8* [[A_ADDR]], + // CHECK: [[CONV:%.+]] = sext i8 [[A]] to i32 + // CHECK: [[IV:%.+]] = load i32, i32* [[IV_ADDR]], + // CHECK: [[MUL:%.+]] = mul nsw i32 [[IV]], 1 + // CHECK: [[ADD:%.+]] = add nsw i32 [[CONV]], [[MUL]] + // CHECK: [[CONV:%.+]] = trunc i32 [[ADD]] to i8 + // CHECK: store i8 [[CONV]], i8* [[I_ADDR]], + // CHECK: [[A:%.+]] = load i8, i8* [[A_ADDR]], + // CHECK: [[CONV:%.+]] = sext i8 [[A]] to i32 + // CHECK: [[CMP:%.+]] = icmp slt i32 [[CONV]], 10 + // CHECK: br i1 [[CMP]], label %[[PRECOND_THEN:[^,]+]], label %[[PRECOND_END:[^,]+]] + // CHECK: [[PRECOND_THEN]] + // CHECK: call void @__kmpc_for_static_init_4 +#pragma omp for + for(char i = a; i < 10; ++i); + // CHECK: call void @__kmpc_for_static_fini + // CHECK: [[PRECOND_END]] +} + // TERM_DEBUG-LABEL: foo int foo() {return 0;}; |