public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/111617] New: Unnecessary instructions generated when comparing mixed-sign small integers
@ 2023-09-27 19:22 davidfromonline at gmail dot com
  2023-09-27 19:25 ` [Bug target/111617] " pinskia at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: davidfromonline at gmail dot com @ 2023-09-27 19:22 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 111617
           Summary: Unnecessary instructions generated when comparing
                    mixed-sign small integers
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: davidfromonline at gmail dot com
  Target Milestone: ---

Compiling with `-std=c2x -O3`

```c
bool a(signed char x, unsigned char y) {
        return x == y;
}

bool b(short x, unsigned short y) {
        return x == y;
}

bool c(int x, unsigned y) {
        return x == y;
}

bool d(long x, unsigned long y) {
        return x == y;
}

bool e(long long x, unsigned long long y) {
        return x == y;
}
```

causes gcc to generate

```asm
a:
        movsx   edi, dil
        movzx   esi, sil
        cmp     edi, esi
        sete    al
        ret
b:
        movsx   edi, di
        movzx   esi, si
        cmp     edi, esi
        sete    al
        ret
c:
        cmp     edi, esi
        sete    al
        ret
d:
        cmp     rdi, rsi
        sete    al
        ret
e:
        cmp     rdi, rsi
        sete    al
        ret
```

The `movsx` and `movzx` seem unnecessary, and are not emitted by clang.

See it live: https://godbolt.org/z/dfc93f7Pv

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

* [Bug target/111617] Unnecessary instructions generated when comparing mixed-sign small integers
  2023-09-27 19:22 [Bug c/111617] New: Unnecessary instructions generated when comparing mixed-sign small integers davidfromonline at gmail dot com
@ 2023-09-27 19:25 ` pinskia at gcc dot gnu.org
  2023-09-27 19:27 ` pinskia at gcc dot gnu.org
  2023-09-27 19:31 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-09-27 19:25 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Target|                            |x86_64-linux-gnu
           Keywords|                            |ABI
          Component|c                           |target

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
There is a disagreement on the ABI between GCC and clang and even what the ABI
says. GCC assumes the upper bits are not zero/sign extended while clang thinks
they are.

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

* [Bug target/111617] Unnecessary instructions generated when comparing mixed-sign small integers
  2023-09-27 19:22 [Bug c/111617] New: Unnecessary instructions generated when comparing mixed-sign small integers davidfromonline at gmail dot com
  2023-09-27 19:25 ` [Bug target/111617] " pinskia at gcc dot gnu.org
@ 2023-09-27 19:27 ` pinskia at gcc dot gnu.org
  2023-09-27 19:31 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-09-27 19:27 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=98425

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98425#c3 also.

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

* [Bug target/111617] Unnecessary instructions generated when comparing mixed-sign small integers
  2023-09-27 19:22 [Bug c/111617] New: Unnecessary instructions generated when comparing mixed-sign small integers davidfromonline at gmail dot com
  2023-09-27 19:25 ` [Bug target/111617] " pinskia at gcc dot gnu.org
  2023-09-27 19:27 ` pinskia at gcc dot gnu.org
@ 2023-09-27 19:31 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-09-27 19:31 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=92821,
                   |                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=46942
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |INVALID

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Also see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92821#c2. clang/LLVM is
still not following the ABI after years of reprorting to them they are wrong.

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

end of thread, other threads:[~2023-09-27 19:31 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-27 19:22 [Bug c/111617] New: Unnecessary instructions generated when comparing mixed-sign small integers davidfromonline at gmail dot com
2023-09-27 19:25 ` [Bug target/111617] " pinskia at gcc dot gnu.org
2023-09-27 19:27 ` pinskia at gcc dot gnu.org
2023-09-27 19:31 ` 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).