On 1/21/19 10:19 AM, Jakub Jelinek wrote:
> On Mon, Jan 21, 2019 at 10:09:01AM +0100, Martin Liška wrote:
>> @@ -11351,6 +11352,7 @@ match
>> gfc_match_gcc_builtin (void)
>> {
>> char builtin[GFC_MAX_SYMBOL_LEN + 1];
>> + char target[GFC_MAX_SYMBOL_LEN + 1];
>>
>> if (gfc_match (" ( %n ) attributes simd", builtin) != MATCH_YES)
>> return MATCH_ERROR;
>> @@ -11361,6 +11363,26 @@ gfc_match_gcc_builtin (void)
>> else if (gfc_match (" ( inbranch ) ") == MATCH_YES)
>> clause = SIMD_INBRANCH;
>>
>> + if (gfc_match (" if ( %n ) ", target) == MATCH_YES)
>> + {
>> + if (strcmp (target, "lp64") == 0)
>> + {
>> + if (TYPE_PRECISION (long_integer_type_node) != 64
>> + || POINTER_SIZE != 64
>> + || TYPE_PRECISION (integer_type_node) != 32)
>> + return MATCH_YES;
>> + }
>> + else if (strcmp (target, "ilp32") == 0)
>> + {
>> + if (TYPE_PRECISION (long_integer_type_node) != 32
>> + || POINTER_SIZE != 32
>> + || TYPE_PRECISION (integer_type_node) != 32)
>> + return MATCH_YES;
>> + }
>> + else
>> + return MATCH_ERROR;
>> + }
>
> You should adjust the syntax above the function too.
> And you need here buy-in from glibc folks.
>> +
>> if (gfc_vectorized_builtins == NULL)
>> gfc_vectorized_builtins = new hash_map<nofree_string_hash, int> ();
>>
>> diff --git a/gcc/testsuite/gfortran.dg/simd-builtins-7.f90
>> b/gcc/testsuite/gfortran.dg/simd-builtins-7.f90
>> new file mode 100644
>> index 00000000000..6445733d288
>> --- /dev/null
>> +++ b/gcc/testsuite/gfortran.dg/simd-builtins-7.f90
>> @@ -0,0 +1,21 @@
>> +! { dg-do compile { target { i?86-*-linux* x86_64-*-linux* } } }
>> +! { dg-additional-options "-msse2 -mno-avx -nostdinc -Ofast
>> -fpre-include=simd-builtins-7.h -fdump-tree-optimized" }
>> +
>> +program test_overloaded_intrinsic
>> + real(4) :: x4(3200), y4(3200)
>> + real(8) :: x8(3200), y8(3200)
>> +
>> + ! this should be using simd clone
>> + y4 = sin(x4)
>> + print *, y4
>> +
>> + ! this should not be using simd clone
>
> The above 2 comments are misleading, they only match what ia32 does.
>
>> + y4 = sin(x8)
>> + print *, y8
>> +end
>> +
>> +! { dg-final { scan-tree-dump "sinf.simdclone" "optimized" { target ia32 }
>> } } */
>> +! { dg-final { scan-tree-dump-not "sin.simdclone" "optimized" { target ia32
>> } } } */
>
> Perhaps use ilp32 instead of ia32?
>
> Jakub
>
Thanks for review, I'm attaching updated patch.
Martin
>From f8901f176f7832591dd9702da681859b9f3ddf38 Mon Sep 17 00:00:00 2001
From: marxin <[email protected]>
Date: Mon, 21 Jan 2019 08:46:06 +0100
Subject: [PATCH] Support if statement in !GCC$ builtin directive.
gcc/fortran/ChangeLog:
2019-01-21 Martin Liska <[email protected]>
* decl.c (gfc_match_gcc_builtin): Support filtering for
'lp64' and 'ilp32'.
gcc/testsuite/ChangeLog:
2019-01-21 Martin Liska <[email protected]>
* gfortran.dg/simd-builtins-7.f90: New test.
* gfortran.dg/simd-builtins-7.h: New test.
---
gcc/fortran/decl.c | 28 ++++++++++++++++++-
gcc/testsuite/gfortran.dg/simd-builtins-7.f90 | 19 +++++++++++++
gcc/testsuite/gfortran.dg/simd-builtins-7.h | 2 ++
3 files changed, 48 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/gfortran.dg/simd-builtins-7.f90
create mode 100644 gcc/testsuite/gfortran.dg/simd-builtins-7.h
diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c
index 3314e176881..3e2e9adcb4a 100644
--- a/gcc/fortran/decl.c
+++ b/gcc/fortran/decl.c
@@ -28,6 +28,7 @@ along with GCC; see the file COPYING3. If not see
#include "match.h"
#include "parse.h"
#include "constructor.h"
+#include "target.h"
/* Macros to access allocate memory for gfc_data_variable,
gfc_data_value and gfc_data. */
@@ -11338,7 +11339,7 @@ gfc_match_gcc_unroll (void)
return MATCH_ERROR;
}
-/* Match a !GCC$ builtin (b) attributes simd flags form:
+/* Match a !GCC$ builtin (b) attributes simd if(target) flags form:
The parameter b is name of a middle-end built-in.
Flags are one of:
@@ -11346,11 +11347,16 @@ gfc_match_gcc_unroll (void)
- inbranch
- notinbranch
+ Target must be one of:
+ - lp64
+ - ilp32
+
When we come here, we have already matched the !GCC$ builtin string. */
match
gfc_match_gcc_builtin (void)
{
char builtin[GFC_MAX_SYMBOL_LEN + 1];
+ char target[GFC_MAX_SYMBOL_LEN + 1];
if (gfc_match (" ( %n ) attributes simd", builtin) != MATCH_YES)
return MATCH_ERROR;
@@ -11361,6 +11367,26 @@ gfc_match_gcc_builtin (void)
else if (gfc_match (" ( inbranch ) ") == MATCH_YES)
clause = SIMD_INBRANCH;
+ if (gfc_match (" if ( %n ) ", target) == MATCH_YES)
+ {
+ if (strcmp (target, "lp64") == 0)
+ {
+ if (TYPE_PRECISION (long_integer_type_node) != 64
+ || POINTER_SIZE != 64
+ || TYPE_PRECISION (integer_type_node) != 32)
+ return MATCH_YES;
+ }
+ else if (strcmp (target, "ilp32") == 0)
+ {
+ if (TYPE_PRECISION (long_integer_type_node) != 32
+ || POINTER_SIZE != 32
+ || TYPE_PRECISION (integer_type_node) != 32)
+ return MATCH_YES;
+ }
+ else
+ return MATCH_ERROR;
+ }
+
if (gfc_vectorized_builtins == NULL)
gfc_vectorized_builtins = new hash_map<nofree_string_hash, int> ();
diff --git a/gcc/testsuite/gfortran.dg/simd-builtins-7.f90 b/gcc/testsuite/gfortran.dg/simd-builtins-7.f90
new file mode 100644
index 00000000000..c3ce5543779
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/simd-builtins-7.f90
@@ -0,0 +1,19 @@
+! { dg-do compile { target { i?86-*-linux* x86_64-*-linux* } } }
+! { dg-additional-options "-msse2 -mno-avx -nostdinc -Ofast -fpre-include=simd-builtins-7.h -fdump-tree-optimized" }
+
+program test_overloaded_intrinsic
+ real(4) :: x4(3200), y4(3200)
+ real(8) :: x8(3200), y8(3200)
+
+ y4 = sin(x4)
+ print *, y4
+
+ y4 = sin(x8)
+ print *, y8
+end
+
+! { dg-final { scan-tree-dump "sinf.simdclone" "optimized" { target ilp32 } } } */
+! { dg-final { scan-tree-dump-not "sin.simdclone" "optimized" { target ilp32 } } } */
+
+! { dg-final { scan-tree-dump "sin.simdclone" "optimized" { target lp64} } } */
+! { dg-final { scan-tree-dump-not "sinf.simdclone" "optimized" { target lp64 } } } */
diff --git a/gcc/testsuite/gfortran.dg/simd-builtins-7.h b/gcc/testsuite/gfortran.dg/simd-builtins-7.h
new file mode 100644
index 00000000000..1617e1086d0
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/simd-builtins-7.h
@@ -0,0 +1,2 @@
+!GCC$ builtin (sin) attributes simd (notinbranch) if(lp64)
+!GCC$ builtin (sinf) attributes simd (notinbranch) if(ilp32)
--
2.20.1