* Testsuite and constant-folding?
@ 2007-01-05 18:45 Brooks Moses
2007-01-05 19:43 ` Joseph S. Myers
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Brooks Moses @ 2007-01-05 18:45 UTC (permalink / raw)
To: gcc-patches; +Cc: fortran
(Note: This issue came up in considering the Fortran testsuite, but I
think it's sufficiently relevant to GCC as a whole (and I'm hoping for
some comments from people familiar with the non-Fortran parts of GCC
that it seemed reasonable to crosspost it.)
I've been recently poking at some bugs in Fortran's intrinsics
(specifically, ISHFTC and IBCLR and the like), and one of the tricky
bits is that there are two entirely separate code paths to consider --
there's the GMP-based one in gcc/fortran/simplify.c that does
constant-folding, and there's the native-code one in libgfortran that
does the runtime work.
However, as best I can tell, the relevant testcases completely ignore
this issue, and thus end up only testing the constant-folding case.
This strikes me as likely to be an endemic problem in the Fortran
testsuite, and I would guess that substantial portions of libgfortran
are not actually tested by "make check-fortran".
So, three questions:
(1) For a given Fortran testcase, is there a reliable way of ensuring
that a given expression is not constant-folded and instead gets
evaluated at runtime?
(2) Is there a way to turn off (essentially) all of the constant-folding
machinery in a given compilation?
(3) How do GCC testsuites other than the Fortran one handle this issue?
I think that this is probably a significant enough issue that it would
be worth implementing an option in the Fortran front end to turn off the
majority (or even all) of the constant folding, and then adding a
testsuite pass that uses this option. Is there a relevant flag already
present in GCC, or would we need to add one? Thoughts on this proposal?
- Brooks
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Testsuite and constant-folding?
2007-01-05 18:45 Testsuite and constant-folding? Brooks Moses
@ 2007-01-05 19:43 ` Joseph S. Myers
2007-01-05 21:36 ` Tobias Schlüter
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Joseph S. Myers @ 2007-01-05 19:43 UTC (permalink / raw)
To: Brooks Moses; +Cc: gcc-patches, fortran
On Fri, 5 Jan 2007, Brooks Moses wrote:
> (3) How do GCC testsuites other than the Fortran one handle this issue?
Using volatile variables is one way to ensure that an built-in function
doesn't get evaluated to a constant at compile time. See for example
gcc.c-torture/execute/builtins/complex-1.c. In practice non-volatile
non-const non-static global variables will also do the job, see e.g.
gcc.dg/builtin-bswap-4.c.
--
Joseph S. Myers
joseph@codesourcery.com
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Testsuite and constant-folding?
2007-01-05 18:45 Testsuite and constant-folding? Brooks Moses
2007-01-05 19:43 ` Joseph S. Myers
@ 2007-01-05 21:36 ` Tobias Schlüter
2007-01-05 21:46 ` Thomas Koenig
2007-01-09 1:16 ` Janis Johnson
3 siblings, 0 replies; 5+ messages in thread
From: Tobias Schlüter @ 2007-01-05 21:36 UTC (permalink / raw)
To: Brooks Moses; +Cc: fortran, gcc-patches
Brooks Moses <brooks.moses@codesourcery.com> wrote on Fri, 05 Jan 2007:
> (Note: This issue came up in considering the Fortran testsuite, but I
> think it's sufficiently relevant to GCC as a whole (and I'm hoping for
> some comments from people familiar with the non-Fortran parts of GCC
> that it seemed reasonable to crosspost it.)
>
>
> I've been recently poking at some bugs in Fortran's intrinsics
> (specifically, ISHFTC and IBCLR and the like), and one of the tricky
> bits is that there are two entirely separate code paths to consider --
> there's the GMP-based one in gcc/fortran/simplify.c that does
> constant-folding, and there's the native-code one in libgfortran that
> does the runtime work.
>
> However, as best I can tell, the relevant testcases completely ignore
> this issue, and thus end up only testing the constant-folding case.
> This strikes me as likely to be an endemic problem in the Fortran
> testsuite, and I would guess that substantial portions of libgfortran
> are not actually tested by "make check-fortran".
(To avoid further confusion downthread: there are two types of
constant folding in a gfortran compilation:
1. Fortran expressions are folded during parsing to determine if an
expression is a valid initialization / constant expression
2. when building trees from the frontend representation (completely
folded per 1.), the middleend fold machinery comes into play.)
> So, three questions:
>
> (1) For a given Fortran testcase, is there a reliable way of ensuring
> that a given expression is not constant-folded and instead gets
> evaluated at runtime?
Yes, or no, depending on how you look at it. Simply set a variable to
the value you want to test the library for, and then pass that to the
intrinsic. The frontend folders will not propagate the value into the
intrisic's argument (which is what you want), but the optimizers may
(and this is hard to avoid, but testing -O0 should be sufficient for
this).
> (2) Is there a way to turn off (essentially) all of the
> constant-folding machinery in a given compilation?
No, since then validity of a program couldn't be established, as
pointed out above.
> (3) How do GCC testsuites other than the Fortran one handle this issue?
Don't know, this is certainly a FE specific issue.
> I think that this is probably a significant enough issue that it would
> be worth implementing an option in the Fortran front end to turn off
> the majority (or even all) of the constant folding, and then adding a
> testsuite pass that uses this option. Is there a relevant flag already
> present in GCC, or would we need to add one? Thoughts on this proposal?
I don't think it's doable. What we've been doing in the past is to
add testcases when we find out that the library or the frontend was
broken. Most testcases are probably still FE only.
Cheers,
- Tobi
----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Testsuite and constant-folding?
2007-01-05 18:45 Testsuite and constant-folding? Brooks Moses
2007-01-05 19:43 ` Joseph S. Myers
2007-01-05 21:36 ` Tobias Schlüter
@ 2007-01-05 21:46 ` Thomas Koenig
2007-01-09 1:16 ` Janis Johnson
3 siblings, 0 replies; 5+ messages in thread
From: Thomas Koenig @ 2007-01-05 21:46 UTC (permalink / raw)
To: Brooks Moses; +Cc: fortran, gcc-patches
On Fri, Jan 05, 2007 at 10:41:05AM -0800, Brooks Moses wrote:
> However, as best I can tell, the relevant testcases completely ignore
> this issue, and thus end up only testing the constant-folding case.
For the record, this is PR 22307.
Thomas
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Testsuite and constant-folding?
2007-01-05 18:45 Testsuite and constant-folding? Brooks Moses
` (2 preceding siblings ...)
2007-01-05 21:46 ` Thomas Koenig
@ 2007-01-09 1:16 ` Janis Johnson
3 siblings, 0 replies; 5+ messages in thread
From: Janis Johnson @ 2007-01-09 1:16 UTC (permalink / raw)
To: Brooks Moses; +Cc: gcc-patches, fortran
On Fri, Jan 05, 2007 at 10:41:05AM -0800, Brooks Moses wrote:
> (3) How do GCC testsuites other than the Fortran one handle this issue?
[I'm still catching up on email, sorry for the delay.]
The tests for decimal floating point expression evaluation in gcc.dg/dfp
have separate versions for compile-time folding and for runtime evaluation.
Runtime tests explicitly use -O0 and have either volatile or global
variables. Fold tests explicitly use -O2; they have calls to link_error
to verify that the expressions are folded, but are also executed to
verify that the program runs without blowing up.
Janis
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2007-01-09 1:16 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-01-05 18:45 Testsuite and constant-folding? Brooks Moses
2007-01-05 19:43 ` Joseph S. Myers
2007-01-05 21:36 ` Tobias Schlüter
2007-01-05 21:46 ` Thomas Koenig
2007-01-09 1:16 ` Janis Johnson
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).