Skip to content

Commit 0243c4f

Browse files
committed
handle review comments
1 parent 2720590 commit 0243c4f

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

flang/lib/Optimizer/OpenMP/DoConcurrentConversion.cpp

+26-9
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace looputils {
2828
/// Stores info needed about the induction/iteration variable for each `do
2929
/// concurrent` in a loop nest.
3030
struct InductionVariableInfo {
31-
/// the operation allocating memory for iteration variable,
31+
/// The operation allocating memory for iteration variable.
3232
mlir::Operation *iterVarMemDef;
3333
};
3434

@@ -57,13 +57,30 @@ using LoopNestToIndVarMap =
5757
/// proves to be insufficient, this should be made more generic.
5858
mlir::Operation *findLoopIterationVarMemDecl(fir::DoLoopOp doLoop) {
5959
mlir::Value result = nullptr;
60-
for (mlir::Operation &op : doLoop) {
61-
// The first `fir.store` op we come across should be the op that updates the
62-
// loop's iteration variable.
63-
if (auto storeOp = mlir::dyn_cast<fir::StoreOp>(op)) {
64-
result = storeOp.getMemref();
65-
break;
60+
61+
// Checks if a StoreOp is updating the memref of the loop's iteration
62+
// variable.
63+
auto isStoringIV = [&](fir::StoreOp storeOp) {
64+
// Direct store into the IV memref.
65+
if (storeOp.getValue() == doLoop.getInductionVar())
66+
return true;
67+
68+
// Indirect store into the IV memref.
69+
if (auto convertOp = mlir::dyn_cast<fir::ConvertOp>(
70+
storeOp.getValue().getDefiningOp())) {
71+
if (convertOp.getOperand() == doLoop.getInductionVar())
72+
return true;
6673
}
74+
75+
return false;
76+
};
77+
78+
for (mlir::Operation &op : doLoop) {
79+
if (auto storeOp = mlir::dyn_cast<fir::StoreOp>(op))
80+
if (isStoringIV(storeOp)) {
81+
result = storeOp.getMemref();
82+
break;
83+
}
6784
}
6885

6986
assert(result != nullptr && result.getDefiningOp() != nullptr);
@@ -291,8 +308,8 @@ class DoConcurrentConversion : public mlir::OpConversionPattern<fir::DoLoopOp> {
291308
assert(loopNestClauseOps.loopLowerBounds.empty() &&
292309
"Loop nest bounds were already emitted!");
293310

294-
auto populateBounds = [&](mlir::Value var,
295-
llvm::SmallVectorImpl<mlir::Value> &bounds) {
311+
auto populateBounds = [](mlir::Value var,
312+
llvm::SmallVectorImpl<mlir::Value> &bounds) {
296313
bounds.push_back(var.getDefiningOp()->getResult(0));
297314
};
298315

flang/test/Transforms/DoConcurrent/non_const_bounds.f90

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ end program main
3232
! CHECK: omp.parallel {
3333

3434

35-
! Verify that we restort to using the outside value for the upper bound since it
35+
! Verify that we resort to using the outside value for the upper bound since it
3636
! is not originally a constant.
3737

3838
! CHECK: omp.wsloop {

0 commit comments

Comments
 (0)