[all-commits] [llvm/llvm-project] ac2c5a: [OPENMP] Fix mixture of omp and clang pragmas

KAWASHIMA Takahiro via All-commits all-commits at lists.llvm.org
Thu May 21 20:55:18 PDT 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: ac2c5af67f036ec810556372b16548ae9b663f36
      https://github.com/llvm/llvm-project/commit/ac2c5af67f036ec810556372b16548ae9b663f36
  Author: ISHIGURO, Hiroshi <fj8500hh at fujitsu.com>
  Date:   2020-05-22 (Fri, 22 May 2020)

  Changed paths:
    M clang/lib/CodeGen/CGStmtOpenMP.cpp
    A clang/test/OpenMP/omp_with_loop_pragma.c

  Log Message:
  -----------
  [OPENMP] Fix mixture of omp and clang pragmas

Fixes PR45753

When a program that contains a loop to which both `omp parallel for`
pragma and `clang loop` pragma are associated is compiled with the
-fopenmp option, `clang loop` pragma did not take effect. The example
below should not be vectorized by the `clang loop` pragma but it was
actually vectorized. The cause is that `llvm.loop.vectorize.width`
was not output to the IR when -fopenmp is specified.

The fix attaches attributes if they exist for the loop.

[example.c]

```
int a[100], b[100];
void foo() {
  #pragma omp parallel for
  #pragma clang loop vectorize(disable)
  for (int i = 0; i < 100; i++)
    a[i] += b[i] * i;
}
```

[compile]

```
$ clang -O2 -fopenmp example.c -c -Rpass=vect
example.c:3:11: remark: vectorized loop (vectorization width: 4, interleaved count: 2) [-Rpass=loop-vectorize]
  #pragma omp parallel for
          ^
```

[IR with -fopenmp]

```
$ clang -O2 exmaple.c -S -emit-llvm -mllvm -disable-llvm-optzns -o - -fopenmp | grep 'vectorize\.width'
```

[IR with -fno-openmp]

```
$ clang -O2 example.c -S -emit-llvm -mllvm -disable-llvm-optzns -o - -fno-openmp | grep 'vectorize\.width'
!7 = !{!"llvm.loop.vectorize.width", i32 1}
```

Differential Revision: https://reviews.llvm.org/D79921




More information about the All-commits mailing list