https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97063

            Bug ID: 97063
           Summary: [ MATMUL intrinsic] The value of result is wrong when
                    vector (step size is negative) * matrix
           Product: gcc
           Version: 10.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: xin....@compiler-dev.com
  Target Milestone: ---

Consider the following Fortran program:
program p
    implicit none
    real(kind=16), dimension(6) :: arr1
    real(kind=16), dimension(6, 10) :: arr2
    real(kind=16), dimension(10) :: arr3, arr6
    real(kind=16), dimension(3) :: arr4
    real(kind=16), dimension(3, 10) :: arr5
    integer :: i, j
    data arr1 /0.0_16, 1.0_16, 2.0_16, 3.0_16, 4.0_16, 5.0_16/
    do i = 1, 6
       do j = 1,10
          arr2(i, j) = (i + j) * 1.0_16
       end do
    end do
    write(*,*) "--arr3--:"
    arr3 = matmul(arr1(5:1:-2),arr2(5:1:-2, :))
    write(*,'(5F5.1)') arr3
    write(*,*) "--arr4--:"
    arr4 = arr1(5:1:-2)
    write(*,'(5F5.1)') arr4
    write(*,*) "--arr6--:"
    arr6 = matmul(arr4, arr2(5:1:-2, :))
    write(*,'(5F5.1)') arr6
end program

Compiled with gfortran 10.1.0, the program prints:

 --arr3--:
 44.0 53.0 62.0 71.0 80.0
 89.0 98.0107.0116.0125.0
 --arr4--:
  4.0  2.0  0.0
 --arr6--:
 32.0 38.0 44.0 50.0 56.0
 62.0 68.0 74.0 80.0 86.0

As you can see,the value of arr3 is differnet with arr6.

Reply via email to