On 1/21/19 8:58 AM, Jakub Jelinek wrote:
> On Mon, Jan 21, 2019 at 08:47:42AM +0100, Martin Liška wrote:
>> diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c
>> index 3314e176881..5c7c062574b 100644
>> --- a/gcc/fortran/decl.c
>> +++ b/gcc/fortran/decl.c
>> @@ -11351,6 +11351,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 +11362,24 @@ gfc_match_gcc_builtin (void)
>> else if (gfc_match (" ( inbranch ) ") == MATCH_YES)
>> clause = SIMD_INBRANCH;
>>
>> + if (gfc_match (" if ( %n ) ", target) == MATCH_YES)
>> + {
>> + unsigned HOST_WIDE_INT size_of_long
>> + = tree_to_uhwi (TYPE_SIZE_UNIT (long_integer_type_node));
>> + if (strcmp (target, "lp64") == 0)
>> + {
>> + if (size_of_long != 8)
>> + return MATCH_YES;
>
> __LP64__ macro is defined if:
> if (TYPE_PRECISION (long_integer_type_node) == 64
> && POINTER_SIZE == 64
> && TYPE_PRECISION (integer_type_node) == 32)
> All of these are middle-end types or target macros, so you should be able to
> test that in the Fortran FE too.
>
>> + }
>> + else if (strcmp (target, "ilp32") == 0)
>> + {
>> + if (size_of_long != 4)
>> + return MATCH_YES;
>
> For this obviously as well.
>
>> + }
>> + else
>> + return MATCH_ERROR;
>> + }
>> +
>> if (gfc_vectorized_builtins == NULL)
>> gfc_vectorized_builtins = new hash_map<nofree_string_hash, int> ();
>
> Jakub
>
Sure, this is patch I've been currently testing.
Thoughts?
Martin
>From 1520b49856a1b39358602c4105dda3891cb166ff 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 | 22 +++++++++++++++++++
gcc/testsuite/gfortran.dg/simd-builtins-7.f90 | 21 ++++++++++++++++++
gcc/testsuite/gfortran.dg/simd-builtins-7.h | 2 ++
3 files changed, 45 insertions(+)
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..d68ab8e7931 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. */
@@ -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;
+ }
+
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
+ 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 } } } */
+
+! { 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