[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
This commit is contained in:
Mike Rice 2021-02-01 20:17:56 -08:00
parent 3a9d2f1488
commit ca98c15f23
3 changed files with 28 additions and 11 deletions

View File

@ -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

View File

@ -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:[@%].+]])

View File

@ -653,9 +653,10 @@ public:
;
#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)