public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [fortran, patch] Add DREAL simplification (last remaining elemental required for initialization expressions)
@ 2011-11-08 10:57 FX
  2011-11-09  4:45 ` Steve Kargl
  0 siblings, 1 reply; 3+ messages in thread
From: FX @ 2011-11-08 10:57 UTC (permalink / raw)
  To: fortran; +Cc: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 397 bytes --]

Attached patch adds a (rather trivial) simplification routine for the DREAL intrinsic (a GNU extension), which is the last unimplemented simplification for elemental intrinsics (PR 38718, which tracks this issue, also lists LSHIFT and RSHIFT, but both have gained simplification routines since its last update).

Regtested on x86_64-linux, comes with a testcase. OK to commit to trunk?
FX



[-- Attachment #2: dreal.ChangeLog --]
[-- Type: application/octet-stream, Size: 299 bytes --]

2011-11-08  Francois-Xavier Coudert  <fxcoudert@gcc.gnu.org>

	PR fortran/38718
	* intrinsic.c (add_functions): 
	* intrinsic.h (gfc_expr): 
	* simplify.c (gfc_simplify_dint): 


2011-11-08  Francois-Xavier Coudert  <fxcoudert@gcc.gnu.org>

	PR fortran/38718
	* gfortran.dg/initialization_29.f90: 


[-- Attachment #3: dreal.diff --]
[-- Type: application/octet-stream, Size: 2454 bytes --]

Index: gcc/fortran/intrinsic.c
===================================================================
--- gcc/fortran/intrinsic.c	(revision 181149)
+++ gcc/fortran/intrinsic.c	(working copy)
@@ -1558,7 +1558,7 @@ add_functions (void)
   make_generic ("dprod", GFC_ISYM_DPROD, GFC_STD_F77);
 
   add_sym_1 ("dreal", GFC_ISYM_REAL, CLASS_ELEMENTAL, ACTUAL_NO, BT_REAL, dd, GFC_STD_GNU,
-	     NULL, NULL, NULL,
+	     NULL, gfc_simplify_dreal, NULL,
 	     a, BT_COMPLEX, dd, REQUIRED);
 
   make_generic ("dreal", GFC_ISYM_REAL, GFC_STD_GNU);
Index: gcc/fortran/intrinsic.h
===================================================================
--- gcc/fortran/intrinsic.h	(revision 181149)
+++ gcc/fortran/intrinsic.h	(working copy)
@@ -262,6 +262,7 @@ gfc_expr *gfc_simplify_digits (gfc_expr 
 gfc_expr *gfc_simplify_dim (gfc_expr *, gfc_expr *);
 gfc_expr *gfc_simplify_dprod (gfc_expr *, gfc_expr *);
 gfc_expr *gfc_simplify_dot_product (gfc_expr *, gfc_expr *);
+gfc_expr *gfc_simplify_dreal (gfc_expr *);
 gfc_expr *gfc_simplify_dshiftl (gfc_expr *, gfc_expr *, gfc_expr *);
 gfc_expr *gfc_simplify_dshiftr (gfc_expr *, gfc_expr *, gfc_expr *);
 gfc_expr *gfc_simplify_epsilon (gfc_expr *);
Index: gcc/fortran/simplify.c
===================================================================
--- gcc/fortran/simplify.c	(revision 181149)
+++ gcc/fortran/simplify.c	(working copy)
@@ -939,6 +939,21 @@ gfc_simplify_dint (gfc_expr *e)
 
 
 gfc_expr *
+gfc_simplify_dreal (gfc_expr *e)
+{
+  gfc_expr *result = NULL;
+
+  if (e->expr_type != EXPR_CONSTANT)
+    return NULL;
+
+  result = gfc_get_constant_expr (BT_REAL, e->ts.kind, &e->where);
+  mpc_real (result->value.real, e->value.complex, GFC_RND_MODE);
+
+  return range_check (result, "DREAL");
+}
+
+
+gfc_expr *
 gfc_simplify_anint (gfc_expr *e, gfc_expr *k)
 {
   gfc_expr *result;
Index: gcc/testsuite/gfortran.dg/initialization_29.f90
===================================================================
--- gcc/testsuite/gfortran.dg/initialization_29.f90	(revision 0)
+++ gcc/testsuite/gfortran.dg/initialization_29.f90	(revision 0)
@@ -0,0 +1,15 @@
+! { dg-do compile }
+!
+! PR fortran/38718
+!
+  implicit none
+  real(kind=8), parameter :: r = kind(0) + 0.2
+  complex(kind=8), parameter :: c = (r, -9.3)
+  integer, parameter :: k = nint(dreal(c))
+  integer, parameter :: l = nint(realpart(c))
+  integer(kind=k) :: i
+  integer(kind=l) :: j
+  i = 42
+  j = 42
+  print *, k, i, j, r
+  end

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [fortran, patch] Add DREAL simplification (last remaining elemental required for initialization expressions)
  2011-11-08 10:57 [fortran, patch] Add DREAL simplification (last remaining elemental required for initialization expressions) FX
@ 2011-11-09  4:45 ` Steve Kargl
  2011-11-09  9:53   ` FX
  0 siblings, 1 reply; 3+ messages in thread
From: Steve Kargl @ 2011-11-09  4:45 UTC (permalink / raw)
  To: FX; +Cc: fortran, gcc-patches

On Tue, Nov 08, 2011 at 11:33:56AM +0100, FX wrote:
> Attached patch adds a (rather trivial) simplification routine for the DREAL intrinsic (a GNU extension), which is the last unimplemented simplification for elemental intrinsics (PR 38718, which tracks this issue, also lists LSHIFT and RSHIFT, but both have gained simplification routines since its last update).
> 
> Regtested on x86_64-linux, comes with a testcase. OK to commit to trunk?
> FX

OK.

PS: Any chance of wrapping the long line to less than 80 characters?

-- 
Steve

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [fortran, patch] Add DREAL simplification (last remaining elemental required for initialization expressions)
  2011-11-09  4:45 ` Steve Kargl
@ 2011-11-09  9:53   ` FX
  0 siblings, 0 replies; 3+ messages in thread
From: FX @ 2011-11-09  9:53 UTC (permalink / raw)
  To: Steve Kargl; +Cc: fortran, gcc-patches

> PS: Any chance of wrapping the long line to less than 80 characters?

Committed as rev. 181198, with the long line in intrinsic.c wrapped.

Thanks for reviewing,
FX

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-11-09  9:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-11-08 10:57 [fortran, patch] Add DREAL simplification (last remaining elemental required for initialization expressions) FX
2011-11-09  4:45 ` Steve Kargl
2011-11-09  9:53   ` FX

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).