public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/26196]  New: optimize if(val>max) val=max;
@ 2006-02-09 14:05 snakebyte at gmx dot de
  2006-02-09 14:05 ` [Bug c/26196] " snakebyte at gmx dot de
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: snakebyte at gmx dot de @ 2006-02-09 14:05 UTC (permalink / raw)
  To: gcc-bugs

Hi,

it seems that the 
 if(val>=max) val=max;

statement is on some processors faster than
 if(val>max) val=max;

I will attach a testcase, which shows that the first version seems to be faster
on amd based systems, the second version on intel based systems. Might be
something -O can detect and optimize.
This came up in a discussion on the kernel janitor mailinglist 
http://marc.theaimsgroup.com/?l=kernel-janitor-discuss&m=113942520002963&w=2

Thanks, Eric


-- 
           Summary: optimize if(val>max) val=max;
           Product: gcc
           Version: 3.4.5
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: snakebyte at gmx dot de


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


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

* [Bug c/26196] optimize if(val>max) val=max;
  2006-02-09 14:05 [Bug c/26196] New: optimize if(val>max) val=max; snakebyte at gmx dot de
@ 2006-02-09 14:05 ` snakebyte at gmx dot de
  2006-02-09 14:06 ` [Bug middle-end/26196] " pinskia at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: snakebyte at gmx dot de @ 2006-02-09 14:05 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from snakebyte at gmx dot de  2006-02-09 14:05 -------
Created an attachment (id=10813)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=10813&action=view)
testcase for possible optimization

This is the used benchmark


-- 


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


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

* [Bug middle-end/26196] optimize if(val>max) val=max;
  2006-02-09 14:05 [Bug c/26196] New: optimize if(val>max) val=max; snakebyte at gmx dot de
  2006-02-09 14:05 ` [Bug c/26196] " snakebyte at gmx dot de
@ 2006-02-09 14:06 ` pinskia at gcc dot gnu dot org
  2006-02-09 14:07 ` pinskia at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-02-09 14:06 UTC (permalink / raw)
  To: gcc-bugs



-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|c                           |middle-end
           Priority|P3                          |P5


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


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

* [Bug middle-end/26196] optimize if(val>max) val=max;
  2006-02-09 14:05 [Bug c/26196] New: optimize if(val>max) val=max; snakebyte at gmx dot de
  2006-02-09 14:05 ` [Bug c/26196] " snakebyte at gmx dot de
  2006-02-09 14:06 ` [Bug middle-end/26196] " pinskia at gcc dot gnu dot org
@ 2006-02-09 14:07 ` pinskia at gcc dot gnu dot org
  2006-02-09 14:18 ` snakebyte at gmx dot de
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-02-09 14:07 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from pinskia at gcc dot gnu dot org  2006-02-09 14:07 -------
Your benchmark is flawed in many different ways.
First the branch prediction cache is not going to be warm in your benchmark
unlike real code.


-- 


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


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

* [Bug middle-end/26196] optimize if(val>max) val=max;
  2006-02-09 14:05 [Bug c/26196] New: optimize if(val>max) val=max; snakebyte at gmx dot de
                   ` (3 preceding siblings ...)
  2006-02-09 14:18 ` snakebyte at gmx dot de
@ 2006-02-09 14:18 ` pinskia at gcc dot gnu dot org
  2006-09-03 20:45 ` pinskia at gcc dot gnu dot org
  2006-09-03 20:53 ` snakebyte at gmx dot de
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-02-09 14:18 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from pinskia at gcc dot gnu dot org  2006-02-09 14:18 -------
All you are saving is one or two instructions if val == max, in real life that
is usually no more than 0.1%  now if it was really in the hot loop, it might be
1-2% depending on how "hot" the loop really is.


-- 


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


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

* [Bug middle-end/26196] optimize if(val>max) val=max;
  2006-02-09 14:05 [Bug c/26196] New: optimize if(val>max) val=max; snakebyte at gmx dot de
                   ` (2 preceding siblings ...)
  2006-02-09 14:07 ` pinskia at gcc dot gnu dot org
@ 2006-02-09 14:18 ` snakebyte at gmx dot de
  2006-02-09 14:18 ` pinskia at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: snakebyte at gmx dot de @ 2006-02-09 14:18 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from snakebyte at gmx dot de  2006-02-09 14:18 -------
wow, thats a fast reply. You got a pointer on how to warm the branch prediction
cache or is this all a no-issue an we can mark this as not a bug?


-- 


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


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

* [Bug middle-end/26196] optimize if(val>max) val=max;
  2006-02-09 14:05 [Bug c/26196] New: optimize if(val>max) val=max; snakebyte at gmx dot de
                   ` (4 preceding siblings ...)
  2006-02-09 14:18 ` pinskia at gcc dot gnu dot org
@ 2006-09-03 20:45 ` pinskia at gcc dot gnu dot org
  2006-09-03 20:53 ` snakebyte at gmx dot de
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-09-03 20:45 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from pinskia at gcc dot gnu dot org  2006-09-03 20:45 -------
(In reply to comment #4)
> wow, thats a fast reply. You got a pointer on how to warm the branch prediction
> cache or is this all a no-issue an we can mark this as not a bug?
Yes by doing it in a loop.


-- 


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


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

* [Bug middle-end/26196] optimize if(val>max) val=max;
  2006-02-09 14:05 [Bug c/26196] New: optimize if(val>max) val=max; snakebyte at gmx dot de
                   ` (5 preceding siblings ...)
  2006-09-03 20:45 ` pinskia at gcc dot gnu dot org
@ 2006-09-03 20:53 ` snakebyte at gmx dot de
  6 siblings, 0 replies; 8+ messages in thread
From: snakebyte at gmx dot de @ 2006-09-03 20:53 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from snakebyte at gmx dot de  2006-09-03 20:53 -------
marked as wontfix since my benchmark is useless


-- 

snakebyte at gmx dot de changed:

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


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


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

end of thread, other threads:[~2006-09-03 20:53 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-02-09 14:05 [Bug c/26196] New: optimize if(val>max) val=max; snakebyte at gmx dot de
2006-02-09 14:05 ` [Bug c/26196] " snakebyte at gmx dot de
2006-02-09 14:06 ` [Bug middle-end/26196] " pinskia at gcc dot gnu dot org
2006-02-09 14:07 ` pinskia at gcc dot gnu dot org
2006-02-09 14:18 ` snakebyte at gmx dot de
2006-02-09 14:18 ` pinskia at gcc dot gnu dot org
2006-09-03 20:45 ` pinskia at gcc dot gnu dot org
2006-09-03 20:53 ` snakebyte at gmx dot de

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