public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/94566] New: conversion between std::strong_ordering and int
@ 2020-04-11 22:04 glisse at gcc dot gnu.org
  2020-04-13 20:24 ` [Bug tree-optimization/94566] " redi at gcc dot gnu.org
                   ` (14 more replies)
  0 siblings, 15 replies; 16+ messages in thread
From: glisse at gcc dot gnu.org @ 2020-04-11 22:04 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 94566
           Summary: conversion between std::strong_ordering and int
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: enhancement
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: glisse at gcc dot gnu.org
  Target Milestone: ---

#include <compare>

int conv1(std::strong_ordering s){
  if(s==std::strong_ordering::less) return -1;
  if(s==std::strong_ordering::equal) return 0;
  if(s==std::strong_ordering::greater) return 1;
  __builtin_unreachable();
}
std::strong_ordering conv2(int i){
  switch(i){
    case -1: return std::strong_ordering::less;
    case 0: return std::strong_ordering::equal;
    case 1: return std::strong_ordering::greater;
    default: __builtin_unreachable();
  }
}

Compiling with -std=gnu++2a -O3. I would like the compiler to notice that those
are just NOP (at most a sign-extension). Clang manages it for conv2. Gcc
generates:

        movl    $-1, %eax
        cmpb    $-1, %dil
        je      .L1
        xorl    %eax, %eax
        testb   %dil, %dil
        setne   %al
.L1:
        ret

and

        xorl    %eax, %eax
        testl   %edi, %edi
        je      .L10
        cmpl    $1, %edi
        sete    %al
        leal    -1(%rax,%rax), %eax
.L10:
        ret


(apparently the C++ committee thinks it is a good idea to provide a type that
is essentially an int that can only be -1, 0 or 1, but not provide any direct
way to convert to/from int)

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

end of thread, other threads:[~2023-06-07 20:27 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-11 22:04 [Bug tree-optimization/94566] New: conversion between std::strong_ordering and int glisse at gcc dot gnu.org
2020-04-13 20:24 ` [Bug tree-optimization/94566] " redi at gcc dot gnu.org
2020-04-14  6:57 ` rguenth at gcc dot gnu.org
2020-04-15 10:23 ` rguenth at gcc dot gnu.org
2020-04-15 10:32 ` glisse at gcc dot gnu.org
2020-05-15  6:57 ` rguenth at gcc dot gnu.org
2021-06-15  1:15 ` pinskia at gcc dot gnu.org
2021-08-03  9:37 ` marxin at gcc dot gnu.org
2021-08-03  9:39 ` marxin at gcc dot gnu.org
2021-08-03  9:41 ` marxin at gcc dot gnu.org
2022-03-14 16:53 ` oschonrock at gmail dot com
2022-03-14 17:10 ` jakub at gcc dot gnu.org
2022-03-14 17:15 ` oschonrock at gmail dot com
2022-03-14 17:25 ` jakub at gcc dot gnu.org
2023-06-07 17:31 ` pinskia at gcc dot gnu.org
2023-06-07 20:27 ` amacleod at redhat 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).