public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/49148] New: Certain expressions take an extremely long time for no apparent reason
@ 2011-05-24 19:14 jchthys at yahoo dot com
  2011-05-24 19:16 ` [Bug c/49148] " jchthys at yahoo dot com
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: jchthys at yahoo dot com @ 2011-05-24 19:14 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49148

           Summary: Certain expressions take an extremely long time for no
                    apparent reason
           Product: gcc
           Version: 4.4.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: jchthys@yahoo.com


Created attachment 24349
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=24349
This is a minimal test case of an expression that takes 100 times longer to
evaluate than it should. See comments for explanations.

I have been doing work on 1-D Jacobi stencils. Basically, this involves a lot
of repeated operations. For some reason, however, I have been getting extremely
long run times for certain expressions. What is weird is that if I TAKE OUT a
multiply operation, the function takes about 100 times longer to run than if I
left it in.

The line that causes the problems is marked in the source code. It reads:

     new[i] = (A[i-1] + A[i] + A[i+1]) / 4.0;

If I change this to the following, there is no problem:

     new[i] = (A[i-1] + 2*A[i] + A[i+1]) / 4.0;

As another example, the following line runs slowly:

     new[i] = (A[i-1] + A[i] + A[i+1]) * 0.3;

while this line runs quickly:

     new[i] = (A[i-1] + 2*A[i] + A[i+1]) * 0.333;

The reason I think this is a bug is that it does not happen with older versions
of GCC (for example, 4.1.2), nor with the Intel C Compiler.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c/49148] Certain expressions take an extremely long time for no apparent reason
  2011-05-24 19:14 [Bug c/49148] New: Certain expressions take an extremely long time for no apparent reason jchthys at yahoo dot com
@ 2011-05-24 19:16 ` jchthys at yahoo dot com
  2011-05-24 19:41 ` jchthys at yahoo dot com
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: jchthys at yahoo dot com @ 2011-05-24 19:16 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49148

John Peyton <jchthys at yahoo dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |missed-optimization

--- Comment #1 from John Peyton <jchthys at yahoo dot com> 2011-05-24 18:56:52 UTC ---
The following command was used to compile and execute the test case:

     gcc gcc_bug.c -O3 -o gcc_bug && ./gcc_bug

Note that -O3 was used. In addition, -lm affects performance minimally if it is
used.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c/49148] Certain expressions take an extremely long time for no apparent reason
  2011-05-24 19:14 [Bug c/49148] New: Certain expressions take an extremely long time for no apparent reason jchthys at yahoo dot com
  2011-05-24 19:16 ` [Bug c/49148] " jchthys at yahoo dot com
@ 2011-05-24 19:41 ` jchthys at yahoo dot com
  2011-05-24 20:06 ` jchthys at yahoo dot com
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: jchthys at yahoo dot com @ 2011-05-24 19:41 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49148

--- Comment #2 from John Peyton <jchthys at yahoo dot com> 2011-05-24 19:16:20 UTC ---
Created attachment 24350
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=24350
This is a minimal example of an expression that takes longer to evaluate than
it should. Run the slightly longer file for an example of the speed difference.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c/49148] Certain expressions take an extremely long time for no apparent reason
  2011-05-24 19:14 [Bug c/49148] New: Certain expressions take an extremely long time for no apparent reason jchthys at yahoo dot com
  2011-05-24 19:16 ` [Bug c/49148] " jchthys at yahoo dot com
  2011-05-24 19:41 ` jchthys at yahoo dot com
@ 2011-05-24 20:06 ` jchthys at yahoo dot com
  2011-05-24 20:42 ` pinskia at gcc dot gnu.org
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: jchthys at yahoo dot com @ 2011-05-24 20:06 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49148

--- Comment #3 from John Peyton <jchthys at yahoo dot com> 2011-05-24 19:16:51 UTC ---
Created attachment 24351
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=24351
Finally, this is a preprocessed version of the minimal case.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c/49148] Certain expressions take an extremely long time for no apparent reason
  2011-05-24 19:14 [Bug c/49148] New: Certain expressions take an extremely long time for no apparent reason jchthys at yahoo dot com
                   ` (2 preceding siblings ...)
  2011-05-24 20:06 ` jchthys at yahoo dot com
@ 2011-05-24 20:42 ` pinskia at gcc dot gnu.org
  2011-05-24 21:47 ` [Bug rtl-optimization/49148] " jchthys at yahoo dot com
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2011-05-24 20:42 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49148

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> 2011-05-24 20:27:39 UTC ---
Maybe you are getting subnormals which causes a huge performance decrease.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug rtl-optimization/49148] Certain expressions take an extremely long time for no apparent reason
  2011-05-24 19:14 [Bug c/49148] New: Certain expressions take an extremely long time for no apparent reason jchthys at yahoo dot com
                   ` (3 preceding siblings ...)
  2011-05-24 20:42 ` pinskia at gcc dot gnu.org
@ 2011-05-24 21:47 ` jchthys at yahoo dot com
  2011-05-24 21:55 ` jchthys at yahoo dot com
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: jchthys at yahoo dot com @ 2011-05-24 21:47 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49148

John Peyton <jchthys at yahoo dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |minor


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug rtl-optimization/49148] Certain expressions take an extremely long time for no apparent reason
  2011-05-24 19:14 [Bug c/49148] New: Certain expressions take an extremely long time for no apparent reason jchthys at yahoo dot com
                   ` (4 preceding siblings ...)
  2011-05-24 21:47 ` [Bug rtl-optimization/49148] " jchthys at yahoo dot com
@ 2011-05-24 21:55 ` jchthys at yahoo dot com
  2011-05-25  9:56 ` rguenth at gcc dot gnu.org
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: jchthys at yahoo dot com @ 2011-05-24 21:55 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49148

--- Comment #5 from John Peyton <jchthys at yahoo dot com> 2011-05-24 21:26:49 UTC ---
> Maybe you are getting subnormals which causes a huge performance decrease.

It looks like that might indeed be the case. It didn't seem to happen with ICC
though. Is it possible that other compilers have different ways of handling
subnormals?


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug rtl-optimization/49148] Certain expressions take an extremely long time for no apparent reason
  2011-05-24 19:14 [Bug c/49148] New: Certain expressions take an extremely long time for no apparent reason jchthys at yahoo dot com
                   ` (5 preceding siblings ...)
  2011-05-24 21:55 ` jchthys at yahoo dot com
@ 2011-05-25  9:56 ` rguenth at gcc dot gnu.org
  2011-05-25 14:45 ` jchthys at yahoo dot com
  2021-12-26 12:49 ` pinskia at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2011-05-25  9:56 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49148

--- Comment #6 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-05-25 09:26:56 UTC ---
Try -ffast-math (the default for ICC) which disables subnormals.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug rtl-optimization/49148] Certain expressions take an extremely long time for no apparent reason
  2011-05-24 19:14 [Bug c/49148] New: Certain expressions take an extremely long time for no apparent reason jchthys at yahoo dot com
                   ` (6 preceding siblings ...)
  2011-05-25  9:56 ` rguenth at gcc dot gnu.org
@ 2011-05-25 14:45 ` jchthys at yahoo dot com
  2021-12-26 12:49 ` pinskia at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: jchthys at yahoo dot com @ 2011-05-25 14:45 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49148

--- Comment #7 from John Peyton <jchthys at yahoo dot com> 2011-05-25 14:40:56 UTC ---
> Try -ffast-math (the default for ICC) which disables subnormals.

Thanks, this helped it run much faster!

I noticed it still takes longer to divide by 3.0 than by 4.0. More
specifically, the following line was fast:

     new[i] = (A[i-1] + 2*A[i] + A[i+1]) / 4.0;

The following line took about 4 times as long to run without -ffast-math:

     new[i] = (A[i-1] + A[i] + A[i+1]) / 3.0;

With -ffast-math, it was faster; however, it was still took about 2 times as
long as the division by 4.0 version. In addition, changing division by 3.0 to
multiplication by 0.333 or even 0.3 did not affect the speed.

Could this also be related to subnormal numbers, or is this just a different
issue?


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug rtl-optimization/49148] Certain expressions take an extremely long time for no apparent reason
  2011-05-24 19:14 [Bug c/49148] New: Certain expressions take an extremely long time for no apparent reason jchthys at yahoo dot com
                   ` (7 preceding siblings ...)
  2011-05-25 14:45 ` jchthys at yahoo dot com
@ 2021-12-26 12:49 ` pinskia at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-26 12:49 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=49148

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |INVALID
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #8 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to John Peyton from comment #7)
> > Try -ffast-math (the default for ICC) which disables subnormals.
> 
> Thanks, this helped it run much faster!

Yes so you confirm this is a subnormal issue.

> 
> Could this also be related to subnormal numbers, or is this just a different
> issue?

Different issue related to /4.0 can be done as *0.25 but I think that might be
solved in newer versions of GCC; I didn't try.

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2021-12-26 12:49 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-05-24 19:14 [Bug c/49148] New: Certain expressions take an extremely long time for no apparent reason jchthys at yahoo dot com
2011-05-24 19:16 ` [Bug c/49148] " jchthys at yahoo dot com
2011-05-24 19:41 ` jchthys at yahoo dot com
2011-05-24 20:06 ` jchthys at yahoo dot com
2011-05-24 20:42 ` pinskia at gcc dot gnu.org
2011-05-24 21:47 ` [Bug rtl-optimization/49148] " jchthys at yahoo dot com
2011-05-24 21:55 ` jchthys at yahoo dot com
2011-05-25  9:56 ` rguenth at gcc dot gnu.org
2011-05-25 14:45 ` jchthys at yahoo dot com
2021-12-26 12:49 ` pinskia at gcc dot gnu.org

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).