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 will not take effect.
The example below should not be vectorized by the "clang loop` pragma but is it actually vectorized.
The cause is that "llvm.loop.vectorize.width" is not output to the IR when -fopenmp is specified.
The fix attaches attributes if they exist in the loop.
[example.c]
int a[100], b[100]; int 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 a.c -c -Rpass=vect
a.c:3:1: remark: vectorized loop (vectorization width: 4, interleaved count: 2) [-Rpass=loop-vectorize] #pragma omp parallel for ^
[IR]
- -fopenmp
$ clang -O2 a.c -S -emit-llvm -mllvm -disable-llvm-optzns -o - -fopenmp |grep "vectorize\.width"
$
- -fno-openmp
$ clang -O2 a.c -S -emit-llvm -mllvm -disable-llvm-optzns -o - -fno-openmp |grep "vectorize\.width"
!7 = !{!"llvm.loop.vectorize.width", i32 1}
const auto &OMPED = cast<OMPExecutableDirective>(S);