Issue 233992
Summary [flang][OpenMP] Wrong step used for LINEAR list items after a multi-item LINEAR clause
Labels flang
Assignees
Reporter adit4443ya
    When a `linear` clause has more than one list item, every list item after that clause gets the wrong step. The result is silently wrong.

Reproducer (`step.f90`):
```fortran
program step
  implicit none
  integer :: i, a, b, c
  a = 0; b = 0; c = 0
  !$omp simd linear(a,b:2) linear(c:3)
  do i = 1, 4
    a = a + 2
    b = b + 2
    c = c + 3
  end do
  print *, a, b, c, i
end program
```

flang (main):
```
$ flang -fopenmp step.f90 && ./a.out
 8 8 9 6
```

gfortran 15.2.1:
```
$ gfortran -fopenmp step.f90 && ./a.out
           8           8          12           5
```

`c` should be 12 and `i` should be 5. In the HLFIR (`flang -fc1 -fopenmp -emit-hlfir`), `c` and the implicitly linear loop variable `i` both get step `2`, when they should get `3` and `1`:
```
omp.simd linear(@_QFEa_linear_i32 %2#0 -> %arg0 : !fir.ref<i32> = %c2_i32 : i32,
 @_QFEb_linear_i32 %4#0 -> %arg1 : !fir.ref<i32> = %c2_i32 : i32,
 @_QFEc_linear_i32 %6#0 -> %arg2 : !fir.ref<i32> = %c2_i32_2 : i32,
                @_QFEi_linear_i32 %8#0 -> %arg3 : !fir.ref<i32> = %c2_i32_2 : i32) linear_var_types([i3
```

Cause: `ClauseProcessor::processLinear` (`flang/lib/Lower/OpenMP/ClauseProcessor.cpp`) adds the step in's objects with `result.linearStepVars.append(objects.size(), operand)`. A clause with N list itemstherefore adds N*N steps instead of N. Steps are matched to linear variables by position, so every later variable is shifted onto the wrong step. A clause with one list item, or a single `linear` clause, is unaffected because all the extra steps are equal.

_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to