1! { dg-do compile { target vect_simd_clones } }
2! { dg-additional-options "-O0 -fdump-tree-gimple -fdump-tree-optimized" }
3! { dg-additional-options "-mno-sse3" { target { i?86-*-* x86_64-*-* } } }
4
5module main
6  implicit none
7contains
8  integer function f01 (x)
9    integer, intent (in) :: x
10    f01 = x
11  end function
12
13  integer function f02 (x)
14    integer, intent (in) :: x
15    f02 = x
16  end function
17
18  integer function f03 (x)
19    integer, intent (in) :: x
20    f03 = x
21  end function
22
23  integer function f04 (x)
24    integer, intent(in) :: x
25
26    !$omp declare variant (f01) match (device={isa("avx512f")}) ! 4 or 8
27    !$omp declare variant (f02) match (implementation={vendor(score(3):gnu)},device={kind(cpu)}) ! (1 or 2) + 3
28    !$omp declare variant (f03) match (implementation={vendor(score(5):gnu)},device={kind(host)}) ! (1 or 2) + 5
29    f04 = x
30  end function
31
32  integer function test1 (x)
33    !$omp declare simd
34    integer, intent (in) :: x
35    integer :: a, b
36
37    ! At gimplification time, we can't decide yet which function to call.
38    ! { dg-final { scan-tree-dump-times "f04 \\\(x" 2 "gimple" } }
39    ! After simd clones are created, the original non-clone test1 shall
40    ! call f03 (score 6), the sse2/avx/avx2 clones too, but avx512f clones
41    ! shall call f01 with score 8.
42    ! { dg-final { scan-tree-dump-not "f04 \\\(x" "optimized" } }
43    ! { dg-final { scan-tree-dump-times "f03 \\\(x" 14 "optimized" } }
44    ! { dg-final { scan-tree-dump-times "f01 \\\(x" 4 "optimized" } }
45    a = f04 (x)
46    b = f04 (x)
47    test1 = a + b
48  end function
49end module
50