[Bug middle-end/85599] Function need not be evaluated in logical expression
tkoenig at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Mon May 7 08:47:00 GMT 2018
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85599
Thomas Koenig <tkoenig at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|WAITING |NEW
Component|fortran |middle-end
Summary|invalid optimization: |Function need not be
|function not always |evaluated in logical
|evaluated in logical |expression
|expression |
--- Comment #13 from Thomas Koenig <tkoenig at gcc dot gnu.org> ---
In the original test case, it is not necessary to evaluate
the function at all. A function evaluation should always be
cheaper than just checking a variable. Constant propagation
would then eliminate all of the test case, leading only
to the effect of
flag = .false.
As a more realistic example, one should change
subroutine foo(a,b)
logical, intent(in) :: a
logical, intent(out) :: b
b = func() .and. a
end subroutine foo
to
subroutine foo(a,b)
logical, intent(in) :: a
logical, intent(out) :: b
if (a) then
b = func()
else
b = .false.
end if
end subroutine
We are passing TRUTH_AND_EXPR to the middle end to allow such
optimizations. Is there something in the semantics of TRUTH_AND_EXPR
(for example needed for other languages) that says that the
function check() needs to be called? Or is this simply some
optimization opportunity that is currently not taken?
More information about the Gcc-bugs
mailing list