summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gfortran.dg/transpose_optimization_1.f90
blob: 885ff7c2034999ce99c8f0f453171a437b16e9fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
! { dg-do compile }
! { dg-options "-Warray-temporaries -fdump-tree-original" }
!
! PR fortran/45648
! Non-copying descriptor transpose optimization (for function call args).
!
! Contributed by Richard Sandiford <richard@codesourcery.com>

module foo
  interface
    subroutine ext1 (a, b)
      real, intent (in), dimension (:, :) :: a, b
    end subroutine ext1
    subroutine ext2 (a, b)
      real, intent (in), dimension (:, :) :: a
      real, intent (out), dimension (:, :) :: b
    end subroutine ext2
    subroutine ext3 (a, b)
      real, dimension (:, :) :: a, b
    end subroutine ext3
  end interface
contains
  ! No temporary needed here.
  subroutine test1 (n, a, b, c)
    integer :: n
    real, dimension (n, n) :: a, b, c
    a = matmul (transpose (b), c)
  end subroutine test1

  ! No temporary either, as we know the arguments to matmul are intent(in)
  subroutine test2 (n, a, b)
    integer :: n
    real, dimension (n, n) :: a, b
    a = matmul (transpose (b), b)
  end subroutine test2

  ! No temporary needed.
  subroutine test3 (n, a, b, c)
    integer :: n
    real, dimension (n, n) :: a, c
    real, dimension (n+4, n+4) :: b
    a = matmul (transpose (b (2:n+1, 3:n+2)), c)
  end subroutine test3

  ! A temporary is needed for the result of either the transpose or matmul.
  subroutine test4 (n, a, b)
    integer :: n
    real, dimension (n, n) :: a, b
    a = matmul (transpose (a), b)       ! { dg-warning "Creating array temporary" }
  end subroutine test4

  ! The temporary is needed here since the second argument to imp1
  ! has unknown intent.
  subroutine test5 (n, a)
    integer :: n
    real, dimension (n, n) :: a
    call imp1 (transpose (a), a)        ! { dg-warning "Creating array temporary" }
  end subroutine test5

  ! No temporaries are needed here; imp1 can't modify either argument.
  ! We have to pack the arguments, however. 
  subroutine test6 (n, a, b)
    integer :: n
    real, dimension (n, n) :: a, b
    call imp1 (transpose (a), transpose (b))    ! { dg-warning "Creating array temporary" }
  end subroutine test6

  ! No temporaries are needed here; imp1 can't modify either argument.
  ! We don't have to pack the arguments. 
  subroutine test6_bis (n, a, b)
    integer :: n
    real, dimension (n, n) :: a, b
    call ext3 (transpose (a), transpose (b))
  end subroutine test6_bis

  ! No temporary is neede here; the second argument is intent(in).
  subroutine test7 (n, a)
    integer :: n
    real, dimension (n, n) :: a
    call ext1 (transpose (a), a)
  end subroutine test7

  ! The temporary is needed here though.
  subroutine test8 (n, a)
    integer :: n
    real, dimension (n, n) :: a
    call ext2 (transpose (a), a)        ! { dg-warning "Creating array temporary" } 
  end subroutine test8

  ! Silly, but we don't need any temporaries here.
  subroutine test9 (n, a)
    integer :: n
    real, dimension (n, n) :: a
    call ext1 (transpose (transpose (a)), a)
  end subroutine test9

  ! The outer transpose needs a temporary; the inner one doesn't.
  subroutine test10 (n, a)
    integer :: n
    real, dimension (n, n) :: a
    call ext2 (transpose (transpose (a)), a)    ! { dg-warning "Creating array temporary" }
  end subroutine test10
end module foo

! { dg-final { scan-tree-dump-times "struct\[^\\n\]*atmp" 4 "original" } }
! { dg-final { cleanup-tree-dump "original" } }