Bug 36117 - Use MPFR for bessel function (optimization, rejects valid F2008)
Summary: Use MPFR for bessel function (optimization, rejects valid F2008)
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.4.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: missed-optimization, rejects-valid
Depends on:
Blocks:
 
Reported: 2008-05-03 12:30 UTC by Tobias Burnus
Modified: 2020-01-01 17:37 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2008-05-03 12:30:51 UTC
Currently, the Bessel function are not simplified, even though MPFR supports this (since 2.3.0) via
— Function: int mpfr_j0 (mpfr_t rop, mpfr_t op, mp_rnd_t rnd)
— Function: int mpfr_j1 (mpfr_t rop, mpfr_t op, mp_rnd_t rnd)
— Function: int mpfr_jn (mpfr_t rop, long n, mpfr_t op, mp_rnd_t rnd)
— Function: int mpfr_y0 (mpfr_t rop, mpfr_t op, mp_rnd_t rnd)
— Function: int mpfr_y1 (mpfr_t rop, mpfr_t op, mp_rnd_t rnd)
— Function: int mpfr_yn (mpfr_t rop, long n, mpfr_t op, mp_rnd_t rnd)

(One should use: #if MPFR_VERSION >= MPFR_VERSION_NUM(2,3,0) )

------------------

Found at:
http://groups.google.com/group/comp.lang.fortran/browse_thread/thread/97eec25eef27e9fb

See especially, these two posts by James Van Buskirk:
http://groups.google.com/group/comp.lang.fortran/msg/44e373c15a051393
http://groups.google.com/group/comp.lang.fortran/msg/a732fb2849020fe3

The following program works if one replaces BESJ0 by ERF or ACOSH.

Error: 'kind' argument of 'cmplx' intrinsic at (1) must be a constant


After fixing the example, please check that also the long examples work.


program bug3
   implicit none
   real, parameter :: Qarg1 = 1.7
   integer, parameter :: k2 = kind(BESJ0(Qarg1))
   integer, parameter :: is_int = 1-1/(2+0*BESJ0(Qarg1))*2
   integer, parameter :: kind_if_real = &
      (1-is_int)*k2+is_int*kind(1.0)
   complex :: z = cmplx(0,1,kind_if_real) ! FAILS
   print *, kind_if_real  ! WORKS prints "4" (and dump is OK)
end program bug3
Comment 1 Richard Biener 2008-05-03 12:46:11 UTC
The frontend should emit calls to the gcc bultin functions which are properly
constant-folded.
Comment 2 Tobias Burnus 2008-05-03 14:00:56 UTC
> The frontend should emit calls to the gcc bultin functions which are properly
> constant-folded.

I think this already happens. The problem is that the information is needed much, much earlier: In initialization expressions, here, the front end needs to know result of the expression for other front-end stuff - such as deciding whether a REAL(4) or REAL(8) number is requested.
Comment 3 Tobias Burnus 2008-05-06 17:07:39 UTC
Subject: Bug 36117

Author: burnus
Date: Tue May  6 17:06:54 2008
New Revision: 134988

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=134988
Log:
2008-05-06  Tobias Burnus  <burnus@net-b.de>

        PR fortran/36117
        * intrinsic.c (add_functions): Call gfc_simplify_bessel_*.
        * intrinsic.h: Add prototypes for gfc_simplify_bessel_*.
        * simplify.c (gfc_simplify_bessel_j0,gfc_simplify_bessel_j1,
        gfc_simplify_bessel_jn,gfc_simplify_bessel_y0,
        gfc_simplify_bessel_y1,gfc_simplify_bessel_yn): New.

2008-05-06  Tobias Burnus  <burnus@net-b.de>

        PR fortran/36117
        * gfortran.dg/bessel_2.f90: New.


Added:
    trunk/gcc/testsuite/gfortran.dg/bessel_2.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/intrinsic.c
    trunk/gcc/fortran/intrinsic.h
    trunk/gcc/fortran/simplify.c
    trunk/gcc/testsuite/ChangeLog

Comment 4 Tobias Burnus 2008-05-06 17:09:05 UTC
FIXED on the trunk (4.4.0).
Comment 5 zadeck@gcc.gnu.org 2008-05-09 12:15:45 UTC
Subject: Bug 36117

Author: zadeck
Date: Fri May  9 12:14:57 2008
New Revision: 135113

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=135113
Log:
2008-05-08  Kenneth Zadeck  <zadeck@naturalbridge.com>

	PR middle-end/36117
	* dce.c (deletable_insn_p): Do not delete calls if 
	df_in_progress.
	(delete_unmarked_insns): When deleting a call, call 
	delete_unreachable_blocks.
	* rtl.texi (RTL_CONST_CALL_P, RTL_PURE_CALL_P,
	RTL_CONST_OR_PURE_CALL_P, RTL_LOOPING_CONST_OR_PURE_CALL_P): Fixed
	doc.
	


Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/dce.c
    trunk/gcc/doc/rtl.texi

Comment 6 Richard Earnshaw 2020-01-01 17:37:37 UTC
Comment #5 was really for PR36177