[llvm] [mlir] [OpenMP][OMPIRBuilder] Fix lastiter assertion in target workshare loop (PR #214996)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 11 00:15:46 PDT 2026
RohithPariki wrote:
> This diff has no test. Please add a test using the reproducer.
Thanks for the thorough review!
1. **Race condition fix**: you are completely right. Forcing `lastiter` to 1 caused all threads executing the outer kernel to take the write-back branch. I've updated `applyWorkshareLoopTarget` to initialize `p.lastiter` to `0` and evaluate whether the current iteration counter inside the outlined loop body equals `TripCount - 1`. `p.lastiter` is updated to `1` only during the last iteration, so only the thread executing the last iteration will perform the write-back.
2. **Added Test**: i have added a test in `mlir/test/Target/LLVMIR/openmp-target-wsloop-linear.mlir` using the reproducer from #213905 to verify both `lastiter` initialization and the in-body last iteration check during LLVM IR lowering.
https://github.com/llvm/llvm-project/pull/214996
More information about the llvm-commits
mailing list