Hi all.
While looking at PR fortran/22572, I wondered where the difference between the
following two programs might be:
$> cat matmul.f90
REAL, DIMENSION(1,1), PARAMETER :: a = 1.0, b = 2.0
REAL, DIMENSION(1,1) :: c
c = MATMUL(a, b)
c = MATMUL(a, b)
end
$> cat sin.f90
REAL, DIMENSION(1, 1), PARAMETER :: a = 1.0
REAL, DIMENSION(1, 1) :: b, c
b = SIN(a)
c = SIN(a)
end
Compiling both with "-Wall -O3 -S -fdump-tree-original -fdump-tree-optimized",
one finds that the calls to SIN in sin.f90 have been optimized into
nothingness, while MATMUL in matmul.f90 is spelled out twice in the optimized
tree dump.
The main difference that springs to mind: SIN is built-in, MATMUL is a library
function. In gcc/builtin.defs, one finds
DEF_LIB_BUILTIN (BUILT_IN_SIN, "sin", BT_FN_DOUBLE_DOUBLE,
ATTR_MATHFN_FPROUNDING)
with
#define ATTR_MATHFN_FPROUNDING (flag_rounding_math ? \
ATTR_PURE_NOTHROW_NOVOPS_LIST : ATTR_CONST_NOTHROW_LIST)
Grep'ing the fortran sources, hardly any ATTR_* are used. Would the
application of ATTR_MATHFN_FPROUNDING or any other ATTR_* (e.g. ATTR_PURE?)
make any difference for the optimizer? If yes, where and how should these
attributes be applied to the function symbol?
Are these the right questions to ask or am I barking up the wrong tree?
Thanks
Daniel