public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/66584] New: gcc differs in static, branch-prediction cost from icc in switch.
@ 2015-06-18 10:16 jmcguiness at liquidcapital dot com
  2015-06-18 14:24 ` [Bug c++/66584] " ebotcazou at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: jmcguiness at liquidcapital dot com @ 2015-06-18 10:16 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 66584
           Summary: gcc differs in static, branch-prediction cost from icc
                    in switch.
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jmcguiness at liquidcapital dot com
  Target Milestone: ---

This means that code optimised for icc is sub-optimal for icc and the reverse
is true. I feel that this feature should be more clearly documented in the web
pages & man pages.

For the following code:

extern void bar1();
extern void bar2();
extern void bar3();

void foo(int i) {
  switch(i) {
  case 1:
    bar1(); // gcc: least likely | icc: most likely
    break;
  case 2:
    bar2(); // gcc: less likely | icc: less likely
    break;
  default:
    bar3(); // gcc: most likely | icc: least likely
  }
}

gcc v4.8.2 & v5.10 for -O2 & -O3 produce:

foo(int):
        cmpl    $1, %edi
        je      .L3
        cmpl    $2, %edi
        jne     .L8
        jmp     bar2()
.L8:
        jmp     bar3()
.L3:
        jmp     bar1()

>From which the static probabilities are quoted, above.

Conversely icc produces:

foo(int):
        cmpl      $1, %edi                                      #9.10
        jne       ..B1.3        # Prob 67%                      #9.10
        jmp       bar1()                                      #11.2
..B1.3:                         # Preds ..B1.1
        cmpl      $2, %edi                                      #9.10
        jne       ..B1.5        # Prob 50%                      #9.10
        jmp       bar2()                                      #14.5
..B1.5:                         # Preds ..B1.3
        jmp       bar3()                                      #17.5

>From which the static probabilities are quoted, above.

Please not: I feel this is *only* a bug in the documentation!

It would be nice if my optimised (for speed) code would be optimised (for
speed) on both platforms in the same way, so that I wouldn't have to optimise
my code, but that is only my taste.


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

end of thread, other threads:[~2015-06-18 16:27 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-18 10:16 [Bug c++/66584] New: gcc differs in static, branch-prediction cost from icc in switch jmcguiness at liquidcapital dot com
2015-06-18 14:24 ` [Bug c++/66584] " ebotcazou at gcc dot gnu.org
2015-06-18 14:44 ` pinskia at gcc dot gnu.org
2015-06-18 15:23 ` jmcguiness at liquidcapital dot com
2015-06-18 15:33 ` jmcguiness at liquidcapital dot com
2015-06-18 15:46 ` pinskia at gcc dot gnu.org
2015-06-18 16:25 ` jmcguiness at liquidcapital dot com
2015-06-18 16:27 ` jmcguiness at liquidcapital dot com

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