[flang-commits] [flang] [flang][OpenMP] Fix LASTPRIVATE for iteration variables (PR #69773)
via flang-commits
flang-commits at lists.llvm.org
Sun Oct 22 21:46:14 PDT 2023
https://github.com/NimishMishra commented:
Thank you for the patch!
If I understand correctly, the previous implementation was generating the `fir.if` depending on a equality check between `v` and `loopIV`. As such, the final update to the iteration variable was being missed.
I'm ok with the approach taken here. Basically, we force the iteration variable to advance by `step`, and then check if it crosses the upperbound `ub`. Depending on whether `step` is positive or negative, a `>` or a `<` predicate is needed for comparison. As such, the ternary select operation seems fine.
I've just one point to raise (@kiranchandramohan can comment better). Through this approach, we have introduced a mandatory set of 1 `arith.addi`, 3 `arith.cmpi`, and 1 `arith.select` in _every_ iteration of the loop. Again, not very sure about this, but can this have a bearing on performance, since loops are extensively present across benchmarks we use for validation?
Not analysed this in depth, but could the following work?
```
%cmp = arith.cmpi eq, %u, %iv
fir.if %cmp {
%temp = arith.addi %arg0, %step
fir.store %temp to %iv
}
```
Basically, we let the current flow (generating `if` on `u = ub`) be, and add the extra operations within the `fir.if`? Would it cause some problems I have missed? I expect if the loop is well formed (say both `ub` and `step` are negative), then also the equality condition should work.
https://github.com/llvm/llvm-project/pull/69773
More information about the flang-commits
mailing list