public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/68110] New: __builtin_sub_overflow unsigned performance issue
@ 2015-10-27  5:07 eggert at gnu dot org
  2015-10-27  5:15 ` [Bug target/68110] " pinskia at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: eggert at gnu dot org @ 2015-10-27  5:07 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 68110
           Summary: __builtin_sub_overflow unsigned performance issue
           Product: gcc
           Version: 5.2.1
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: eggert at gnu dot org
  Target Milestone: ---

I ran into this minor performance issue when changing Gnulib's lib/intprops.h
to use the new __builtin_sub_overflow function. I found that
__builtin_sub_overflow is less efficient than the portable C code that it
replaced, when the operands and result are unsigned, or unsigned long, or
unsigned long long. To reproduce the problem, compile and run the following
program with 'gcc -O2 -S' on x86-64:

  _Bool f1 (unsigned long long a, unsigned long long b)
  {
    return a < b;
  }

  _Bool f2 (unsigned long long a, unsigned long long b)
  {
    unsigned long long r;
    return __builtin_sub_overflow (a, b, &r);
  }

Although the functions are semantically equivalent, f1 uses only 3
instructions:

        f1:
                cmpq    %rsi, %rdi
                setb    %al
                ret

whereas f2 uses 5 instructions:

        f2:
                movq    %rdi, %rax
                subq    %rsi, %rax
                cmpq    %rdi, %rax
                seta    %al
                ret

There is a similar problem for x86.


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

end of thread, other threads:[~2023-11-13  3:05 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-27  5:07 [Bug c/68110] New: __builtin_sub_overflow unsigned performance issue eggert at gnu dot org
2015-10-27  5:15 ` [Bug target/68110] " pinskia at gcc dot gnu.org
2015-10-27  5:19 ` pinskia at gcc dot gnu.org
2015-10-27  6:34 ` eggert at gnu dot org
2015-10-27  9:46 ` rguenth at gcc dot gnu.org
2021-08-21 22:33 ` [Bug tree-optimization/68110] " pinskia at gcc dot gnu.org
2021-08-21 22:34 ` pinskia at gcc dot gnu.org
2023-11-13  3:05 ` 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).