Issue 176408
Summary [MachinePipeliner] Generate invalid schedule due to incorrect memory instructions reordering
Labels new issue
Assignees
Reporter kasuga-fj
    The following Fortran program produces incorrect output when MachinePipeliner is enabled.

```fortran
program main
  integer,parameter :: n = 10
  real a(n),b(n),c(n)
  do i=1,n
 a(i)=1.0
    b(i)=4.0
    c(i)=1.0
  end do
  call sub(n,a,b,c,4.0)
 write(6,*) c
  stop
end program main

subroutine sub(n,a,b,c,x)
 integer n
  real a(n),b(n),c(n),x,s
  do i=2,n
    s = a(i) + sqrt(b(i))
 a(i) = a(i-1) + x
    c(i) = a(i) + s
  end do
end subroutine
```

```sh
$ flang -v
flang version 22.0.0git (https://github.com/llvm/llvm-project.git 2f7e218017db69454ea84e1849fcb9a11b1f7fef)
...

# Without pipeliner
$ flang -O3 -mcpu=neoverse-v1 -fno-unroll-loops a.f90
$ ./a.out
 1. 8. 12. 16. 20. 24. 28. 32. 36. 40.
Fortran STOP

# With pipeliner
$ flang -O3 -mcpu=neoverse-v1 -fno-unroll-loops -mllvm -aarch64-enable-pipeliner a.f90
$ ./a.out
 1. 8. 12. 28. 36. 44. 52. 60. 68. 40.
Fortran STOP
```

See https://godbolt.org/z/943W3ch6d for the reduced reproducer and debug output. Apparently, in the subroutine `sub`, the order of `SU(5)` (the load from `a(i)`) and `SU(10)` (the store to `a(i)`) is swapped incorrectly.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to