[flang-commits] [flang] [flang][OpenMP] Fix LASTPRIVATE for iteration variables (PR #69773)
Leandro Lupori via flang-commits
flang-commits at lists.llvm.org
Mon Oct 23 10:48:18 PDT 2023
================
@@ -349,34 +354,55 @@ void DataSharingProcessor::insertLastPrivateCompare(mlir::Operation *op) {
}
}
} else if (mlir::isa<mlir::omp::WsLoopOp>(op)) {
- mlir::Operation *lastOper = op->getRegion(0).back().getTerminator();
- firOpBuilder.setInsertionPoint(lastOper);
-
// Update the original variable just before exiting the worksharing
// loop. Conversion as follows:
//
// omp.wsloop {
// omp.wsloop { ...
// ... store
- // store ===> %cmp = llvm.icmp "eq" %iv %ub
- // omp.yield fir.if %cmp {
- // } ^%lpv_update_blk:
+ // store ===> %v = arith.addi %iv, %step
+ // omp.yield %cmp = %step < 0 ? %v < %ub : %v > %ub
+ // } fir.if %cmp {
+ // fir.store %v to %loopIV
----------------
luporl wrote:
The `fir.store` here is needed. Considering the example of the previous conversation, `loopIV` is updated in the beginning of the loop body only, to have the same value as `iv`, but we need it to hold `v` instead (`iv` + `step`). Also, `^%lpv_update_blk` copies `loopIV` to `ia` and not `iv` to `loopIV`. In the end this store gets optimized, because `^%lpv_update_blk` generates a load `loopIV` right after it.
https://github.com/llvm/llvm-project/pull/69773
More information about the flang-commits
mailing list