Author: Mike Rice Date: 2021-02-02T10:09:37-08:00 New Revision: ca98c15f23354520bf689bd5feb333a716159d2c
URL: https://github.com/llvm/llvm-project/commit/ca98c15f23354520bf689bd5feb333a716159d2c DIFF: https://github.com/llvm/llvm-project/commit/ca98c15f23354520bf689bd5feb333a716159d2c.diff LOG: [OpenMP] Fix iterations calculation for dependent counters. The number of iterations calculation was failing in some cases with more than two collpased loops. Now the LoopIterationSpace selected matches InitDependOnLC and CondDependOnLC. Differential Revision: https://reviews.llvm.org/D95834 Added: Modified: clang/lib/Sema/SemaOpenMP.cpp clang/test/OpenMP/for_codegen.cpp clang/test/OpenMP/for_loop_messages.cpp Removed: ################################################################################ diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp index df42767f6ce4..b9315d287e6d 100644 --- a/clang/lib/Sema/SemaOpenMP.cpp +++ b/clang/lib/Sema/SemaOpenMP.cpp @@ -7413,10 +7413,7 @@ Expr *OpenMPIterationSpaceChecker::buildNumIterations( // LB = TestIsLessOp.getValue() ? min(LB(MinVal), LB(MaxVal)) : // max(LB(MinVal), LB(MaxVal)) if (InitDependOnLC) { - const LoopIterationSpace &IS = - ResultIterSpaces[ResultIterSpaces.size() - 1 - - InitDependOnLC.getValueOr( - CondDependOnLC.getValueOr(0))]; + const LoopIterationSpace &IS = ResultIterSpaces[*InitDependOnLC - 1]; if (!IS.MinValue || !IS.MaxValue) return nullptr; // OuterVar = Min @@ -7493,10 +7490,7 @@ Expr *OpenMPIterationSpaceChecker::buildNumIterations( // UB = TestIsLessOp.getValue() ? max(UB(MinVal), UB(MaxVal)) : // min(UB(MinVal), UB(MaxVal)) if (CondDependOnLC) { - const LoopIterationSpace &IS = - ResultIterSpaces[ResultIterSpaces.size() - 1 - - InitDependOnLC.getValueOr( - CondDependOnLC.getValueOr(0))]; + const LoopIterationSpace &IS = ResultIterSpaces[*CondDependOnLC - 1]; if (!IS.MinValue || !IS.MaxValue) return nullptr; // OuterVar = Min diff --git a/clang/test/OpenMP/for_codegen.cpp b/clang/test/OpenMP/for_codegen.cpp index 5a8402ee1702..64652e530f6a 100644 --- a/clang/test/OpenMP/for_codegen.cpp +++ b/clang/test/OpenMP/for_codegen.cpp @@ -198,6 +198,28 @@ void loop_with_counter_collapse() { } } } + +// CHECK-LABEL: loop_with_counter_collapse4 +void loop_with_counter_collapse4() { + + // Check bounds calculation when collapse > 2 + // CHECK: store i32 0, i32* [[I_TMP:%.+]], + // CHECK: [[VAL:%.+]] = load i32, i32* [[I_TMP]], + // CHECK: store i32 [[VAL]], i32* [[K_LB_MIN:%.+]], + // CHECK: store i32 6, i32* [[I_TMP]], + // CHECK: [[VAL:%.+]] = load i32, i32* [[I_TMP]], + // CHECK: store i32 [[VAL]], i32* [[K_LB_MAX:%.+]], + #pragma omp for collapse(4) + for (int i = 0; i < 7; i++) { + for (int j = 0; j < 11; j++) { + for (int k = i; k < 7; k++) { + for (int l = 0; l < 11; l++) { + } + } + } + } +} + // CHECK-LABEL: define {{.*void}} @{{.*}}without_schedule_clause{{.*}}(float* {{.+}}, float* {{.+}}, float* {{.+}}, float* {{.+}}) void without_schedule_clause(float *a, float *b, float *c, float *d) { // CHECK: [[GTID:%.+]] = call i32 @__kmpc_global_thread_num([[IDENT_T_TY]]* [[DEFAULT_LOC:[@%].+]]) diff --git a/clang/test/OpenMP/for_loop_messages.cpp b/clang/test/OpenMP/for_loop_messages.cpp index a1bc9bd3e045..e62ec07acc04 100644 --- a/clang/test/OpenMP/for_loop_messages.cpp +++ b/clang/test/OpenMP/for_loop_messages.cpp @@ -653,9 +653,10 @@ class TC { ; #pragma omp parallel -// expected-error@+5 2 {{expected loop invariant expression or '<invariant1> * ii + <invariant2>' kind of expression}} -// expected-error@+4 {{expected loop invariant expression or '<invariant1> * TC::ii + <invariant2>' kind of expression}} -// expected-error@+4 {{expected loop invariant expression or '<invariant1> * TC::ii + <invariant2>' kind of expression}} +// expected-error@+6 {{expected loop invariant expression or '<invariant1> * TC::ii + <invariant2>' kind of expression}} +// expected-error@+6 {{expected loop invariant expression or '<invariant1> * TC::ii + <invariant2>' kind of expression}} +// expected-error@+4 2 {{expected loop invariant expression or '<invariant1> * ii + <invariant2>' kind of expression}} +// expected-error@+4 2 {{expected loop invariant expression or '<invariant1> * ii + <invariant2>' kind of expression}} #pragma omp for collapse(3) for (ii = 10 + 25; ii < 1000; ii += 1) for (iii = ii * 10 + 25; iii < ii / ii - 23; iii += 1) _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits