llvm / llvm/llvm-project

`#pragma omp tile` and `lastprivate`

Open
#223,676 0 comments 0 reactions 0 assignees View on GitHub
clang:openmp
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

Incorrect code generation of `lastprivate` on a tiled loop:

```cpp
// RUN: %libomp-compile-and-run | FileCheck %s --match-full-lines

#ifndef HEADER
#define HEADER

#include
#include

int tilesize = -2;

int main() {
printf("do\n");

int i = -42;
int x = -99;
#pragma omp parallel for num_threads(8) schedule(static,1) firstprivate(x) lastprivate(x) lastprivate(i) collapse(2)
#pragma omp tile sizes(5)
for (i = 0; i < 6; ++i)
x = i;

printf("i=%d x=%d\n", i, x);

printf("done\n");
return EXIT_SUCCESS;
}

#endif /* HEADER */

// CHECK: do
// CHECK-NEXT: i=6 x=5
// CHECK-NEXT: done
```

Outputs:
1. Without -fopenmp / pragmas (reference): `i=6 x=5` (expected/reference result)
2. `#pragma omp parallel for` only and without collapse: `i=6 x=5`
3. `#pragma omp tile sizes(5)` only : `i=5 x=5`
4. No collapse : `i=5 x=5`
5. tile+for+collapse: `i=1 x=1`

The reason is likely that the `Finals` field of OMPLoopBasedDirective is not preserved by tiling.

Contributor guide

Open the contributing guide

Research direction

Start by compiling and running the supplied C++ reproducer with the shown OpenMP pragma combinations, confirming the tiled loop produces i=1 x=1 instead of i=6 x=5. Then inspect OMPLoopBasedDirective and the tiling path, focusing on whether the Finals field survives transformation; done means the supplied FileCheck command reports the expected output.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
65/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.