public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "kargl at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug fortran/30409] [fortran] missed optimization with pure function arguments
Date: Mon, 23 Oct 2023 19:23:09 +0000 [thread overview]
Message-ID: <bug-30409-4-xGJySrDlIR@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-30409-4@http.gcc.gnu.org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=30409
--- Comment #10 from kargl at gcc dot gnu.org ---
(In reply to anlauf from comment #8)
> The suggested optimization needs to take into account that the evaluation
> of the temporary expression might trap, or that allocatable variables are
> not allocated, etc.
>
> The trap etc. would not occur if the trip count of the loop is zero for the
> non-hoisted variant, so we need to make sure not to generate failing code
> for the hoisted one.
>
> Similarly, for conditional code in the loop body, like
>
> if (cond) then
> expression1 (..., 1/y)
> else
> expression2 (..., 1/z)
> end if
>
> where cond protects from traps even for finite trip counts, these conditions
> may also need to be identified, and an appropriate block generated.
I'm not sure what you are worried about here. If one has
do i = 1, n
... = expression1(..., 1/y)
end do
then this is equivalent to
do i = 1, n
tmp = 1 / y
... = expression1(..., tmp)
end do
which is equivalent to
tmp = 1 / y
do i = 1, n
... = expression1(..., tmp)
end do
I suppose I could do something exceedingly stupid such as
function expression1(..., xxx)
common /foo/y
y = 0
...
end
but this would then lead to invalid Fortran when i = 2 in the
above initial loops as (1/y) is invalid Fortran if y = 0.
next prev parent reply other threads:[~2023-10-23 19:23 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <bug-30409-4@http.gcc.gnu.org/bugzilla/>
2010-10-02 8:10 ` tkoenig at gcc dot gnu.org
2023-10-22 16:43 ` kargl at gcc dot gnu.org
2023-10-22 19:18 ` anlauf at gcc dot gnu.org
2023-10-23 5:50 ` tkoenig at gcc dot gnu.org
2023-10-23 19:23 ` kargl at gcc dot gnu.org [this message]
2023-10-23 19:28 ` anlauf at gcc dot gnu.org
2023-10-23 21:45 ` kargl at gcc dot gnu.org
2007-01-08 21:31 [Bug fortran/30409] New: " kargl at gcc dot gnu dot org
2007-01-08 21:32 ` [Bug fortran/30409] " kargl at gcc dot gnu dot org
2007-01-08 21:36 ` kargl at gcc dot gnu dot org
2007-01-09 11:11 ` rguenth at gcc dot gnu dot org
2007-01-09 16:08 ` kargl at gcc dot gnu dot org
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=bug-30409-4-xGJySrDlIR@http.gcc.gnu.org/bugzilla/ \
--to=gcc-bugzilla@gcc.gnu.org \
--cc=gcc-bugs@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).